API key verification forwards client User-Agent, causing Python urllib requests to fail
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- node.js, typescript
- Domain
- api, authentication
Research direction
The report names verifyAPIKey() and createBackendApiClient(options) in @clerk/backend, and includes a reproduction repository with an npm run repro script. Read the verification path and compare the outbound request's User-Agent with the incoming request; run the reproduction with both User-Agent values. Done when both requests authenticate successfully with the same credentials. An open linked pull request (#10358) indicates work is already underway.
Written by the indexing model from the issue text.
Description
Preliminary Checks
-
I have reviewed the documentation: https://clerk.com/docs
-
I have searched for existing issues: https://github.com/clerk/javascript/issues
-
I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)
-
This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Reproduction
https://github.com/jandorn/clerk-api-key-user-agent-repro
Publishable key
pk_live_Y2xlcmsudGVsZXNjb3BlLmVuZXJneSQ
Description
Steps to reproduce:
- Clone the reproduction repository and run
npm ci. - Copy
.env.exampleto.envand configure credentials from the same Clerk instance, including a valid API key. - Run
npm run repro.
The script uses unpatched @clerk/[email protected] and calls authenticateRequest(request, { acceptsToken: 'api_key' }) twice with the same credentials. Only the incoming User-Agent changes.
Expected behavior:
Both requests authenticate successfully.
Actual behavior:
Python-urllib/3.11→ upstream HTTP 403 (text/html),isAuthenticated: false, reason:unexpected-error.clerk-api-key-repro/1.0→ upstream HTTP 200 (application/json),isAuthenticated: true.
The full live output is included in the reproduction README.
Suspected cause:
verifyAPIKey() passes the authentication context to createBackendApiClient(options). The context's incoming userAgent overrides the SDK's default User-Agent.
Using the SDK User-Agent for this outbound request resolved the issue in our application:
const client = createBackendApiClient({ ...options, userAgent: USER_AGENT });
Environment
System:
OS: macOS 27.0.1
CPU: (15) arm64 Apple M5 Pro
Memory: 75.17 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 23.11.0 - /opt/homebrew/bin/node
npm: 11.19.1 - /opt/homebrew/bin/npm
pnpm: 10.11.0 - /opt/homebrew/bin/pnpm
bun: 1.3.9 - /Users/jandorn/.bun/bin/bun
Browsers:
Chrome: 155.0.8059.85
Firefox: 144.0.2
Safari: 27.0.1
npmPackages:
@clerk/backend: 3.2.2 => 3.2.2
- Dominant language
- TypeScript
- Stars
- 1.8k
- Forks
- 483
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 325
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from clerk/javascript
-
ClerkAPIError drops meta.lockout_expires_in_seconds from user_locked errorsPossibly taken @umeraamir69 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
clerk/javascript#10026 · 2 comments ·
Maintainers usually reply within 1 day
-
@clerk/nextjs: onBeforeSetActive never settles when invalidateCacheAction rejects (e.g. after a redeploy), so setActive and signOut hang foreverPossibly taken @RaphaelFakhri claimed this 20 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
clerk/javascript#9987 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 44/100
clerk/javascript#10413 · 1 comment ·
Maintainers usually reply within 1 day
-
Dev instances: clerk-js rewrites __clerk_db_jwt non-atomically, concurrent requests fail with dev-browser-missingPossibly taken @umeraamir69 claimed this 3 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
clerk/javascript#10411 ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 55/100
clerk/javascript#10356 ·
Maintainers usually reply within 1 day
All issues in clerk/javascript
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Clouditera/VulnHunter#57 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug bug:behavior clawsweeper:bulk-filed clawsweeper:fix-shape-clear clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:auth-provider issue-rating: 🦞 diamond lobster P2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
openclaw/openclaw#185297 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
apex-dev-tools/apex-log-parser#199 ·
Maintainers usually reply within 1 day