google / google/adk-python

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

Đã đóng
#5,851 1 bình luận 0 reaction 1 người được giao Được @sanketpatil06 nhận Xem trên GitHub
web
Ngôn ngữ chính
Python
Star
21.5k
Fork
4k
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
37

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.