-
Notifications
You must be signed in to change notification settings - Fork 29
fix: validate postMessage origin in LiveControls to prevent XSS #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,8 +59,32 @@ const snippet = (live: Live) => { | |
| globalThis.window.location.href = `${href}`; | ||
| } | ||
| }; | ||
| const TRUSTED_ORIGINS = [ | ||
| "https://deco.cx", | ||
| "https://admin.deco.cx", | ||
| "https://play.deco.cx", | ||
| "https://admin-cx.deco.page", | ||
| "https://deco.chat", | ||
| "https://admin.decocms.com", | ||
| "https://decocms.com", | ||
| "https://studio.decocms.com", | ||
| ]; | ||
| const isTrustedOrigin = (origin: string) => | ||
| TRUSTED_ORIGINS.indexOf(origin) !== -1 || | ||
| (origin.startsWith("https://") && origin.endsWith(".deco.cx")) || | ||
| origin === globalThis.window.location.origin; | ||
|
|
||
| const onMessage = (event: MessageEvent<EditorEvent>) => { | ||
| if (!isTrustedOrigin(event.origin)) { | ||
| return; | ||
| } | ||
| const { data } = event; | ||
| if ( | ||
| typeof data !== "object" || data === null || | ||
| typeof (data as { type?: unknown }).type !== "string" | ||
| ) { | ||
| return; | ||
| } | ||
| switch (data.type) { | ||
| case "editor::inject": { | ||
| return eval(data.args.script); | ||
|
Comment on lines
+82
to
90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate Line 90 assumes Proposed fix- switch (data.type) {
- case "editor::inject": {
- return eval(data.args.script);
- }
- }
+ switch (data.type) {
+ case "editor::inject": {
+ if (
+ typeof (data as { args?: { script?: unknown } }).args?.script !== "string"
+ ) {
+ return;
+ }
+ return eval((data as { args: { script: string } }).args.script);
+ }
+ }🧰 Tools🪛 Biome (2.4.14)[error] 90-90: eval() exposes to security risks and performance issues. (lint/security/noGlobalEval) 🪛 OpenGrep (1.20.0)[ERROR] 90-90: eval() with dynamic input can execute arbitrary code. Avoid dynamic code evaluation entirely, or use a safe alternative. (coderabbit.code-injection.eval-js) 🤖 Prompt for AI Agents |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Validate
args.scriptbefore dispatchingeditor::inject; the current shape check still allows malformed messages to reachdata.args.scriptand throw.Prompt for AI agents