Skip to content

fix: parse OPENAI_CUSTOM_HEADERS with commas inside quoted values#9252

Closed
DOsinga wants to merge 1 commit into
mainfrom
fix/8495-custom-headers-comma-in-quotes
Closed

fix: parse OPENAI_CUSTOM_HEADERS with commas inside quoted values#9252
DOsinga wants to merge 1 commit into
mainfrom
fix/8495-custom-headers-comma-in-quotes

Conversation

@DOsinga
Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga commented May 15, 2026

Fixes #8495

The parse_custom_headers function was splitting naively on commas, breaking header values that contain commas (e.g. x-litellm-tags="tag1,tag2").

This replaces the parser with a quote-aware version that treats content between double quotes as a single value.

Changes:

  • Rewrote parse_custom_headers to handle quoted values containing commas
  • Added 3 unit tests covering simple, quoted-with-commas, and mixed scenarios

Copy link
Copy Markdown

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

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: 5286e2fdb2

ℹ️ 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 crates/goose/src/providers/openai.rs Outdated
Comment on lines +837 to +838
while i < len && chars[i] != '=' {
i += 1;
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 Stop key scan at commas when parsing malformed entries

The new parser scans for = without treating , as a segment boundary, so a malformed chunk (for example k1=v1,,k2=v2 or k1=v1,invalid,k2=v2) causes the next valid header to be merged into the previous key (e.g. ",k2" / "invalid,k2") and k2 is never parsed correctly. This is a regression from the previous implementation, which skipped invalid segments and still preserved subsequent valid headers, and it can silently send wrong header names in production when users include an accidental extra comma.

Useful? React with 👍 / 👎.

Fixes #8495

The parse_custom_headers function was splitting naively on commas,
breaking header values that contain commas (e.g. x-litellm-tags="tag1,tag2").

Replace with a quote-aware parser that treats content between double
quotes as a single value.

Signed-off-by: Douwe Osinga <douwe@squareup.com>
@DOsinga DOsinga force-pushed the fix/8495-custom-headers-comma-in-quotes branch from 5286e2f to b87caf3 Compare May 15, 2026 14:48
Copy link
Copy Markdown

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

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

ℹ️ 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 +835 to +837
match ch {
'"' => in_quotes = !in_quotes,
',' if !in_quotes => {
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 quote characters in parsed header values

The quote-handling branch toggles in_quotes but never appends " to current, so every double quote inside a header value is silently removed during parsing. This mutates legitimate values (for example structured auth parameters or JSON-like metadata) and can also mis-parse escaped-quote inputs such as x-meta="a\"b,c" by flipping quote state at the wrong time, which can corrupt subsequent key/value boundaries.

Useful? React with 👍 / 👎.

@DOsinga
Copy link
Copy Markdown
Collaborator Author

DOsinga commented May 18, 2026

Superseded by #9306 which uses shlex for quote-aware tokenization instead of a hand-rolled parser.

@DOsinga DOsinga closed this May 18, 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.

Not respecting OPENAI_CUSTOM_HEADERS that have commas in values

1 participant