Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 246f105 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Author
|
Hi, friendly ping on this one. It's rebased and the checks are green on my side. Happy to adjust anything if you'd like it done differently. Thanks! |
…eader The cleanup looked up the lowercase header name on a plain-object headers bag, so a header written as `Authorization` was never found and the fake CF_TEMP_TOKEN was forwarded upstream. Resolve the existing key case-insensitively before checking and deleting it. The `Headers` path is unchanged. Fixes cloudflare#355
harshbhx
force-pushed
the
fix/355-authorization-header-case
branch
from
November 22, 2026 15:12
6363844 to
246f105
Compare
Author
|
Hi, checking whether this is still of interest. It's rebased on main and the changeset is in. If it's not a fit, no worries, I'll close it. |
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.
Fixes #355
Summary
Strip the injected
CF_TEMP_TOKENfrom the outgoing request even when the wrapped SDK writes the auth header asAuthorization(or any non-lowercase spelling) on a plain-object headers bag.Problem
In
processModelRequest(packages/ai-gateway-provider/src/index.ts) the cleanup read and deletedreq.request.headers[authHeader], whereauthHeaderdefaults to the lowercase"authorization".Headersinstances are case-insensitive, but plain objects are not, so anAuthorizationkey was never found and the fakeBearer CF_TEMP_TOKENwas forwarded to the upstream provider (e.g. OpenRouter) instead of being removed so BYOK / unified billing could apply.Solution
On the plain-object path, find the existing key whose lowercase form equals
authHeader.toLowerCase(), then check and delete that key. TheHeaderspath is unchanged. I did not normalise headers where the request is captured, to keep the change small; happy to do that instead if you prefer.Changes
packages/ai-gateway-provider/src/index.tspackages/ai-gateway-provider/test/request-shaping.test.tsAuthorizationheader.changeset/quiet-headers-match.mdai-gateway-providerBefore / After
Headers
{ Authorization: "Bearer <CF_TEMP_TOKEN>" }:Authorizationvalue are left alone.How to test
pnpm --filter ai-gateway-provider testsrc/index.tschange and re-run: the new "strips a plain-objectAuthorizationheader" test fails.Testing done
Temp-token header cleanupinrequest-shaping.test.ts): temp token stripped fromAuthorizationwhile other headers stay; a realAuthorizationkey is kept.ai-gateway-provider, format, lint, type-check, buildHeadersbranch has no new test: the binding path spreads headers into a plain object, so aHeaderstest would pass vacuously.Notes for reviewers
The tests drive
processModelRequestthrough a small stub model, since the real provider SDKs lowercase the header themselves.