google / google/adk-python

Follow-up: allow safe data:image/* schemes via url_filter in SVG sanitizer

Geschlossen
#5,851 1 Kommentar 0 Reaktionen 1 zugewiesene Person Beansprucht von @sanketpatil06 Auf GitHub ansehen
web
Vorherrschende Sprache
Python
Sterne
21.5k
Forks
4k
Ø Merge
1 T. 14 Std.
Gemergte PRs (30 T.)
37

Beschreibung

Follow-up to #5514.

The SVG sanitizer added in that fix currently blocks every `data:` URL inside SVG attributes (href, xlink:href, etc.) as a conservative default. That's the right call for the immediate XSS fix — `data:image/svg+xml` and `data:text/html` are real vectors, and dropping them outright avoids whack-a-mole on MIME parsing edge cases.

Per @'s comment (https://github.com/google/adk-python/issues/5514#issuecomment-4533094365), opening this so the narrower whitelist doesn't get forgotten.

### What's left to do

Wire a `url_filter` (or equivalent attribute callback) into the sanitizer so the scheme check can distinguish safe raster MIME types from script-capable ones:

- allow: `data:image/png`, `data:image/jpeg`, `data:image/gif`, `data:image/webp`
- keep blocking: `data:image/svg+xml`, `data:text/html`, `data:application/*`, anything ambiguous
- keep blocking: `javascript:`, `vbscript:`, plain `data:` with no MIME, MIME with stray whitespace/control chars

### Why it's worth doing later (not now)

In ADK today, raster artifacts surface as their own `image/*` blobs rather than embedded inside SVG, so the current block doesn't degrade the dev UI. But once user-supplied SVGs from external sources show up (e.g., LLM-generated diagrams that inline a small PNG legend), the strict block will start cutting legitimate content. Better to land the relaxation behind a tested filter than to loosen the regex under pressure.

### Suggested tests

```python
# allow
assert sanitize('') # preserved

# block
assert 'data:' not in sanitize('')
assert 'data:' not in sanitize('')
assert 'data:' not in sanitize('') # stray space

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.