Skip to content

Save cookies on redirect response - #6094

Merged
bijin-bruno merged 1 commit into
usebruno:mainfrom
JeroenVinke:bugfix/save-cookies-after-redirect
Dec 15, 2025
Merged

bijin-bruno merged 1 commit into
usebruno:mainfrom
JeroenVinke:bugfix/save-cookies-after-redirect

Conversation

@JeroenVinke

@JeroenVinke JeroenVinke commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

Description

When the response is a redirect (e.g. 302) the set-cookie headers were not processed.

This problem happened in the collection runner and the CLI.

Let me know if the change is too naive

Are there any automated tests I can add?

Fixes #5658

Contribution Checklist:

  • 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

  • Bug Fixes
    • Improved cookie management for error responses. When cookie storage is enabled, the application now properly persists cookies received from failed HTTP requests. This enhancement ensures consistent session handling across both successful and unsuccessful API calls, providing more reliable authentication and session state management for users working with HTTP error scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI 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.

Pull Request Overview

This PR fixes a bug where set-cookie headers in redirect responses (e.g., 302) were not being processed. The fix adds cookie saving logic to the error response handler, since Axios treats redirects with maxRedirects: 0 as errors.

Key Changes

  • Added cookie saving logic in the error response handler to capture cookies from redirect responses

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JeroenVinke
JeroenVinke force-pushed the bugfix/save-cookies-after-redirect branch from a976753 to c9d2c0f Compare November 14, 2025 07:29

@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.

LGTM. we may need to fix the linting errors

@JeroenVinke
JeroenVinke force-pushed the bugfix/save-cookies-after-redirect branch from c9d2c0f to 18960de Compare December 13, 2025 09:38
@coderabbitai

coderabbitai Bot commented Dec 13, 2025 •

Copy link
Copy Markdown
Contributor

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Two files updated to persist cookies from error responses in CLI and Electron IPC network handlers, extending the existing success-path cookie-saving logic to error paths when cookie storage is enabled.

Changes

Cohort / File(s) Summary
Cookie persistence on error responses
packages/bruno-cli/src/runner/run-single-request.js, packages/bruno-electron/src/ipc/network/index.js
Adds conditional cookie persistence in error response handlers, mirroring success-path behavior to ensure cookies are stored even when requests result in HTTP errors or error responses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify error.response structure and headers availability in both error contexts
  • Confirm cookie-saving function calls are consistent between success and error paths
  • Check that options.disableCookies and preferencesUtil.shouldStoreCookies() conditions are logically equivalent across both files

Possibly related issues

Poem

🍪 Errors once lost their precious crumbs,
Now cookies persist when response comes,
Redirect storms no more shall fail,
The CLI's jar now tells the tale. ✨

Pre-merge checks and finishing touches

✅ 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 summarizes the main change: saving cookies on redirect responses, which directly addresses the linked issue #5658.
Linked Issues check ✅ Passed The code changes successfully implement cookie persistence on redirect responses in both the CLI and collection runner, directly addressing the requirements in issue #5658.
Out of Scope Changes check ✅ Passed All changes are focused on saving cookies from error/redirect responses and are directly related to the stated objective of handling Set-Cookie headers in redirect scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5537c and 18960de.

📒 Files selected for processing (2)
  • packages/bruno-cli/src/runner/run-single-request.js (1 hunks)
  • packages/bruno-electron/src/ipc/network/index.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-cli/src/runner/run-single-request.js
  • packages/bruno-electron/src/ipc/network/index.js
🧬 Code graph analysis (2)
packages/bruno-cli/src/runner/run-single-request.js (3)
packages/bruno-electron/src/ipc/network/index.js (1)
  • saveCookies (43-57)
packages/bruno-electron/src/ipc/network/axios-instance.js (1)
  • saveCookies (18-32)
packages/bruno-cli/src/utils/axios-instance.js (1)
  • saveCookies (9-20)
packages/bruno-electron/src/ipc/network/index.js (3)
packages/bruno-electron/src/store/preferences.js (1)
  • preferencesUtil (178-230)
packages/bruno-electron/src/ipc/network/axios-instance.js (1)
  • saveCookies (18-32)
packages/bruno-cli/src/utils/axios-instance.js (1)
  • saveCookies (9-20)
🔇 Additional comments (2)
packages/bruno-cli/src/runner/run-single-request.js (1)

549-551: LGTM! Fixes the redirect cookie issue.

The addition correctly saves cookies from error responses (including redirects when maxRedirects is 0). This mirrors the success-path behavior at lines 539-541 and ensures Set-Cookie headers are processed regardless of HTTP status code.

packages/bruno-electron/src/ipc/network/index.js (1)

1420-1422: LGTM! Fixes the redirect cookie issue.

The addition correctly saves cookies from error responses (including redirects when maxRedirects is 0). This mirrors the success-path behavior at lines 1381-1383 and ensures Set-Cookie headers are processed regardless of HTTP status code.

Note: The outer shouldStoreCookies() check is redundant (the saveCookies function already checks this at line 44), but maintains consistency with the established pattern used elsewhere in the codebase (lines 787-789, 1381-1383).


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

@bijin-bruno
bijin-bruno merged commit 1b9ea47 into usebruno:main Dec 15, 2025
@sanish-bruno

sanish-bruno commented Dec 15, 2025 •

Copy link
Copy Markdown
Collaborator

This is a related PR #5387 , It is done for both cli as well as electron. and it is handled at the axios level. But, we will have to check, why we needed this changes in the first place cc: @Pragadesh44-Bruno @pooja-bruno @bijin-bruno

@pooja-bruno

Copy link
Copy Markdown
Collaborator

@sanish-bruno, I checked and this doesn’t seem to be related to the PR you attached. This issue is different, and the fix looks fine to me.

@sanish-bruno

Copy link
Copy Markdown
Collaborator

@JeroenVinke I have few doubts,

  1. What happens if we have multiple redirects, the cookies returned by all of them will get saved to request.url, although the cookie is set by another domain. The current logic may work when there is a single redirect, but the behaviour needs to be checked when there is multiple redirects
    packages/bruno-electron/src/ipc/network/axios-instance.js:309 here we always set the cookies to error.config.url

  2. We are already saving the cookies within the error callback for axios instances
    packages/bruno-electron/src/ipc/network/axios-instance.js:309
    packages/bruno-cli/src/utils/axios-instance.js:136
    Why do we have to do this again at multiple places?

cc: @Pragadesh44-Bruno @bijin-bruno

@JeroenVinke

Copy link
Copy Markdown
Contributor Author

@sanish-bruno good points, should I revert the change until we have had time to investigate further?

bijin-bruno added a commit that referenced this pull request Dec 15, 2025
bijin-bruno added a commit that referenced this pull request Dec 15, 2025
@bijin-bruno

Copy link
Copy Markdown
Collaborator

I’m reverting this PR via #6413, as the issue appears to have already been addressed in #5387, and due to time constraints for the v3.0.0 release.

We can revisit this and investigate further if the issue still exists, and address it in a future version.

@JeroenVinke Thanks for your understanding, and we really appreciate the time and effort you put into this contribution.

@ahamayeah59

ahamayeah59 commented Dec 15, 2025 •

Copy link
Copy Markdown

So in wich version of Bruno did you guys resolve this bug ? Because im' actually running 2.15.1 ans the bug is still present.

Thnaks

maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
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.

Unable to retrieve cookies on redirect in CLI / runner

6 participants