google / google/adk-python

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

Fermée
#5,851 1 commentaire 0 réactions 1 personne assignée Réclamée par @sanketpatil06 Voir sur GitHub
web
Langage dominant
Python
Étoiles
21.5k
Forks
4k
Merge moyen
1 j 14 h
PR mergées (30 j)
37

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.