Skip to content

test(sections-editor): cover rich-text link URL-scheme validation - #5012

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
test/rich-text-link-validation-coverage-w2
Open

test(sections-editor): cover rich-text link URL-scheme validation#5012
pedrofrxncx wants to merge 1 commit into
mainfrom
test/rich-text-link-validation-coverage-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Adds regression coverage for isSafeLinkUrl/normalizeLinkUrl in apps/mesh/src/web/components/sections-editor/rich-text-link-validation.ts.

Source: no issue/PR — a gap found while auditing the sections-editor directory: this file had zero test coverage.

Why a maintainer wants it: isSafeLinkUrl is the sole guard preventing a rich-text link inserted through the CMS editor from carrying a javascript:/data:/vbscript: URL. Since links are rendered into <a href> for every visitor of the published page, a regression here (e.g. someone "simplifying" the protocol check, or an allowlist typo) would reopen a stored-XSS vector with no test to catch it.

Trust-boundary justification (C4 gate): this directly meets the security/privacy bar — it validates an untrusted, user-typed URL that crosses into rendered HTML served to site visitors, and its explicit purpose (per its own docstring) is blocking script-executing protocols.

What the test covers: allowed protocols (https/http/mailto/tel/ftp) and relative/fragment links; blocked protocols including case-variant (JavaScript:) and whitespace-in-scheme bypass attempts (java\tscript:, java\nscript:, leading space) that are known real-world sanitizer-bypass techniques, plus other unlisted protocols (ws:, chrome-extension:); and normalizeLinkUrl's trim/bare-domain/pass-through behavior, confirming a dangerous URL that passes through normalizeLinkUrl unchanged still gets rejected by isSafeLinkUrl. I manually verified each bypass case against the actual implementation before writing the assertions (all currently pass — this is a coverage gap being closed, not a bug fix).

Command a reviewer runs: bun test apps/mesh/src/web/components/sections-editor/rich-text-link-validation.test.ts

Checks run locally: bun run fmt, bunx tsc --noEmit in apps/mesh (clean), and the targeted test file above (9 pass). Full CI validates the rest.


Summary by cubic

Adds regression tests for isSafeLinkUrl and normalizeLinkUrl in the sections editor to ensure only safe link schemes are allowed and dangerous ones are blocked. Covers allowed protocols (https/http/mailto/tel/ftp), relative/fragment paths, blocks case/whitespace-bypass variants and other unlisted schemes, and verifies normalization behavior without weakening rejection.

Written for commit 6634b00. Summary will update on new commits.

Review in cubic

Adds regression coverage for isSafeLinkUrl/normalizeLinkUrl — the guard
against javascript:/data:/vbscript: URLs in CMS rich-text links — including
case, whitespace-in-scheme, and other unlisted-protocol bypass attempts.
This trust-boundary function had zero test coverage; a regression here
would let a rich-text link execute script for every visitor of the page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant