Skip to content

fix(internal): lowercase header names with locale-pinned en-US rule#1933

Open
tsushanth wants to merge 1 commit into
openai:mainfrom
tsushanth:fix/issue-1928-turkish-locale-header-normalization
Open

fix(internal): lowercase header names with locale-pinned en-US rule#1933
tsushanth wants to merge 1 commit into
openai:mainfrom
tsushanth:fix/issue-1928-turkish-locale-header-normalization

Conversation

@tsushanth

Copy link
Copy Markdown

Why

Closes #1928.

`String.prototype.toLowerCase()` applies the host locale to certain Unicode mappings. On a Turkish process locale the uppercase `I` in `OpenAI-Organization` becomes the dotless `ı`, producing `openaı-organization`, which fails Node's HTTP token validation (`TypeError: Header name must be a valid HTTP token`) and tears down the request before it is ever sent. The reporter traced this all the way to `src/internal/headers.ts:77` and verified the workaround.

I also looked at the other call sites where this SDK lowercases header names for matching, and found the redactor in `src/internal/utils/log.ts` does the same thing on the same hot path. There the consequence is more subtle but more serious: an `Authorization` header arriving as `authorızatıon` after the Turkish casing rule never matches the redaction list, so the bearer token would be written verbatim into the logged request representation. Worth fixing in the same PR since it's the same root cause and a security-shaped exposure.

What

  • `src/internal/headers.ts`: `name.toLowerCase()` → `name.toLocaleLowerCase('en-US')` in `buildHeaders`, with a comment linking back to this issue.
  • `src/internal/utils/log.ts`: pre-compute `lowerName = name.toLocaleLowerCase('en-US')` once and use that for the redaction comparisons. (Also removes the five repeated `.toLowerCase()` calls.) Same comment + issue link.

HTTP header names are RFC 9110 ASCII so anchoring on en-US is the correct invariant.

Tests

`tests/buildHeaders.test.ts` — new `lowercases header names with ASCII rules even under a Turkish process locale` test. Monkey-patches `String.prototype.toLowerCase` for the duration of the test to mimic the Turkish casing rule (`I` → `ı`), then verifies the canonical key in the resulting `NullableHeaders` is `openai-organization` and ASCII-only.

`yarn jest tests/buildHeaders.test.ts` → 11 passed. `yarn jest tests/log.test.ts` → 4 passed.

Stainless note

This change is in `src/internal/`, which is generated by Stainless. I considered whether the right path was to wait for the upstream codegen change. Felt it was worth proposing the diff directly anyway because (a) the bug currently corrupts requests / leaks credentials in production on a non-trivial install base, (b) the fix is mechanical and easy to mirror in the generator template, and (c) precedent from openai/anthropic SDK repos suggests external PRs to generated paths are merged when correctness-shaped.

Happy to defer to whatever process you'd prefer for landing this — let me know if you'd like the change in a different form.

Closes openai#1928.

`String.prototype.toLowerCase()` applies the host locale to certain
Unicode mappings. On a Turkish process locale the uppercase `I` in
`OpenAI-Organization` becomes the dotless `ı`, producing
`openaı-organization`, which fails Node's HTTP token validation
(`TypeError: Header name must be a valid HTTP token`) and tears down
the request before it is ever sent.

The same surface — header-name lowercasing for matching purposes — also
appeared in the log redactor in `src/internal/utils/log.ts`. There the
consequence is more subtle but more serious: an `Authorization` header
arriving as `authorızatıon` after the Turkish casing rule never matched
the redaction list, so the bearer token leaked into the logged request
representation.

Replace both with `name.toLocaleLowerCase('en-US')`, which keeps the
casing rule on the locale-invariant ASCII path regardless of the
runtime environment. HTTP header names are RFC-9110 ASCII so en-US is
the right anchor.

Adds a regression test in `tests/buildHeaders.test.ts` that monkey-
patches `String.prototype.toLowerCase` to mimic the Turkish casing
rule, then confirms the resulting canonical key is still
`openai-organization` and ASCII-only.
@tsushanth tsushanth requested a review from a team as a code owner June 10, 2026 18:48
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

1 participant