An adversarial pass found 5 Critical XSS sinks where props declared number/enum in TypeScript were interpolated raw into exported HTML attribute values, trusting the type — but nothing enforces it at runtime (AI update_props only validates node_id; deserialized saved state is untyped JSON). Fixed all 5 (NumberCounter data-target, StarRating aria-label, FormContainer method, ContactForm/InputField input type) plus 6 sibling sinks found by an exhaustive audit of every attribute-value interpolation across src/components: a JS-source injection into ContentSlider's inline setInterval script, a prototype-pollution-adjacent allowlist gap in Section's divider-shape lookup, TextareaField rows, Testimonials rating aria-label, HeroSimple textAlign, and MapEmbed zoom. Adds shared sanitizeFormMethod/sanitizeInputType allowlist helpers to utils/escape.ts alongside the existing escapeAttr/safeUrl/cssValue primitives. Every fix is TDD'd: a malicious-value test reproduces the raw injection against the pre-fix code, then passes after the fix. 502 tests green (npx vitest run), tsc + vite build green (npm run build). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import { describe, test, expect } from 'vitest';
|
|
import { HtmlBlock } from './HtmlBlock';
|
|
|
|
const toHtml = (HtmlBlock as any).toHtml;
|
|
|
|
describe('HtmlBlock.toHtml sanitizes raw code (A4.1)', () => {
|
|
test('strips <script> and on-handlers from exported output', () => {
|
|
const { html } = toHtml({ code: '<script>alert(1)</script><p onclick="x">hi</p>' }, '');
|
|
expect(html).not.toContain('<script');
|
|
expect(html).not.toContain('onclick');
|
|
expect(html).toContain('<p>hi</p>');
|
|
});
|
|
|
|
test('does not wrap output in an unsanitized element carrying the style prop raw', () => {
|
|
// toHtml only ever returns the sanitized `code` blob -- there is no
|
|
// wrapper <div style="..."> in the exported HTML, so a malicious
|
|
// `style` prop (e.g. an attacker-controlled object with a breakout
|
|
// toString()) has nothing to splice into.
|
|
const malicious = { toString: () => 'color:red" onmouseover="alert(1)' } as any;
|
|
const { html } = toHtml({ code: '<p>hi</p>', style: malicious }, '');
|
|
expect(html).not.toMatch(/onmouseover/);
|
|
expect(html).not.toMatch(/<div/);
|
|
expect(html).toBe('<p>hi</p>');
|
|
});
|
|
});
|