Skip to content

fix(security): strengthen DOM-clobbering defenses - #199

Merged
JosunLP merged 1 commit into
devfrom
fix/179-dom-clobbering
Jul 6, 2026
Merged

fix(security): strengthen DOM-clobbering defenses#199
JosunLP merged 1 commit into
devfrom
fix/179-dom-clobbering

Conversation

@JosunLP

@JosunLP JosunLP commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #179 (Low; defense-in-depth).

DOM-clobbering protection only stripped id/name values whose exact value was in a ~30-entry reserved list, and the classic duplicate-id HTMLCollection vector (<a id=x></a><a id=x name=y>) passed unchanged. The list was also missing many high-value targets (attributes, nodeName, getElementById, defaultView, implementation, …).

Fix

  • Expanded RESERVED_IDS with the missing global/document/node/traversal targets.
  • Duplicate-id stripping in sanitize-core.ts: the first occurrence of an id is kept; later elements sharing it have their id dropped, so named access resolves to a single node.
  • Documented that the id/name denylist is defense-in-depth, not a complete guarantee — fully untrusted content should drop id/name entirely.

Verification

  • New tests: duplicate id="x" reduced to one occurrence; several newly-added reserved ids (attributes, getElementById, defaultView, implementation) are stripped. Both fail on the pre-fix code.
  • security/core/view suites: all pass. tsc --noEmit clean.

🤖 Generated with Claude Code

Expanded RESERVED_IDS with the many missing high-value clobbering targets
(attributes, nodeName, getElementById, defaultView, implementation, DOM
traversal props, document methods, …) and added duplicate-id stripping in
sanitize-core: two elements sharing an id turn getElementById/named
access into a clobberable HTMLCollection (the classic <a id=x><a id=x
name=y> vector), so later duplicates are now dropped.

Documented that the id/name denylist is defense-in-depth, not a complete
guarantee — fully untrusted content should drop id/name entirely.

Fixes #179

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 740b9207-c8c8-4644-82b7-ae48924b6732

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/179-dom-clobbering

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added security Changes to the security module tests Chenges to the tests labels Jul 6, 2026
@JosunLP
JosunLP merged commit ae34e26 into dev Jul 6, 2026
9 checks passed
@JosunLP
JosunLP deleted the fix/179-dom-clobbering branch July 6, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Changes to the security module tests Chenges to the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant