fix: locale-sensitive header normalization#1941
Open
jbeckwith-oai wants to merge 1 commit into
Open
Conversation
7147463 to
65ed8ad
Compare
HAYDEN-OAI
approved these changes
Jun 16, 2026
HAYDEN-OAI
left a comment
There was a problem hiding this comment.
looks good overall. thanks for the careful root-cause analysis and targeted coverage!
| const lowerName = name.toLowerCase(); | ||
| if (!seenHeaders.has(lowerName)) { | ||
| targetHeaders.delete(name); | ||
| targetHeaders.delete(lowerName); |
There was a problem hiding this comment.
nice fix, and the regression coverage for locale-sensitive Headers implementations is convincing. one edge case worth following up on: toLowerCase() performs full unicode case conversion, so an invalid name like cooKie becomes the valid cookie before Headers can reject it. validating the original name against the ascii http-token grammar before lowercasing would preserve the existing rejection behavior without reintroducing the turkish locale issue.
65ed8ad to
1eeaa2c
Compare
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
Fixes #1928.
This updates
buildHeadersto normalize header names to lowercase ASCII before passing them intoHeaders.delete()andHeaders.append().Root cause
The original issue reports
OpenAI-OrganizationandOpenAI-Projectbecoming invalid header names likeopenaı-organizationunder a Turkish locale. Plain JavaScriptString.prototype.toLowerCase()is not locale-sensitive in Node, so changing only the internal comparison key is not enough. The issue workaround points at the real failure mode: a bundled/runtimeHeadersimplementation may normalize the mixed-case header name with Turkish locale rules when we calldelete()orappend()with the original name.By handing
Headersthe SDK's already-normalized ASCII header name, we avoid depending on the runtime's header-name casing behavior.Validation
pnpm exec jest tests/buildHeaders.test.ts --runInBandenv LANG=tr_TR.UTF-8 LC_ALL=tr_TR.UTF-8 pnpm exec jest tests/buildHeaders.test.ts --runInBandpnpm exec jest tests/index.test.ts tests/lib/azure.test.ts tests/log.test.ts tests/lib/workload-identity.test.ts tests/lib/bedrock.test.ts tests/api-resources/webhooks.test.ts --runInBandpnpm exec jest tests/buildHeaders.test.ts tests/api-resources/chat/completions/completions.test.ts --runInBandpnpm exec jest tests/api-resources/beta/threads/threads.test.ts tests/api-resources/videos.test.ts --runInBandpnpm exec prettier --check src/internal/headers.ts tests/buildHeaders.test.tspnpm exec eslint src/internal/headers.ts tests/buildHeaders.test.tspnpm exec tsc --noEmitpnpm build