Skip to content

fix(apiform): strip path components from upload filenames - #120

Open
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/apiform-upload-basename
Open

fix(apiform): strip path components from upload filenames#120
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/apiform-upload-basename

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Aug 20, 2026

Copy link
Copy Markdown

Summary

Ensure multipart uploads send only the basename of reader-provided file paths, regardless of whether the path uses POSIX or Windows separators.

Problem

internal/apiform.encodeReader derives filenames from readers exposing Name() with path.Base, which only treats / as a separator. A Windows-style name such as C:\dir\report.pdf can therefore remain unchanged when processed on a non-Windows host or supplied by a cross-platform/custom reader, placing directory components in the multipart filename= parameter instead of just report.pdf.

Fix

Normalize backslash separators before taking the path basename. POSIX paths keep their existing behavior, while Windows-style paths reduce to the same basename representation.

The change is limited to the Name() fallback. Readers that explicitly implement Filename() retain control of the filename they provide.

Regression coverage

Added table-driven multipart tests covering POSIX and Windows-style paths. Both must produce filename="report.pdf", and the serialized body must not contain directory components.

Validation

The branch is based directly on current upstream main (a7719136b8ed401b0c51a05553a5e4f720150307) and contains one DCO-signed commit touching only the multipart encoder plus focused regression coverage. Full repository test execution is left to CI.

Risk

Low. Only the fallback filename derived from a reader's Name() changes, and only by removing directory components. File contents, content type handling, explicit Filename() implementations, field names, and non-file multipart fields are unchanged.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 20, 2026 20:36
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek force-pushed the fix/apiform-upload-basename branch from ff7e2ed to 8095fae Compare August 20, 2026 20:38
@markstuart-oai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T07:56:17.181714Z 47daacf New commits
🔒 Security Review Completed 2026-09-06T07:56:40.757603Z 47daacf New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 8095fae62c

ℹ️ 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 internal/apiform/encoder.go Outdated
}

func multipartBaseName(name string) string {
return path.Base(strings.ReplaceAll(name, `\`, "/"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve backslashes in POSIX basenames

When Name() comes from a real POSIX file whose basename contains a backslash, this unconditional replacement treats a legal filename character as a directory separator. For example, /tmp/invoice\2026.pdf previously produced filename="invoice\\2026.pdf" but now produces filename="2026.pdf", changing the filename observed by the API; only interpret backslashes as separators for recognizably Windows paths or according to the reader's native path semantics.

AGENTS.md reference: AGENTS.md:L38-L43

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 47daacf. Windows-style paths are now normalized only when they are recognizably Windows paths; legal backslashes in POSIX basenames are preserved. Added the /tmp/invoice\\2026.pdf regression. Focused apiform test passes.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 8095fae62c

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.

@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: 47daacf87e

ℹ️ 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 on lines +184 to +185
if len(name) < 2 || name[1] != ':' {
return false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Strip relative Windows path components

On Windows, a reader such as an *os.File opened with a relative path like reports\report.pdf retains that relative name, but this predicate returns false because it has neither a drive prefix nor a UNC prefix. path.Base then treats the backslash as an ordinary character, so the multipart header still sends filename="reports\\report.pdf"; single-backslash rooted paths have the same problem. Account for native Windows path semantics so these common paths are reduced to report.pdf.

AGENTS.md reference: AGENTS.md:L38-L43

Useful? React with 👍 / 👎.

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