-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix(trace-viewer): reject unsafe snapshot tag names #42712
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
Changes from all commits
261d9ff
6b0816a
fbeb249
169e8e4
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 |
|---|---|---|
|
|
@@ -126,6 +126,34 @@ test('snapshot renderer handles case-insensitive iframe tag names', () => { | |
| expect(html).toContain('__playwright_src__'); | ||
| }); | ||
|
|
||
| test('snapshot renderer drops unsafe tag names that smuggle attributes', () => { | ||
| const renderer = new SnapshotRenderer(new LRUCache(1_000_000), [], [makeSnapshot({ | ||
| html: ['HTML', {}, ['BODY', {}, ['img src=x onerror=alert(1)', {}], 'safe']], | ||
|
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. can you share more info about how this could actually happen? i thought we already did a lot of sanitization that would prevent this so im concerned we're adding additional protection for something that cant actually happen
Contributor
Author
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.
A recorded page cannot produce this. Capture uses live A zip opened with The existing filters only match exact names ( Same crafted-zip model as the SCRIPT / on* / srcdoc / object / embed / doctype guards already in this file.
|
||
| })], [], 0); | ||
| const { html } = renderer.render(); | ||
| expect(html).not.toContain('onerror=alert(1)'); | ||
| expect(html).not.toContain('<img src=x'); | ||
| expect(html).toContain('safe'); | ||
| }); | ||
|
|
||
| test('snapshot renderer still renders ordinary custom elements', () => { | ||
| const renderer = new SnapshotRenderer(new LRUCache(1_000_000), [], [makeSnapshot({ | ||
| html: ['HTML', {}, ['BODY', {}, | ||
| ['MY-WIDGET', { 'id': 'w' }, 'hello'], | ||
| ['MY-WIDGET_V2', { 'id': 'w2' }, 'v2'], | ||
| ['MY-WIDGET.V2', { 'id': 'w3' }, 'dot'], | ||
| ['math-α', { 'id': 'm' }, 'alpha'], | ||
| ['my-élément', { 'id': 'e' }, 'elem'], | ||
| ]], | ||
| })], [], 0); | ||
| const { html } = renderer.render(); | ||
| expect(html).toContain('<MY-WIDGET id="w">hello</MY-WIDGET>'); | ||
| expect(html).toContain('<MY-WIDGET_V2 id="w2">v2</MY-WIDGET_V2>'); | ||
| expect(html).toContain('<MY-WIDGET.V2 id="w3">dot</MY-WIDGET.V2>'); | ||
| expect(html).toContain('<math-α id="m">alpha</math-α>'); | ||
| expect(html).toContain('<my-élément id="e">elem</my-élément>'); | ||
| }); | ||
|
|
||
| test('stripAnsiEscapes should not exhibit polynomial backtracking', () => { | ||
| // \x1b[ + 50000 semicolons + non-terminal character. | ||
| // Before the fix this took >3 seconds due to O(n^2) backtracking. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.