Fix persistent XSS in data export via unsanitized review messages#2
Open
emrazik wants to merge 1 commit into
Open
Fix persistent XSS in data export via unsanitized review messages#2emrazik wants to merge 1 commit into
emrazik wants to merge 1 commit into
Conversation
Review messages were stored and re-emitted verbatim by the JSON export endpoint and then rendered into a new window via document.write(), allowing stored XSS payloads to execute in any user's browser on export. - routes/dataExport.ts: sanitize review.message with sanitizeSecure() before including it in the export payload - data-export.component.ts: replace document.write() with a safe Blob download so the JSON is saved as a file instead of rendered as HTML Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Finding
NetSPI Finding #1048219768 — Cross-Site Scripting (Persistent) | High
Users can store XSS payloads in product reviews. When any user exports their data at
/#/privacy-security/data-export, those review messages are returned verbatim in the JSON payload and the frontend renders the JSON into a new window withdocument.write(). This executes embedded<script>tags and event-handler attributes in the victim's browser.What changed
routes/dataExport.tsreview.messageis now passed throughsecurity.sanitizeSecure()before being added to the export payload. This strips or escapes any HTML tags from the stored review text before it leaves the server.frontend/src/app/data-export/data-export.component.tsReplaced
window.open('', '_blank').document.write(this.userData)with a Blob-based file download. The JSON string is wrapped in aBlobwithapplication/jsonMIME type, a temporary object URL is created, an<a>element triggers the download, and the URL is revoked immediately after. The browser never parses the content as HTML, so no injected markup can execute regardless of what the server returns.Test plan
<img src=x onerror="alert(1)">, then navigate to/privacy-security/data-exportand export — the downloaded file should contain the sanitized text and no alert should fire🤖 Generated with Claude Code