fix: reject invalid multipart MIME header controls - #105
Merged
Conversation
There was a problem hiding this comment.
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
apiformmultipart 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
marked this pull request as ready for review
August 19, 2026 18:25
HAYDEN-OAI
approved these changes
Aug 19, 2026
HAYDEN-OAI
left a comment
Contributor
There was a problem hiding this comment.
Independent deep security review at 0b79621 found no introduced P1/P2 issues.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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=1GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build go vet ./...GOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build ./scripts/lintGOCACHE=/Users/jbeckwith/.cache/openai-cli-go-build GOOS=linux GOARCH=amd64 go build ./...TestFilesCreateCLICancelClosesStalledFIFOwas excluded locally because its macOSEPIPEassertion also fails unchanged at the original base revision; Linux CI will run the complete unfiltered suite.