Skip to content

[fix] Following redirects discards set cookies without explicit domain #1760

@wilsonjackson

Description

@wilsonjackson

Describe the bug

Node.js version: 16.16.0

OS version: macOS monterey

Description: When redirects are followed (via .redirects()) cookies set by the redirecting server are not persisted correctly.

This bug was introduced with #1757, which assumes that there will always be a request object set on the response received by Agent.prototype._saveCookies. However, _saveCookies is invoked by two events: response and redirect, and that assumption is only true of the response event.

Actual behavior

If a cookie without an explicit domain has already been set in Superagent's cookie jar, that cookie cannot be overwritten using the same parameters during a followed redirect.

Expected behavior

Setting a cookie with the same parameters in a followed redirect should overwrite the previous cookie.

Code to reproduce

https://gist.github.com/wilsonjackson/746aee8f563e8486fa2f99c32baba235

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions