mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 05:50:11 +01:00
Don't load code when not in sandbox.
This commit is contained in:
parent
6b1ae1c271
commit
f8bdfcbaba
1 changed files with 9 additions and 1 deletions
|
|
@ -8,6 +8,12 @@ import { IMessage, IPreviewState } from "../shared";
|
||||||
import "./style.scss";
|
import "./style.scss";
|
||||||
|
|
||||||
window.addEventListener("message", (event) => {
|
window.addEventListener("message", (event) => {
|
||||||
|
const isInSandbox = window.origin === "null";
|
||||||
|
if (!isInSandbox) {
|
||||||
|
// To prevent someone from using this html file to run arbitrary code in non-sandboxed context
|
||||||
|
console.error("not in sandbox");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const e = event.data as IMessage | { kind: undefined };
|
const e = event.data as IMessage | { kind: undefined };
|
||||||
if (e.kind === "initialize") {
|
if (e.kind === "initialize") {
|
||||||
initialize(e.state);
|
initialize(e.state);
|
||||||
|
|
@ -43,7 +49,9 @@ async function initialize(state: IPreviewState) {
|
||||||
eval(state.js);
|
eval(state.js);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const pre = document.createElement("pre");
|
const pre = document.createElement("pre");
|
||||||
pre.appendChild(document.createTextNode(`${err}`));
|
pre.appendChild(
|
||||||
|
document.createTextNode(`${err}: ${(err as any).state}`)
|
||||||
|
);
|
||||||
document.body.insertBefore(pre, document.body.firstChild);
|
document.body.insertBefore(pre, document.body.firstChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue