Skip to content

Fix OpenAI input image sanitization#384

Merged
ablaszkiewicz merged 2 commits intoPostHog:masterfrom
vikas5914:fix-openai-input-image-sanitization
Feb 6, 2026
Merged

Fix OpenAI input image sanitization#384
ablaszkiewicz merged 2 commits intoPostHog:masterfrom
vikas5914:fix-openai-input-image-sanitization

Conversation

@vikas5914
Copy link
Contributor

@vikas5914 vikas5914 commented Dec 7, 2025

Summary

  1. Extend sanitize_openai_image to redact base64 data when OpenAI’s Responses API sends input_image items where image_url is a string (as documented here).

  2. Restore the regression test for that payload format so we cover both dict-style image_url objects and string URLs.
    The previous check only handled { "type": "image_url", "image_url": { "url": ... } }. But OpenAI also allows:

{
    "type": "input_image",
    "image_url": f"data:image/jpeg;base64,{base64_image}",
}

Example from the official docs:

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-4.1-mini",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "what's in this image?"},
            {
                "type": "input_image",
               "image_url": f"data:image/jpeg;base64,{base64_image}",
            },
        ],
    }],
)

print(response.output_text)

Without this fix, base64 strings in that shape weren’t redacted.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. posthog/ai/sanitization.py, line 99-102 (link)

    style: inconsistent type checking - sanitize_openai_image checks isinstance(item.get("image_url"), str) but this function only checks "image_url" in item

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@vikas5914
Copy link
Contributor Author

@ablaszkiewicz Sorry for tagging you but any chance to review this?

@ablaszkiewicz ablaszkiewicz requested review from a team and removed request for a team December 11, 2025 09:00
@ablaszkiewicz
Copy link
Contributor

lgtm ✅ Python pipeline is currently broken. We are fixing it

@vikas5914
Copy link
Contributor Author

@ablaszkiewicz hey , any update on this

@ablaszkiewicz
Copy link
Contributor

@vikas5914 can you please recreate this PR as a new one? You can tag me there

@ablaszkiewicz ablaszkiewicz merged commit b6e6633 into PostHog:master Feb 6, 2026
19 of 21 checks passed
@ablaszkiewicz
Copy link
Contributor

@vikas5914 nevermind. It went through

@ablaszkiewicz
Copy link
Contributor

ablaszkiewicz commented Feb 6, 2026

@vikas5914 Ooops there was no version.py change and no changelog. My bad I didn't check that. I've just opened this PR which will actually deploy this change #425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants