Skip to content

feat: enhance axios instance to strip sensitive auth headers on cross-origin redirects - #7578

Open
abhishek-bruno wants to merge 1 commit into
usebruno:mainfrom
abhishek-bruno:fix/strip-auth-header-on-cross-origin-redirect
Open

abhishek-bruno wants to merge 1 commit into
usebruno:mainfrom
abhishek-bruno:fix/strip-auth-header-on-cross-origin-redirect

Conversation

@abhishek-bruno

@abhishek-bruno abhishek-bruno commented Mar 26, 2026 •

Copy link
Copy Markdown
Member

Description

JIRA

  • Strip Authorization and Proxy-Authorization headers when a redirect crosses origins (different host, port, or scheme)
  • Matches curl 7.58+ and browser behavior (CVE-2018-1000007)
  • Applies to both Electron and CLI axios interceptors

Fixes #7570 and #5704

Test plan

  • npx bruno run collection/redirects/Test\ Cross\ Origin\ Redirect\ Strips\ Auth.bru — auth stripped
  • npx bruno run collection/redirects/Test\ Same\ Origin\ Redirect\ Preserves\ Auth.bru — auth preserved
  • Existing redirect tests still pass

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

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

    • Enhanced HTTP redirect security: Authorization headers are removed when a request follows a redirect to a different origin, and preserved for same-origin redirects.
  • Tests

    • Added end-to-end tests verifying auth header behavior for cross-origin and same-origin redirects.
    • Test environment extended with a cross-origin redirect endpoint to validate stripping behavior.

@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 76a3a8d9-41da-4603-a32f-3408acee415d

📥 Commits

Reviewing files that changed from the base of the PR and between 6b6e46c and abadb52.

📒 Files selected for processing (6)
  • packages/bruno-cli/src/utils/axios-instance.js
  • packages/bruno-electron/src/ipc/network/axios-instance.js
  • packages/bruno-tests/collection/redirects/Test Cross Origin Redirect Strips Auth.bru
  • packages/bruno-tests/collection/redirects/Test Same Origin Redirect Preserves Auth.bru
  • packages/bruno-tests/src/index.js
  • packages/bruno-tests/src/redirect/index.js
✅ Files skipped from review due to trivial changes (1)
  • packages/bruno-tests/collection/redirects/Test Cross Origin Redirect Strips Auth.bru
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/bruno-cli/src/utils/axios-instance.js
  • packages/bruno-electron/src/ipc/network/axios-instance.js
  • packages/bruno-tests/src/index.js
  • packages/bruno-tests/collection/redirects/Test Same Origin Redirect Preserves Auth.bru

Walkthrough

Strips sensitive auth headers (authorization, Authorization, proxy-authorization, Proxy-Authorization) from redirected requests when the redirect target origin differs from the original request origin. The origin comparison is try/catch‑protected. Adds tests and local test servers to validate same‑origin preservation and cross‑origin stripping.

Changes

Cohort / File(s) Summary
CLI axios instance
packages/bruno-cli/src/utils/axios-instance.js
On redirect, attempt to compare original and target origins; if origins differ, remove auth headers from the redirected request. Origin parsing is wrapped in try/catch.
Electron axios instance
packages/bruno-electron/src/ipc/network/axios-instance.js
Same origin-check and auth-header stripping on cross-origin redirects; additionally record a timeline entry when Authorization headers are removed. try/catch protects URL parsing.
Redirect test cases
packages/bruno-tests/collection/redirects/Test Cross Origin Redirect Strips Auth.bru, packages/bruno-tests/collection/redirects/Test Same Origin Redirect Preserves Auth.bru
Add tests: cross‑origin redirect verifies auth header is stripped; same‑origin redirect verifies auth header is preserved.
Test servers & routes
packages/bruno-tests/src/index.js, packages/bruno-tests/src/redirect/index.js
Add CROSS_ORIGIN_PORT/second server, new /redirect-to-headers (same‑origin) and /cross-origin (302 to http://localhost:8082/headers) endpoints for testing redirect behaviors.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant OriginServer
participant CrossOriginServer
Client->>OriginServer: GET /api (Authorization: Bearer ...)
OriginServer-->>Client: 302 Location: http://localhost:8082/headers
Client->>Client: parse original and target URLs (try/catch)
alt different origins
Client->>Client: remove authorization / proxy-authorization headers
else same origin
Client->>Client: preserve headers
end
Client->>CrossOriginServer: GET /headers (headers depending on origin check)
CrossOriginServer-->>Client: 200 OK (response)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

🔐 A redirect whispered, "Follow me afar,"
Bruno checked origins before sharing the bar.
Secrets stayed hidden when hosts did not match,
Headers now guarded, no credential dispatch. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enhancing axios instances to strip sensitive auth headers on cross-origin redirects, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR implements the primary requirement from #7570: stripping Authorization and Proxy-Authorization headers on cross-origin redirects, matching curl 7.58+ behavior and addressing CVE-2018-1000007.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objectives: axios instance modifications, test infrastructure setup for cross-origin testing, and comprehensive test coverage for both cross-origin and same-origin redirect scenarios.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/bruno-tests/src/redirect/index.js (1)

106-109: Hardcoded port creates inconsistency with configurable CROSS_ORIGIN_PORT.

packages/bruno-tests/src/index.js defines crossOriginPort via process.env.CROSS_ORIGIN_PORT || 8082, but this route hardcodes 8082. If someone overrides the env var, the redirect will target the wrong port.

Consider injecting the port dynamically or documenting that CROSS_ORIGIN_PORT must remain 8082 for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 73df422 and 0a23e86.

📒 Files selected for processing (6)
  • packages/bruno-cli/src/utils/axios-instance.js
  • packages/bruno-electron/src/ipc/network/axios-instance.js
  • packages/bruno-tests/collection/redirects/Test Cross Origin Redirect Strips Auth.bru
  • packages/bruno-tests/collection/redirects/Test Same Origin Redirect Preserves Auth.bru
  • packages/bruno-tests/src/index.js
  • packages/bruno-tests/src/redirect/index.js

@sanish-bruno sanish-bruno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.origin correctly handles port normalization, scheme differences, and credential stripping.
  • The fail-open catch block 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 8082 while the server uses a configurable crossOriginPort variable — these should stay in sync.
  • Auth-stripping logic is duplicated across CLI and Electron with different URL constructor calls — follows existing codebase patterns but worth noting for future DRY-up.

@abhishek-bruno
abhishek-bruno force-pushed the fix/strip-auth-header-on-cross-origin-redirect branch from 0a23e86 to 6b6e46c Compare April 2, 2026 13:00
…-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.
@abhishek-bruno
abhishek-bruno force-pushed the fix/strip-auth-header-on-cross-origin-redirect branch from 6b6e46c to abadb52 Compare April 3, 2026 07:29
delete requestConfig.headers['authorization'];
delete requestConfig.headers['Authorization'];
delete requestConfig.headers['proxy-authorization'];
delete requestConfig.headers['Proxy-Authorization'];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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})`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid timeline event?

@bijin-bruno

Copy link
Copy Markdown
Collaborator

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?
cc - @sreelakshmi-bruno @anusree-bruno @naman-bruno

@sreelakshmi-bruno

Copy link
Copy Markdown
Collaborator

Yes, we should do this after we introduce a "Follow Authorization header" setting for users who need the old behavior.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop sending the Authorization header during a 302 redirect if the host is not the same

4 participants