fix: prevent XSS in markdown rendering and ATOM feed#1495
Merged
mattwoberts merged 4 commits intomainfrom Apr 11, 2026
Merged
Conversation
Re-enable HTML entity encoding that was disabled during Tiptap editor integration (the editor outputs markdown, not HTML, so encoding is safe). Remove dangerous html.UnescapeString call in ATOM feed comment rendering. Add HTML tag stripping fallback for SSR when DOMPurify is unavailable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix prettier formatting for XSS test inputs array (single line, double quotes). Fix Go test assertion — alert() text content is expected in escaped output, only raw <script> tags should be absent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The encodeHTML function converts < and > to entities, so text like onerror safely appears as text content inside entity-encoded tags. Assertions now check for actual dangerous HTML elements rather than matching harmless text content. Fix plaintext expected value for b tags. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the quick fix. The pre-encoding approach before marked is solid, one suggestion: consider adding a backend test for javascript: URIs in comments to mirror the frontend coverage in feed_test.go. |
…ering-leading-to-pot
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.
Summary
Fixes GHSA-wm2w-gfh7-qg69 — Unsafe Markdown Rendering Leading to Potential XSS.
public/services/markdown.ts— was disabled during Tiptap editor integration (commit ac36ede), but the Tiptap editor outputs markdown (configured withhtml: false), not HTML, so encoding</>beforemarkedprocesses input is safe and necessaryhtml.UnescapeString()inapp/handlers/feed.go— comment content is stored as-is in the DB, so unescaping before markdown rendering needlessly converts HTML entities back to raw HTML in ATOM feed outputDOMPurify.isSupportedis false (SSR/older browsers), strip HTML tags instead of returning raw unsanitized input<script>,<img onerror>,<svg onload>,javascript:URIs; backend test verifying<script>tags are escaped in ATOM feed outputTest plan
<script>alert(1)</script>— verify it renders as escaped text<img src=x onerror=alert(1)>— verify no JS executes/feed/global.atomand/feed/posts/{n}.atom— verify no unescaped HTMLmake lintandmake test