Fix C1/C2: XSS via unsanitized style keys and animation attrs
C1: cssPropsToString emitted the camelToKebab'd style-object KEY unsanitized while only sanitizing the VALUE. A malicious style key containing a quote (reachable via AI update_props or deserialized saved state) could close the style="..." attribute and inject a live element. Now validates each key against a CSS property/custom-prop allowlist and drops anything that doesn't match. C2: buildDataAttrs (html-export.ts) interpolated props.animation and props.animationDelay directly into data-animation="..."/ data-animation-delay="..." with no escaping, for every exported node. Now routes both through escapeAttr. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
36c3b2f503
commit
e5f30a4a56
4 files changed
+143
-4
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { exportBodyHtml } from './html-export';
|
||||
|
||||
/**
|
||||
* C2: buildDataAttrs (internal to html-export.ts) previously interpolated
|
||||
* `props.animation` / `props.animationDelay` directly into
|
||||
* `data-animation="${...}"` / `data-animation-delay="${...}"` with no
|
||||
* escaping. Runs for EVERY node (via renderNode -> buildDataAttrs ->
|
||||
* injectAttrs) and is reachable via AI `update_props` + deserialized saved
|
||||
* state. A malicious value like `x"><img src=y onerror=alert(1)>` breaks
|
||||
* out of the attribute and injects a live element.
|
||||
*/
|
||||
describe('buildDataAttrs escapes animation/animationDelay (C2)', () => {
|
||||
const makeState = (props: Record<string, unknown>) =>
|
||||
JSON.stringify({
|
||||
ROOT: {
|
||||
type: { resolvedName: 'Container' },
|
||||
isCanvas: true,
|
||||
props: { tag: 'div', style: {}, ...props },
|
||||
displayName: 'Container',
|
||||
custom: {},
|
||||
hidden: false,
|
||||
nodes: [],
|
||||
linkedNodes: {},
|
||||
},
|
||||
});
|
||||
|
||||
test('malicious animation value is escaped -- no raw breakout, no injected <img>', () => {
|
||||
const payload = 'x"><img src=y onerror=alert(1)>';
|
||||
const state = makeState({ animation: payload });
|
||||
const { html } = exportBodyHtml(state);
|
||||
|
||||
expect(html).not.toContain('<img src=y onerror=alert(1)>');
|
||||
expect(html).not.toMatch(/data-animation="x">/);
|
||||
// The attribute value must be escaped, so no raw `"` or `<` survives
|
||||
// inside the data-animation attribute region.
|
||||
expect(html).toContain('data-animation="x"><img src=y onerror=alert(1)>"');
|
||||
});
|
||||
|
||||
test('malicious animationDelay value is escaped -- no raw breakout', () => {
|
||||
const payload = 'x"><script>alert(1)</script>';
|
||||
const state = makeState({ animation: 'fade-in', animationDelay: payload });
|
||||
const { html } = exportBodyHtml(state);
|
||||
|
||||
expect(html).not.toContain('<script>alert(1)</script>');
|
||||
expect(html).toContain('data-animation-delay="x"><script>alert(1)</script>"');
|
||||
});
|
||||
|
||||
test('normal animation value still emits data-animation="fade-in" unchanged', () => {
|
||||
const state = makeState({ animation: 'fade-in' });
|
||||
const { html } = exportBodyHtml(state);
|
||||
expect(html).toContain('data-animation="fade-in"');
|
||||
});
|
||||
|
||||
test('normal animationDelay value still emits unchanged', () => {
|
||||
const state = makeState({ animation: 'fade-in', animationDelay: '0.5s' });
|
||||
const { html } = exportBodyHtml(state);
|
||||
expect(html).toContain('data-animation-delay="0.5s"');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user