Skip to content

fix(sandbox): validate raster view_image content - #4450

Closed
sylvesterkaczmarek wants to merge 11 commits into
openai:mainfrom
sylvesterkaczmarek:fix/view-image-content-validation
Closed

sylvesterkaczmarek wants to merge 11 commits into
openai:mainfrom
sylvesterkaczmarek:fix/view-image-content-validation

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Require view_image to identify signature-bearing raster image formats from the bytes it reads instead of trusting a raster-looking filename.

The previous detector checked known image signatures first, then accepted any filename whose MIME type began with image/. That meant arbitrary bytes stored as report.png, photo.jpg, or another raster image extension could be returned as structured image data.

This change narrows the filename fallback to SVG only. PNG, JPEG, GIF, WebP, BMP, and TIFF require their existing byte signatures. SVG and SVGZ retain the established filename fallback because SVG has no single binary magic value and SVGZ is compressed, so removing filename inference entirely would break valid BOM/prolog/alternate-encoding and compressed SVG inputs that were already supported.

Test plan

Added regression coverage showing that:

  • non-image bytes named fake.png are rejected
  • valid PNG bytes named payload.bin are accepted as PNG
  • SVG inputs beginning with a UTF-8 BOM, comment, or DOCTYPE remain accepted
  • UTF-16 SVG remains accepted
  • compressed SVGZ remains accepted

Repository CI is used for full verification because this environment has GitHub connector access but no materialized dependency checkout.

Issue number

None. Found during a sandbox content-validation audit.

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

Copy link
Copy Markdown

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: f6a6772f4a

ℹ️ 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".

@seratch seratch changed the title fix(sandbox) validate view_image content fix(sandbox): validate view_image content Aug 16, 2026

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before we can merge it, please preserve the deliberately supported SVG path when valid SVG content begins with a UTF-8 BOM, XML comment, or DOCTYPE, and add focused regression coverage for those prolog forms. The current head rejects those files because removing the extension fallback leaves _detect_image_mime_type() recognizing only <svg or <?xml at the start. Please also remove the now-unused path parameter and its Path import.

The invalid-.png test covers the base failure. After these changes and green CI, this should be ready for another review.

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

Copy link
Copy Markdown

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: d4269fc10e

ℹ️ 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".

sylvesterkaczmarek commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed the requested SVG compatibility cases and then simplified the implementation around the supported-format boundary. Raster formats with stable signatures now require byte evidence, while SVG/SVGZ retain the existing filename fallback so BOM/comment/DOCTYPE, UTF-16, and compressed SVG inputs stay compatible without adding an XML/decompression parser to media sniffing. Focused regression coverage includes the maintainer-requested prolog cases plus UTF-16 and SVGZ. The branch is mergeable; GitHub Actions remains gated before jobs are created.

@sylvesterkaczmarek sylvesterkaczmarek changed the title fix(sandbox): validate view_image content fix(sandbox): validate raster view_image content Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 864bd7304c

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 864bd7304c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Copy link
Copy Markdown
Contributor Author

@seratch The requested SVG compatibility coverage is addressed on the current head. I simplified the fix so signature-bearing raster formats require byte evidence, while SVG/SVGZ retain their established filename fallback for BOM/comment/DOCTYPE, UTF-16, and compressed inputs. Fresh Codex and security reviews on 864bd7304c found no issues. CI is still gated before any jobs are created; ready for re-review when available.

@seratch

seratch commented Aug 16, 2026

Copy link
Copy Markdown
Member

@sylvesterkaczmarek can you resolve the CI errors?

Copy link
Copy Markdown
Contributor Author

Resolved the CI failures in 8bd5d1b: the regression test is now Ruff-formatted and explicitly narrows ToolOutputImage.image_url before the three startswith() assertions, addressing the only pyright errors. The previous CI run already passed the Python 3.10–3.14 and Windows test jobs; the failing jobs were limited to formatting and typecheck. Fresh CI should verify the fix.

Copy link
Copy Markdown
Contributor Author

Fresh CI is now fully green on 8bd5d1b. The requested formatting/typecheck fixes are verified; ready for re-review.

@seratch

seratch commented Aug 16, 2026

Copy link
Copy Markdown
Member

We'll merge #4462 instead; your contribution is included in its commit.

@seratch seratch closed this Aug 16, 2026
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.

2 participants