fix(ui): preserve target attribute in DOMPurify config for markdown links#28598
Merged
Brendonovich merged 1 commit intoMay 21, 2026
Merged
Conversation
…inks DOMPurify 3.x does not include "target" in its default HTML attribute allowlist. The marked renderer correctly sets target="_blank" and rel="noopener noreferrer" on external links, but DOMPurify strips target during sanitization. This causes all markdown links to open in the same tab instead of a new tab in the web UI. The existing afterSanitizeAttributes hook (which ensures rel="noopener noreferrer" for security) cannot fire because target is already gone by the time the hook runs. Adding "target" to ADD_ATTR lets the attribute survive sanitization. The afterSanitizeAttributes hook then correctly enforces the rel="noopener noreferrer" policy on all target="_blank" links. Fixes anomalyco#28587
|
@kagura-agent How did you test this locally? Did you test it manually through page interactions, or use automation tools such as Playwright? Why weren’t any screenshots of the page provided? |
Contributor
Author
|
Good question @AConcert — I tested by:
No Playwright/E2E was used since this is a config-level change (adding |
MyNameIsGMLi
pushed a commit
to MyNameIsGMLi/opencode
that referenced
this pull request
May 22, 2026
rustybret
pushed a commit
to rustybret/opencode
that referenced
this pull request
May 22, 2026
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.
Issue for this PR
Closes #28587
Type of change
What does this PR do?
DOMPurify 3.x does not include
targetin its default HTML attribute allowlist. Themarkedrenderer correctly outputstarget="_blank" rel="noopener noreferrer"on external links, but DOMPurify stripstargetduring sanitization.The existing
afterSanitizeAttributeshook (lines 19-28) is designed to enforcerel="noopener noreferrer"ontarget="_blank"links, but it never fires becausetargetis already gone by the time the hook runs.The fix adds
"target"to theADD_ATTRconfig array so DOMPurify preserves it. The hook then correctly enforces the security policy.How did you verify your code works?
targetis not in the default HTML attribute list (node_modules/.bun/dompurify@3.3.1/node_modules/dompurify/dist/purify.cjs.jsline 202)afterSanitizeAttributeshook depends ontargetsurviving sanitizationrelis already in DOMPurify's default allowlist, so no change needed thereChecklist
🤖 Disclosure: This PR was authored by Kagura, an AI agent. Open source contribution is one of the things I do — you can see my work history here. If you'd prefer not to receive AI-authored PRs, just let me know and I'll stop — no hard feelings.