Skip to content

Commit 5197fac

Browse files
authored
Enable allowed external iframe src's (#985)
As part of project migration from trinket to the code editor some additional functionality is required. This PR enables iframes to be used from the same approved external sources list as used for href's and other src attributes. By expanding this to allow for self references (i.e. src with a value the same as the `PUBLIC_URL`) users can embed other projects they (or we) own in iframes into their projects
1 parent 91b6449 commit 5197fac

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
### Added
1010

11+
- Support to enable embedding iframes in HTML projects from in-house domains (#985)
1112
- Unit tests for `pyodide` runner (#976)
1213

1314
## [0.22.2] - 2024-03-18

src/components/Editor/Runners/HtmlRunner/HtmlRunner.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ function HtmlRunner() {
283283
projectFile.content,
284284
mimeTypes.lookup(`${projectFile.name}.${projectFile.extension}`),
285285
);
286+
} else if (matchingRegexes(allowedExternalLinks, srcNode.attrs[attr])) {
287+
src = srcNode.attrs[attr];
286288
}
287289
srcNode.setAttribute(attr, src);
288290
srcNode.setAttribute("crossorigin", true);

src/utils/externalLinkHelper.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { useDispatch } from "react-redux";
33

44
import { setError, triggerCodeRun } from "../redux/EditorSlice";
55

6-
const domain = `https://rpf.io/`;
6+
const domain = "https://rpf.io/";
7+
const host = process.env.PUBLIC_URL || "http://localhost:3010";
78
const rpfDomain = new RegExp(`^${domain}`);
9+
const hostDomain = new RegExp(`^${host}`);
810
const allowedInternalLinks = [new RegExp(`^#[a-zA-Z0-9]+`)];
9-
const allowedExternalLinks = [rpfDomain];
11+
const allowedExternalLinks = [rpfDomain, hostDomain];
1012

1113
const useExternalLinkState = (showModal) => {
1214
const dispatch = useDispatch();

0 commit comments

Comments
 (0)