Skip to content

[quality] add 33 unit tests for src/lib/sanitizeHtml.ts (XSS defense module) - #6822

Merged
kubestellar-hive[bot] merged 1 commit into
mainfrom
quality/test-sanitize-html
Sep 11, 2026
Merged

[quality] add 33 unit tests for src/lib/sanitizeHtml.ts (XSS defense module)#6822
kubestellar-hive[bot] merged 1 commit into
mainfrom
quality/test-sanitize-html

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Adds src/__tests__/sanitizeHtml.test.ts — 33 unit tests for src/lib/sanitizeHtml.ts, the primary XSS-defense module that sanitizes user-supplied MDX before it is rendered on the docs site.

The module was previously untested by any file in src/__tests__/ even though it is the security-critical layer stripping <script>, <style>, <iframe>, inline on* event handlers, HTML/Jinja/JSX comments, CDATA, DOCTYPE, and processing instructions, plus normalizing <img> / <br> / <hr> / class= attributes.

Coverage

Area Tests
stripUntilStable — no-op, direct match, multi-character bypass loop 3
removeCommentPatterns — complete, unclosed, nested, Jinja, JSX-style, no-op 6
Dangerous-tag stripping — complete pairs, lone openers, partialRe pass 5
Spacer-attack regression guards<sty<script>…</script>le> and inline-handler reconstruction (docs#6233) 2
Inline on* event handler stripping (quoted, unquoted, boolean) 1
Contributor table conversion — well-formed, empty (drops table), escapeAngle on all three fields 3
<img> normalization — no src, missing alt, title preserved 3
Normalization tail — <br>/<hr>, attribute stripping, classclassName, style, meta/link/base, CDATA/PI/DOCTYPE, <sub> unwrap, C0 control stripping, idempotence 10

All 33 tests pass locally with vitest run.

Test-only change; no production files touched. sanitizeHtml.ts is the file most likely to accumulate silent regressions since sanitization changes are subtle and easy to break — this test suite locks in every documented invariant in the module comments.

Refs #6703


Filed by quality agent (ACMM L4/L6 — full mode)

— hive: agent=quality backend=copilot model=claude-opus-4.7

Adds src/__tests__/sanitizeHtml.test.ts covering the primary XSS-defense
module used to sanitize user-supplied MDX before rendering. The module
previously had no direct unit tests, despite carrying the security-critical
duty of stripping script/style/iframe tags, inline event handlers, comments,
CDATA/DOCTYPE/PI, and normalizing img/br/hr/class attributes.

Tests cover:

- stripUntilStable: no-op, direct match, multi-character bypass loop
- removeCommentPatterns: complete/unclosed HTML, nested, Jinja, JSX-style
- Dangerous-tag stripping: complete pairs, lone openers, partial openers
- Spacer-attack resistance for <sty<script>...</script>le> and inline-handler
  reconstruction (Fixes: #6233 regression guard)
- Inline on* event handler stripping
- Contributors table conversion: well-formed, empty (drops the table),
  escapeAngle() coverage on all three fields
- <img> normalization: no src, missing alt, title preserved
- Normalization tail: <br>/<hr>, align/width/height/frameborder/scrolling/
  allowfullscreen stripping, class -> className, style stripping, meta/link/
  base removal, CDATA/PI/DOCTYPE removal, <sub> unwrap, C0 control stripping,
  idempotence.

Test-only change. Refs #6703.

Signed-off-by: quality-agent <quality@kubestellar-hive.local>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: kubestellar-hive[bot] <223556219+Copilot@users.noreply.github.com>
@kubestellar-hive

Copy link
Copy Markdown
Contributor Author

Important

Held for human sign-off on the direction, not on the code.

This PR's only tracked rationale is #6703, which the hive filed itself — issue #6703 was filed by kubestellar-hive[bot] and no human has acknowledged it. An agent-filed issue does not, on its own, establish that anyone agreed to the direction (hivecommons/hive#5117).

The change may well be right; nothing here is a review of it. To release the hold, acknowledge the direction on that issue — comment on it, assign yourself, or add the approved-direction label — and remove the hold label here.

@kubestellar-hive kubestellar-hive Bot added the hold label Sep 9, 2026
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Sep 9, 2026
@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Sep 9, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellar-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 05adc40
🔍 Latest deploy log https://app.netlify.com/projects/kubestellar-docs/deploys/6aa0a78482afa0000993fac6

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 9, 2026
@kubestellar-prow kubestellar-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 9, 2026
@kubestellar-prow

Copy link
Copy Markdown

Hi @kubestellar-hive[bot]. Thanks for your PR.

I'm waiting for a kubestellar member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.


it('loops until stable to catch multi-character bypass (interleaved pattern)', () => {
// <scr<script>ipt> collapses to <script> after one pass; loop catches it.
const out = stripUntilStable('<scr<script>ipt>', /<script>/g)
@clubanderson clubanderson removed the hold label Sep 11, 2026
@clubanderson

Copy link
Copy Markdown
Member

Direction acknowledged by hub admin (approved-direction added on #6703); releasing the #5117 hold. This hive runs at ACMM L6 and may act on its own findings.

@kubestellar-hive
kubestellar-hive Bot merged commit 6c18c72 into main Sep 11, 2026
9 of 17 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the quality/test-sanitize-html branch September 11, 2026 16:50
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot dco-signoff: yes Indicates the PR's author has signed the DCO. frontend needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants