feat(ai): Redact base64 data URLs in image_url content blocks #5953
3 issues
High
AttributeError when image_url content is a string instead of dict - `sentry_sdk/ai/utils.py:600`
The _is_image_type_with_blob_content function at line 600 assumes image_url is always a dict by calling .get("url", ""). However, OpenAI's format allows image_url to be a string directly (e.g., {"type": "image_url", "image_url": "https://..."}), as handled in transform_openai_content_part (lines 142-143). When a string is passed, this will raise AttributeError: 'str' object has no attribute 'get', causing a runtime crash during blob redaction.
Also found at:
sentry_sdk/ai/utils.py:659-660
Medium
AttributeError when image_url is a string instead of a dict - `sentry_sdk/ai/utils.py:600`
The _is_image_type_with_blob_content function assumes image_url is always a dict, but OpenAI's format also supports a string shorthand (e.g., {"type": "image_url", "image_url": "data:image/jpeg;base64,..."}). When image_url is a string, calling .get("url", "") on it will raise AttributeError: 'str' object has no attribute 'get'. This causes redact_blob_message_parts to crash when processing messages with the string format, potentially leaking base64 image content to Sentry span data.
Also found at:
sentry_sdk/ai/utils.py:659-660
TypeError when redacting image_url that is a string instead of a dict - `sentry_sdk/ai/utils.py:684-685`
Line 685 assumes item["image_url"] is a dict when performing item["image_url"]["url"] = BLOB_DATA_SUBSTITUTE. If image_url is a string (which is valid per OpenAI's format), this will raise TypeError: 'str' object does not support item assignment. This is a separate issue from the detection bug since even if detection were fixed, the redaction would still fail.
Also found at:
sentry_sdk/ai/consts.py:4-6
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 1 | 1m 57s | $1.42 |
| find-bugs | 2 | 2m 57s | $2.99 |
| skill-scanner | 0 | 50.9s | $0.57 |
| security-review | 0 | 2m 48s | $0.78 |
Duration: 8m 34s · Tokens: 3.1M in / 29.8k out · Cost: $5.78 (+extraction: $0.02, +merge: $0.00, +fix_gate: $0.01, +dedup: $0.00)