Test/safelink inert rendering coverage#512
Open
Favourejiro wants to merge 2 commits into
Open
Conversation
Add RTL cases for trailing-slash path differences in NavLink's startsWith-based active logic (issue Disciplr-Org#321): a trailing slash on `to` that the current path lacks stays inactive, and a current path that appends a trailing slash to `to` is active.
Tighten SafeLink coverage and the link-safety it relies on (issue Disciplr-Org#365): - Add a full unsafe-scheme matrix (javascript:, data:, empty, whitespace, missing scheme, userinfo-bearing) asserting the inert [Invalid Link] span and its rejected-URL title, plus children-rendering in both branches. - Enforce target="_blank" and rel="noopener noreferrer" against caller overrides by spreading caller props before the safety attributes. - Reject userinfo-bearing URLs (e.g. https://trusted.com@evil.com) in normalizeEvidenceUrl, closing a credential/phishing vector.
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.
closes #365
tighten unit-test coverage for
SafeLink's inert rendering andrel/targetattribute enforcement across the fullunsafe-scheme matrix.
While extending the tests, the issue's required assertions surfaced two real link-safety gaps that had to be fixed for the assertions to
hold. Both are small, security-positive changes.
Changes
src/components/SafeLink.tsx— enforce safety attributesPreviously
{...props}was spread aftertarget/rel, so a caller could override them (e.g.rel=""ortarget="_self"),silently defeating tab-nabbing protection. The spread now comes before the enforced attributes, so
target="_blank"andrel="noopener noreferrer"always win while non-conflicting props (e.g.className) still pass through.src/utils/url.ts— reject userinfo-bearing URLsnormalizeEvidenceUrlaccepted URLs likehttps://trusted.com@evil.combecause the protocol washttps:. Userinfo(
username/password) is now rejected — it's a common credential/phishing vector that hides the real host.src/components/__tests__/SafeLink.test.tsx— expanded coveragetest.each):javascript:,data:, empty, whitespace-only, missing-scheme, and userinfo-bearing URLs allrender the inert
[Invalid Link]span with theRejected URL: …title.http/https(incl. query strings) render an<a>withtarget="_blank"andrel="noopener noreferrer".target/relcannot override the enforced values.classNameare forwarded.Testing
npm run test -- src/components/tests/SafeLink.test.tsx src/utils/tests/url.test.ts
SafeLink.test.tsx— 14 passingurl.test.ts— 10 passingValidationDetail,ConfirmationModal,EvidenceUpload) — 49 passing, no regressions in link safety.