Fix: Sanitize SVG to prevent Stored XSS (Fixes #5514) - #5515
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
c219054 to
0509ef2
Compare
|
Hi @jeongbeannnn , Thank you for your contribution! Please fix the failing tests. |
97b1eda to
aece767
Compare
aece767 to
813a31b
Compare
|
Hi @haranrk, I rebuilt this PR on the latest main branch after the web server refactor. The PR now contains one clean commit touching three files, and the merge conflict and accidental Desktop/... paths are gone. The SVG sanitization now lives in api_server.py and is shared by both load_artifact() and load_artifact_version(). It uses an nh3 strict allowlist instead of regex filtering. Local validation:
Could you please review PR #5515 when you have a chance? Thank you! |
Summary
This PR fixes a Stored XSS vulnerability in the ADK web development UI that allows arbitrary JavaScript execution via malicious SVG artifacts (Issue #5514).
Changes
_sanitize_svg_content()function to remove XSS vectors from SVG contentload_artifact()to sanitize SVG artifacts before returning to clients<foreignObject>,<script>tags, and event handler attributesTechnical Details
Vulnerability
The vulnerability exists because the web dev UI uses Angular's
bypassSecurityTrustHtml()to render SVG content without prior sanitization. An attacker can craft a malicious SVG artifact containing:<foreignObject>elements with embedded XHTMLonerror,onload,onclickWhen a developer views the artifact in the dev UI, the XSS payload executes with full access to the developer's credentials and session.
Fix Strategy
Server-side SVG sanitization using regex-based filtering:
<foreignObject>elements completely<script>tagsjavascript:URLsTesting
tests/unittests/cli/test_svg_sanitization.pyVerification
<script>tags ✓References