Skip to content

fix(security): restrict comment data URLs to raster images - #1196

Merged
qwqcode merged 1 commit into
masterfrom
codex/restrict-comment-data-urls
Oct 11, 2026
Merged

qwqcode merged 1 commit into
masterfrom
codex/restrict-comment-data-urls

Conversation

@qwqcode

@qwqcode qwqcode commented Oct 11, 2026

Copy link
Copy Markdown
Member

Comment and preview HTML currently retains data:text/html links. Remove data: from the general URL allowlist and the anchor exception in DOMPurify. Permit inline data only on image src and data-src, with explicit PNG, JPEG, GIF, WebP, AVIF, or BMP MIME types. HTML, JavaScript, SVG, and malformed data URLs are removed; ordinary links and raster images remain supported.

Lazy image URLs pass through DOMPurify to the same per-tag URL validation as normal image sources. Regression tests cover both attributes, entity/control-character variants, Markdown and raw HTML rendering, and the existing backend Markdown sanitizer used for API/email output. The backend already rejects the reported links and needs no implementation change.

Security verification: the reported link survives the old sanitizer, but Chromium 149.0.7827.55 blocked navigation when clicked with both _self and _blank; no script execution was observed. The fixed renderer removes the href before insertion. This confirms an overly broad URL policy, not a reproduced same-origin XSS. MDN documents opaque data origins and modern browsers' top-level navigation restrictions.

Validation:

  • All 124 frontend tests pass, including 61 added regression cases.
  • Full Go suite (make test) passes.
  • Full frontend/sidebar build (pnpm build:all), ESLint, Prettier, and git diff --check pass.
  • Local Chromium checks confirm the reported href is stripped for both navigation targets.

Refs #1176.

@qwqcode
qwqcode merged commit 78b24f7 into master Oct 11, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant