Skip to content

Prevent invalid images from poisoning resumed threads - #23494

Closed
rhan-oai wants to merge 5 commits into
mainfrom
rhan/fix-image-poisoning
Closed

rhan-oai wants to merge 5 commits into
mainfrom
rhan/fix-image-poisoning

Conversation

@rhan-oai

@rhan-oai rhan-oai commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

Fixes #16605.

A malformed image payload can be persisted into model-visible history and then replayed on later turns or after resume. When the Responses API rejects that replay with an invalid_value .image_url error, the thread can stay poisoned because the same bad payload is reconstructed and sent again.

This PR keeps the fix focused on recognizing those API errors and recovering the thread by rolling back the failed turn. Inline image preflight validation in app-server, protocol conversion, or dynamic tool output paths is intentionally left for a follow-up.

What changed

  • Map additional Responses API invalid-image 400 shapes to CodexErr::InvalidImageRequest(), including .image_url invalid_value responses and the empty-base64 image message.
  • Reuse the existing thread rollback reconstruction path for invalid-image failures so the failed turn is removed from in-memory state and persisted replay history.
  • Emit a ThreadRolledBack event plus a user-facing error when automatic rollback succeeds or fails.
  • Remove the previous placeholder sanitizer path that replaced image content with Invalid image; rollback is now the recovery behavior.
  • Add a regression for the invalid local-image flow that verifies rollback marker persistence, resume behavior, and that the follow-up request does not replay the bad image or placeholder text.

Local testing

Before:
invalid image

After:
Screenshot 2026-05-20 at 4 10 44 PM

Quitting and resuming thread:
Screenshot 2026-05-20 at 4 11 13 PM

Verification

  • cargo fmt --all --check --manifest-path codex-rs/Cargo.toml
  • cargo test -p codex-api --lib map_api_error_maps_invalid_image --manifest-path codex-rs/Cargo.toml
  • cargo test -p codex-api --lib map_api_error_maps_empty_base64_image_message_from_400_body --manifest-path codex-rs/Cargo.toml
  • cargo test -p codex-core --lib context_manager::history::tests --manifest-path codex-rs/Cargo.toml
  • cargo test -p codex-core --lib session::tests::thread_rollback --manifest-path codex-rs/Cargo.toml

@rhan-oai
rhan-oai requested a review from a team as a code owner May 19, 2026 15:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc1e0ef706

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/utils/image/src/lib.rs Outdated
Comment on lines +95 to +101
let bytes = BASE64_STANDARD
.decode(payload)
.map_err(|_| PromptImageUrlError::InvalidBase64Payload)?;
if bytes.is_empty() {
return Err(PromptImageUrlError::EmptyBase64Payload);
}
image::load_from_memory(&bytes).map_err(|_| PromptImageUrlError::InvalidImageBytes)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Bound inline image validation before decoding

When a v2/app-server caller or MCP/dynamic tool supplies a large inline data: image URL, this validator decodes the entire base64 payload and then asks image to parse it without any size cap; the app-server text limit only counts text input, so a single image field can force large allocations/CPU before the input is rejected or forwarded. Please cap the accepted payload size before decoding/parsing, or reuse an existing bounded image-loading path.

Useful? React with 👍 / 👎.

@rhan-oai
rhan-oai force-pushed the rhan/fix-image-poisoning branch 5 times, most recently from b1661f2 to 536a439 Compare May 19, 2026 20:23
@openai openai deleted a comment from chatgpt-codex-connector Bot May 19, 2026
@rhan-oai
rhan-oai marked this pull request as draft May 19, 2026 20:51
@rhan-oai
rhan-oai force-pushed the rhan/fix-image-poisoning branch 2 times, most recently from 283efa3 to aaf4fcd Compare May 20, 2026 00:46
@rhan-oai
rhan-oai force-pushed the rhan/fix-image-poisoning branch from aaf4fcd to ef5acb2 Compare May 20, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expected a base64-encoded data URL with an image MIME type

1 participant