Skip to content

fix: reject invalid multipart MIME header controls - #105

Merged
jbeckwith-oai merged 1 commit into
mainfrom
codex/harden-multipart-mime-headers
Aug 19, 2026
Merged

fix: reject invalid multipart MIME header controls#105
jbeckwith-oai merged 1 commit into
mainfrom
codex/harden-multipart-mime-headers

Conversation

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

Summary

  • Reject invalid MIME-header control bytes in multipart field names, uploaded filenames, and content types before constructing multipart headers.
  • Preserve valid Unicode, quotes, backslashes, horizontal tabs, supported public APIs, streaming, retry, content-length, and cancellation behavior.
  • Add exhaustive encoder and CLI regression coverage, including nested JSON/YAML keys, every prohibited ASCII control byte, both filename interfaces, reader cleanup, unknown-length streams, and real newline-containing Unix filenames.

Validation

  • GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build ./scripts/test -skip '^TestFilesCreateCLICancelClosesStalledFIFO$' — all repository packages passed; Windows/amd64 tests compiled successfully.
  • GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build go test -race ./internal/apiform ./pkg/cmd -run '^(TestEncode|TestMarshal|TestMultipart|TestFilesCreateCLIRejectsNewlineFilenameBeforeRequest|TestFilesCreateCLIStreams|TestFilesCreateCLIDoesNotReplayUploads|TestImagesEditCLI|TestExactLength|TestOpenFileUpload|TestEmbedFiles)' -count=1
  • GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build go vet ./...
  • GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build ./scripts/lint
  • GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build GOOS=linux GOARCH=amd64 go build ./...

TestFilesCreateCLICancelClosesStalledFIFO was excluded locally because its macOS EPIPE assertion also fails unchanged at the original base revision; Linux CI will run the complete unfiltered suite.

Copilot AI lite review requested due to automatic review settings August 19, 2026 18:20

Copilot AI 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.

Pull request overview

This PR hardens multipart form encoding in the CLI and internal apiform encoder by rejecting ASCII control bytes that can be used for MIME header injection (e.g., CR/LF) in multipart field names, uploaded filenames, and content types.

Changes:

  • Add control-byte validation for multipart field names, filenames, and content types before constructing part headers.
  • Add exhaustive security/regression tests for apiform multipart encoding, including nested decoded JSON/YAML keys and all prohibited ASCII control bytes.
  • Add CLI-level regression tests ensuring invalid multipart header inputs are rejected before reading upload streams and before issuing HTTP requests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
pkg/cmd/multipartheader_test.go Adds CLI/multipart streaming tests to ensure invalid header controls are rejected early (no upload reads, owned readers closed, no requests sent).
internal/apiform/encoder.go Introduces control-byte validation for multipart header-relevant values (field name, filename, content type) before part header construction.
internal/apiform/encoder_security_test.go Adds comprehensive encoder security coverage for control-byte rejection and preservation of valid Unicode/escaping/tab behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jbeckwith-oai
jbeckwith-oai marked this pull request as ready for review August 19, 2026 18:25
@jbeckwith-oai
jbeckwith-oai requested a review from a team as a code owner August 19, 2026 18:25

@HAYDEN-OAI HAYDEN-OAI 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.

Independent deep security review at 0b79621 found no introduced P1/P2 issues.

@jbeckwith-oai
jbeckwith-oai added this pull request to the merge queue Aug 19, 2026
Merged via the queue into main with commit fad98b4 Aug 19, 2026
9 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/harden-multipart-mime-headers branch August 19, 2026 18:47
@openai-sdks openai-sdks Bot mentioned this pull request Aug 19, 2026
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.

3 participants