Skip to content

fix: locale-sensitive header normalization#1941

Open
jbeckwith-oai wants to merge 1 commit into
mainfrom
codex/fix-locale-header-normalization
Open

fix: locale-sensitive header normalization#1941
jbeckwith-oai wants to merge 1 commit into
mainfrom
codex/fix-locale-header-normalization

Conversation

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

Summary

Fixes #1928.

This updates buildHeaders to normalize header names to lowercase ASCII before passing them into Headers.delete() and Headers.append().

Root cause

The original issue reports OpenAI-Organization and OpenAI-Project becoming invalid header names like openaı-organization under a Turkish locale. Plain JavaScript String.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/runtime Headers implementation may normalize the mixed-case header name with Turkish locale rules when we call delete() or append() with the original name.

By handing Headers the 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 --runInBand
  • env LANG=tr_TR.UTF-8 LC_ALL=tr_TR.UTF-8 pnpm exec jest tests/buildHeaders.test.ts --runInBand
  • pnpm 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 --runInBand
  • pnpm exec jest tests/buildHeaders.test.ts tests/api-resources/chat/completions/completions.test.ts --runInBand
  • pnpm exec jest tests/api-resources/beta/threads/threads.test.ts tests/api-resources/videos.test.ts --runInBand
  • pnpm exec prettier --check src/internal/headers.ts tests/buildHeaders.test.ts
  • pnpm exec eslint src/internal/headers.ts tests/buildHeaders.test.ts
  • pnpm exec tsc --noEmit
  • pnpm build

@jbeckwith-oai jbeckwith-oai changed the title [codex] Fix locale-sensitive header normalization fix: locale-sensitive header normalization Jun 15, 2026
@jbeckwith-oai jbeckwith-oai force-pushed the codex/fix-locale-header-normalization branch from 7147463 to 65ed8ad Compare June 15, 2026 17:26
@jbeckwith-oai jbeckwith-oai requested a review from HAYDEN-OAI June 15, 2026 17:27
@jbeckwith-oai jbeckwith-oai marked this pull request as ready for review June 15, 2026 17:30
@jbeckwith-oai jbeckwith-oai requested a review from a team as a code owner June 15, 2026 17:30

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

looks good overall. thanks for the careful root-cause analysis and targeted coverage!

Comment thread src/internal/headers.ts
const lowerName = name.toLowerCase();
if (!seenHeaders.has(lowerName)) {
targetHeaders.delete(name);
targetHeaders.delete(lowerName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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.

Bug: TypeError: Header name must be a valid HTTP token ["openaı-organization"] on Turkish Windows/Locale

2 participants