fix(web2): stop stamping an empty Authorization on every proxied request - #972
fix(web2): stop stamping an empty Authorization on every proxied request#972Shitikyan wants to merge 1 commit into
Conversation
The outbound Authorization header was keyed on `requireAuthForAll`, which actually governs INBOUND access to the DAHR proxy (the x-dahr-session-id check in isAuthorizedRequest). That flag defaults to true on production, so every proxied request went out carrying `Bearer undefined` regardless of whether the caller supplied a token. Permissive targets ignore the bogus header — which is why httpbin.org proxied fine and DAHR looked healthy — while targets that validate it reject the request: api.github.com answers 401 "Bad credentials" and raw.githubusercontent.com answers 404. Keying the header on the flag also meant a token passed off production was silently dropped. Forward the header only when the caller actually supplied a token. The inbound session-id control is untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe proxy now forwards ChangesProxy authorization forwarding
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| Filename | Overview |
|---|---|
| src/features/web2/proxy/Proxy.ts | Ties the outbound bearer header to the caller-supplied token and removes the unrelated inbound-auth configuration gate. |
| src/features/web2/proxy/Proxy.test.ts | Adds focused authorization-header tests, but the configured test command does not discover this file. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/features/web2/proxy/Proxy.test.ts:1
**Regression Tests Are Not Discovered**
The repository's test script uses `--testMatch '**/tests/**/*.ts'`, which does not match this file under `src/features/web2/proxy/`. The normal test workflow therefore skips these cases, so an authorization-header regression can pass without failing the configured suite.
Reviews (1): Last reviewed commit: "fix(web2): stop stamping an empty Author..." | Re-trigger Greptile
| @@ -0,0 +1,77 @@ | |||
| // Importing Proxy pulls the node runtime in (SharedState -> chain -> logger -> | |||
There was a problem hiding this comment.
Regression Tests Are Not Discovered
The repository's test script uses --testMatch '**/tests/**/*.ts', which does not match this file under src/features/web2/proxy/. The normal test workflow therefore skips these cases, so an authorization-header regression can pass without failing the configured suite.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/features/web2/proxy/Proxy.test.ts
Line: 1
Comment:
**Regression Tests Are Not Discovered**
The repository's test script uses `--testMatch '**/tests/**/*.ts'`, which does not match this file under `src/features/web2/proxy/`. The normal test workflow therefore skips these cases, so an authorization-header regression can pass without failing the configured suite.
How can I resolve this? If you propose a fix, please make it concise.
Fixes #959.
Root cause
Not a stale token, as the report guessed — the proxy sends an Authorization header nobody asked for.
The outbound
Authorizationheader was keyed onrequireAuthForAll. That flag actually governs inbound access to the DAHR proxy — thex-dahr-session-idcheck inisAuthorizedRequest— and says nothing about what the target site should receive. It defaults toSharedState.PROD, so on the public testnet every proxied request went out carryingBearer undefined, whether or not the caller supplied a token (exceptionsis empty by default, so nothing was exempt).That explains both reported symptoms and why DAHR looked healthy:
https://httpbin.org/get→ 200, because permissive targets ignore a bogus Authorization headerapi.github.com→ 401 "Bad credentials", because GitHub validates itraw.githubusercontent.com→ 404, GitHub's answer to invalid auth on raw contentIt also meant a token passed off production was silently dropped, since the flag is false there.
Fix
Forward the header only when the caller actually supplied a token. The inbound session-id control is untouched —
isAuthorizedRequeststill gates access to the proxy exactly as before. The outbound gaterequiresAuthorizationhad no other caller and is removed, along with the now-unusedtargetUrlparameter.Tests
New
Proxy.test.ts(there was no proxy coverage at all). Verified non-vacuous: restoring the unconditional injection makes the first case fail.undefinedBearer <token>x-dahr-session-idheader is still stamped🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests