-
Notifications
You must be signed in to change notification settings - Fork 0
fix(security): fail closed on hostile clipboard throw values #351
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
Draft
seonghobae
wants to merge
21
commits into
main
Choose a base branch
from
fix/clipboard-hostile-throw-349
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
758c36c
test(security): reproduce hostile clipboard throw escape
seonghobae ce82230
fix(security): brand clipboard sanitizer errors safely
seonghobae 3f963bf
fix(security): avoid inspecting hostile clipboard throw values
seonghobae 71f19ae
test(security): reject bidi controls in link targets
seonghobae 2041bb7
fix(security): reject bidirectional link controls
seonghobae 01100de
refactor(security): keep SafeLink policy dependency explicit
seonghobae f2262e3
test(security): reproduce Unicode whitespace link bypass
seonghobae 9889496
fix(security): reject Unicode whitespace in link targets
seonghobae 690277d
fix(scope): remove unrelated SafeLink changes
seonghobae c0983b7
fix(scope): restore SafeLink policy ownership
seonghobae 1518a56
fix(scope): drop unrelated SafeLink regressions
seonghobae e54c776
test(security): preserve sanitizer hostile-config regression
seonghobae 3460f2d
test(security): cover primitive clipboard throw containment
seonghobae 9529b81
fix(security): guard primitive clipboard errors
seonghobae 61936f2
chore: synchronize clipboard repair with protected main
seonghobae 6e5a56f
chore: synchronize hostile clipboard containment with protected main
seonghobae 8881f2a
chore: synchronize hostile clipboard containment with protected main
seonghobae a31e4d4
Merge remote-tracking branch 'origin/main' into fix/clipboard-hostile…
seonghobae baea226
test(ci): cover event-specific Python matrix
seonghobae d7f83fc
test(ci): bind Python matrix to event
seonghobae cff066f
revert(ci): restore Office contract owner
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/extensions/SafeClipboardExtension.hostileThrow.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { | ||
| DEFAULT_CLIPBOARD_HTML_BYTES, | ||
| DEFAULT_CLIPBOARD_MAX_DEPTH, | ||
| DEFAULT_CLIPBOARD_MAX_NODES, | ||
| type ClipboardSanitizationError, | ||
| } from './SafeClipboard.js'; | ||
| import { | ||
| SafeClipboard, | ||
| type SafeClipboardOptions, | ||
| } from './SafeClipboardExtension.js'; | ||
|
|
||
| /** | ||
| * Exercise the real ProseMirror paste transform with a hostile value thrown by | ||
| * host option access. The thrown proxy must never be inspected by Inkspan. | ||
| */ | ||
| describe('SafeClipboard hostile thrown-value containment', () => { | ||
| it('fails closed without prototype inspection when a config getter throws a proxy', () => { | ||
| const privateSentinel = new Error('private prototype sentinel'); | ||
| const hostileThrownValue = new Proxy(Object.create(null) as object, { | ||
| getPrototypeOf() { | ||
| throw privateSentinel; | ||
| }, | ||
| }); | ||
| const onError = vi.fn((_error: ClipboardSanitizationError) => undefined); | ||
| const hostileOptions = { | ||
| get config(): never { | ||
| throw hostileThrownValue; | ||
| }, | ||
| maxHtmlBytes: DEFAULT_CLIPBOARD_HTML_BYTES, | ||
| maxNodes: DEFAULT_CLIPBOARD_MAX_NODES, | ||
| maxDepth: DEFAULT_CLIPBOARD_MAX_DEPTH, | ||
| onError, | ||
| document, | ||
| } as SafeClipboardOptions; | ||
|
|
||
| const addPlugins = SafeClipboard.config.addProseMirrorPlugins; | ||
| if (!addPlugins) throw new Error('SafeClipboard plugin factory is unavailable'); | ||
| const plugins = addPlugins.call({ options: hostileOptions } as never); | ||
| const plugin = plugins[0]; | ||
| const transform = plugin?.props.transformPastedHTML; | ||
| if (!plugin || !transform) { | ||
| throw new Error('SafeClipboard paste transform is unavailable'); | ||
| } | ||
|
|
||
| let transformed: string | undefined; | ||
| expect(() => { | ||
| transformed = transform.call(plugin, '<p>private source</p>', {} as never); | ||
| }).not.toThrow(); | ||
|
|
||
| expect(transformed).toBe(''); | ||
| expect(onError).toHaveBeenCalledTimes(1); | ||
| expect(onError).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| code: 'invalid_html', | ||
| message: 'Rich clipboard HTML could not be sanitized.', | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.