Repository navigation
feat: enhance axios instance to strip sensitive auth headers on cross-origin redirects - #7578
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
WalkthroughStrips sensitive auth headers ( Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/bruno-tests/src/redirect/index.js (1)
106-109: Hardcoded port creates inconsistency with configurableCROSS_ORIGIN_PORT.
packages/bruno-tests/src/index.jsdefinescrossOriginPortviaprocess.env.CROSS_ORIGIN_PORT || 8082, but this route hardcodes8082. If someone overrides the env var, the redirect will target the wrong port.Consider injecting the port dynamically or documenting that
CROSS_ORIGIN_PORTmust remain8082for this test.♻️ Option: Pass port via app.locals
In
packages/bruno-tests/src/index.js:app.locals.crossOriginPort = crossOriginPort;Then in this file:
router.get('/cross-origin', function (req, res) { - res.status(302).set('Location', 'http://localhost:8082/headers').send(); + const port = req.app.locals.crossOriginPort || 8082; + res.status(302).set('Location', `http://localhost:${port}/headers`).send(); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-tests/src/redirect/index.js` around lines 106 - 109, The /cross-origin route currently hardcodes port 8082 in the redirect (router.get('/cross-origin')), which conflicts with the configurable CROSS_ORIGIN_PORT used in startup (crossOriginPort). Update the route to use the runtime-configured port rather than the literal 8082: read the port from app.locals.crossOriginPort (set in packages/bruno-tests/src/index.js where crossOriginPort is computed) or from process.env.CROSS_ORIGIN_PORT, then build the Location header using that value so the redirect respects the configured CROSS_ORIGIN_PORT.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-cli/src/utils/axios-instance.js`:
- Around line 29-42: The response interceptor in makeAxiosInstance is missing
the redirect-origin header stripping logic used in the CLI axios instance;
update the response/error interceptor in packages' makeAxiosInstance to parse
original and redirect URLs (like the CLI code that computes originalOrigin/new
URL(redirectUrl).origin) and, when origins differ, delete
Authorization/Proxy-Authorization headers from requestConfig.headers (handle
both lowercase and capitalized keys) inside the try/catch fallback;
alternatively, for OAuth2 token requests you can set maxRedirects: 0 by default
for that instance or for token endpoint requests to prevent cross-origin
redirect leaks.
---
Nitpick comments:
In `@packages/bruno-tests/src/redirect/index.js`:
- Around line 106-109: The /cross-origin route currently hardcodes port 8082 in
the redirect (router.get('/cross-origin')), which conflicts with the
configurable CROSS_ORIGIN_PORT used in startup (crossOriginPort). Update the
route to use the runtime-configured port rather than the literal 8082: read the
port from app.locals.crossOriginPort (set in packages/bruno-tests/src/index.js
where crossOriginPort is computed) or from process.env.CROSS_ORIGIN_PORT, then
build the Location header using that value so the redirect respects the
configured CROSS_ORIGIN_PORT.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e8fdaa43-c451-4909-82a3-d73ddb542bb1
📒 Files selected for processing (6)
packages/bruno-cli/src/utils/axios-instance.jspackages/bruno-electron/src/ipc/network/axios-instance.jspackages/bruno-tests/collection/redirects/Test Cross Origin Redirect Strips Auth.brupackages/bruno-tests/collection/redirects/Test Same Origin Redirect Preserves Auth.brupackages/bruno-tests/src/index.jspackages/bruno-tests/src/redirect/index.js
sanish-bruno
left a comment
There was a problem hiding this comment.
PR Review
Found 3 issue(s): 1 security suggestion, 1 minor bug, 1 nit.
Summary
- Good security improvement — stripping auth headers on cross-origin redirects aligns with CVE-2018-1000007 mitigation in curl 7.58+ and browser behavior.
- Origin comparison via
URL.origincorrectly handles port normalization, scheme differences, and credential stripping. - The fail-open
catchblock could be tightened: when URL parsing fails, the safer default for a security feature is to strip rather than preserve sensitive headers. - Test route hardcodes port
8082while the server uses a configurablecrossOriginPortvariable — these should stay in sync. - Auth-stripping logic is duplicated across CLI and Electron with different
URLconstructor calls — follows existing codebase patterns but worth noting for future DRY-up.
0a23e86 to
6b6e46c
Compare
…-origin redirects - Implemented logic to remove authorization headers when redirecting to a different origin, aligning with security best practices (CVE-2018-1000007). - Added logging for stripped headers in the Electron IPC axios instance. - Updated test server to support cross-origin redirection for testing purposes.
6b6e46c to
abadb52
Compare
| delete requestConfig.headers['authorization']; | ||
| delete requestConfig.headers['Authorization']; | ||
| delete requestConfig.headers['proxy-authorization']; | ||
| delete requestConfig.headers['Proxy-Authorization']; |
There was a problem hiding this comment.
Header names are case-insensitive, use lowercase comparison to ensure consistent matching.
| timeline.push({ | ||
| timestamp: new Date(), | ||
| type: 'info', | ||
| message: `Stripped Authorization headers: redirect crosses origin (${originalOrigin} → ${redirectOrigin})` |
There was a problem hiding this comment.
Is this a valid timeline event?
|
This requires further product discussion — should we preserve the current behavior and introduce an opt-in override at the request and/or collection settings level? |
|
Yes, we should do this after we introduce a "Follow Authorization header" setting for users who need the old behavior. |
Description
JIRA
AuthorizationandProxy-Authorizationheaders when a redirect crosses origins (different host, port, or scheme)Fixes #7570 and #5704
Test plan
npx bruno run collection/redirects/Test\ Cross\ Origin\ Redirect\ Strips\ Auth.bru— auth strippednpx bruno run collection/redirects/Test\ Same\ Origin\ Redirect\ Preserves\ Auth.bru— auth preservedContribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
New Features
Tests