fix: accept Bearer prefix on public API key auth - #1990
Open
giladresisi wants to merge 1 commit into
Open
Conversation
Strix Security ReviewNo security issues found. Updated for Reviewed by Strix |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
What kind of change does this PR introduce?
Bug fix (backend, public API auth).
PublicAuthMiddleware.usenow strips an optionalBearerprefix (case-insensitive) from theAuthorizationheader before matching it against the organization's API key or apos_OAuth token. Previously the header value was matched as an exact string, so any client sending the conventionalAuthorization: Bearer <key>form got a 401 "Invalid API key" even though the key itself was valid. Everything after the prefix strip - key lookup, OAuth token path, subscription check - is unchanged.Why was this change needed?
A support ticket (August 2026) from a customer running unattended publishing automation against the public API reported intermittent 401s "even though the API key is valid and stored unchanged". Investigation found nothing server-side that would 401 a valid key; the one client-side shape that reproduces it exactly is some code paths adding the standard
Bearerprefix while others send the raw key. Accepting both forms removes the whole failure class and matches how most HTTP clients and SDKs send tokens by default.Other information:
Came out of a support-ticket investigation together with two sibling PRs improving Instagram and Threads container-error messages; each is independent.
QA
Tested end to end against a running backend: raw key,
Bearer <key>and lowercasebearer <key>all return 200 with the org's integrations; a wrong key returns 401 "Invalid API key" with and without the prefix; a missing header still returns 401 "No API Key found".curl -H "Authorization: <key>" http://localhost:3000/public/v1/integrations- expect 200 with the integration listcurl -H "Authorization: Bearer <key>" http://localhost:3000/public/v1/integrations- expect the same 200 (was 401 "Invalid API key" before this fix)curl -H "Authorization: Bearer wrong" http://localhost:3000/public/v1/integrations- expect 401 "Invalid API key"curl http://localhost:3000/public/v1/integrationswith no header - expect 401 "No API Key found"Checklist: