-
Notifications
You must be signed in to change notification settings - Fork 70
feat(security): warn once when enableSecureText is disabled + document XSS trade-off #480
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ac877c
feat(security): warn once when enableSecureText is disabled + documen…
gnbm a093eae
feat(security): add showSecureTextWarning option to suppress the warning
gnbm 128a68a
address Copilot review: fire warning on config, accurate XSS scope in…
gnbm 3d105aa
Potential fix for pull request finding
gnbm b61ee18
Potential fix for pull request finding
gnbm 1b76a5f
docs(warning): point console.warn at the properties page (drop dead a…
gnbm a7a84c3
Update virtual-select-1.2.0.min.js
gnbm 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** cSpell:ignore vscomp securetext */ | ||
|
|
||
| // Tests for S1: when enableSecureText is disabled (default), option text is rendered as raw HTML. | ||
| // The plugin should log a single (per page) console warning so the XSS trade-off is discoverable, | ||
| // without changing the default (kept off for large-dataset performance). | ||
|
|
||
| describe('Security: enableSecureText one-time warning (S1)', () => { | ||
| const mount = (win: Window, id: string, extra: Record<string, unknown> = {}) => { | ||
| const doc = win.document; | ||
| const existing = doc.getElementById(id); | ||
| if (existing) { | ||
| existing.remove(); | ||
| } | ||
| const $ele = doc.createElement('div'); | ||
| $ele.id = id; | ||
| doc.body.appendChild($ele); | ||
| // @ts-expect-error - VirtualSelect attached to window by the bundle | ||
| win.VirtualSelect.init({ ele: $ele, options: [{ label: 'A', value: 'a' }], ...extra }); | ||
| return $ele; | ||
| }; | ||
|
|
||
| it('warns once (not per instance) when enableSecureText is disabled', () => { | ||
| cy.visit('get-started'); | ||
| cy.window().then((win) => { | ||
| // reset the one-time flag so the assertion is deterministic regardless of demo dropdowns | ||
| // @ts-expect-error - static flag | ||
| win.VirtualSelect.secureTextWarningShown = false; | ||
| cy.spy(win.console, 'warn').as('warn'); | ||
|
|
||
| mount(win, 'vs-s1-a'); | ||
| mount(win, 'vs-s1-b'); // second instance must NOT warn again | ||
| }); | ||
|
|
||
| cy.get('@warn').its('callCount').should('eq', 1); | ||
| cy.get('@warn').its('firstCall.args.0').should('include', 'enableSecureText'); | ||
| }); | ||
|
|
||
| it('does not warn when enableSecureText is enabled', () => { | ||
| cy.visit('get-started'); | ||
| cy.window().then((win) => { | ||
| // @ts-expect-error - static flag | ||
| win.VirtualSelect.secureTextWarningShown = false; | ||
| cy.spy(win.console, 'warn').as('warnEnabled'); | ||
|
|
||
| mount(win, 'vs-s1-c', { enableSecureText: true }); | ||
| }); | ||
|
|
||
| cy.get('@warnEnabled').should('not.be.called'); | ||
| }); | ||
|
|
||
| it('does not warn when showSecureTextWarning is false (explicit opt-out)', () => { | ||
| cy.visit('get-started'); | ||
| cy.window().then((win) => { | ||
| // @ts-expect-error - static flag | ||
| win.VirtualSelect.secureTextWarningShown = false; | ||
| cy.spy(win.console, 'warn').as('warnOptedOut'); | ||
|
|
||
| mount(win, 'vs-s1-d', { showSecureTextWarning: false }); | ||
| }); | ||
|
|
||
| cy.get('@warnOptedOut').should('not.be.called'); | ||
| }); | ||
|
|
||
| it('warns even when constructed with empty options (options may be loaded later)', () => { | ||
| cy.visit('get-started'); | ||
| cy.window().then((win) => { | ||
| // @ts-expect-error - static flag | ||
| win.VirtualSelect.secureTextWarningShown = false; | ||
| cy.spy(win.console, 'warn').as('warnEmpty'); | ||
|
|
||
| // The warning fires on configuration alone, so a select initialised with no options | ||
| // (then populated later via setOptions / server search) is still flagged. | ||
| const doc = win.document; | ||
| const existing = doc.getElementById('vs-s1-empty'); | ||
| if (existing) { | ||
| existing.remove(); | ||
| } | ||
| const $ele = doc.createElement('div'); | ||
| $ele.id = 'vs-s1-empty'; | ||
| doc.body.appendChild($ele); | ||
| // @ts-expect-error - VirtualSelect attached to window by the bundle | ||
| win.VirtualSelect.init({ ele: $ele, options: [] }); | ||
| }); | ||
|
|
||
| cy.get('@warnEmpty').its('callCount').should('eq', 1); | ||
| cy.get('@warnEmpty').its('firstCall.args.0').should('include', 'enableSecureText'); | ||
| }); | ||
| }); |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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.