Repository navigation
Conversation
Cover isUrlSaveForRedirect against open-redirect inputs (other origins, protocol-relative and backslash URLs, javascript:, data:, blob: and file: schemes, encoded and whitespace-prefixed variants, non-root context paths) and the permission helpers in permissions.js (present, absent, array, corrupt and non-array session data). Part of DependencyTrack#1731. Signed-off-by: duderoot <[email protected]>
Assert that the formatters in common.js that build HTML with xss-filters escape hostile input in element content and quoted attributes, neutralise dangerous URL schemes in generated links, and render ordinary input as before. Part of DependencyTrack#1731. Signed-off-by: duderoot <[email protected]>
Add @vitest/coverage-v8, a test-coverage npm script and v8 coverage configuration that emits text and lcov reports into coverage/. No thresholds are enforced. Ignore coverage/ in git, eslint and prettier so a local report does not break the lint and format checks. Signed-off-by: duderoot <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds unit tests for the security-relevant pure helpers and an optional, report-only coverage script. No production code is changed.
src/shared/utils.test.js:isUrlSaveForRedirect(), the open-redirect guard for the post-loginredirectparameter. Covers allowed same-origin paths (including under a non-root context path) and rejection of other origins, protocol-relative and backslash URLs,javascript:/data:/blob:/file:schemes, percent-encoded and whitespace-prefixed variants, disallowed paths and empty input.src/shared/permissions.test.js:hasPermission(),storePermissions()andgetPermissions(), including absent, corrupt and non-array stored data.src/shared/common.test.js: the formatters that build HTML withxss-filters. Hostile input (<script>, attribute break-outs,javascript:links) must come out escaped, and ordinary input must render as before.npm run test-coverage:@vitest/coverage-v8with text and lcov reports incoverage/, and no enforced threshold.coverage/is now ignored by git, ESLint and Prettier, so a local report no longer breaksnpm run eslint. This is a separate commit, so it is easy to drop if unwanted.Addressed Issue
Closes #2102
Follows up on #1731, which was closed after Vitest, Playwright and the test CI workflows covered most of it.
Additional Details
Effectiveness. Tests for existing code pass immediately, so each group was checked by temporarily breaking the guarded logic and confirming the tests fail. Examples: dropping the origin check, the protocol check or the path allowlist in
isUrlSaveForRedirect; inverting or prefix-matching permission checks; removing eachxssFilterscall or swappinguriInDoubleQuotedAttrfor a weaker filter. 28 of 30 such changes are caught. The other two cannot change the result: removing the empty-storage guard ingetPermissions(JSON.parse(null)already yieldsnull, which the array guard handles), and loosening the protocol regex (the origin and path checks already restrict the result).Behaviour documented, not changed:
/loginand/change-passwordare accepted redirect targets, because they are inacceptableRootContextPaths.https://<host>/dashboard) is rejected, because the allowlist compares the raw input against path prefixes.hasPermission()returnsundefined, notfalse, for arguments that are neither a string nor an array.PORTFOLIO_MANAGEMENTdoes not implyPORTFOLIO_MANAGEMENT_READ) or the other way round.Test setup. Tests run in Vitest's default node environment without a DOM library.
window.locationandsessionStorageare stubbed withvi.stubGlobal.@/i18nand@/plugins/toastrare mocked because they access browser globals at import time.common.jslink formatters are exercised with a realvue-routerusingcreateMemoryHistory.176 unit tests pass.
npm run eslint,npm run prettierandnpm run buildare clean.Checklist