Packages

tough-cookie

6.1.0 · 6 Nov 2026BSD-3-Clause202.3M / weekRepositorynpmAtom feed

Your version

6.1.0

Latest6 Nov 2026Where it was published

Summary· from the note as AI read it

Migration neededRead before upgrading: 8 changes to make.

Before you upgrade

  • Secure cookies from http origins now rejected; check origins or set enforceSecureOriginOnStorage false
  • setCookie now rejects Secure cookies from insecure origins; handle error or opt out
  • Opt out via enforceSecureOriginOnStorage if relying on storing Secure cookies from http
  • __Host- cookies must set an explicit Path=/ attribute
  • Cookie.validate() now fails for invalid token names; check validation logic
  • __Host- cookies must set an explicit Path=/ attribute
  • Cookie.validate() now fails for invalid token names; check validation logic
  • Secure cookies from http origins now rejected; check origins or opt out

New

  • New exported PrefixSecurityMode type for the prefixSecurity option.
  • The getCookiesSync, getCookieString*, getSetCookieStrings* and setCookieSync methods now accept a URL as well as a string, matching their async counterparts.
  • feat: introduce PrefixSecurityMode string literal union type
  • feat: add enforceSecureOriginOnStorage option to opt out of Secure-cookie origin rejection

In short

8 breaking4 new7 fixed22 internal

  • Breaking

    Secure cookies are rejected when set from an insecure origin

  • Breaking

    CookieJar now refuses to store a Secure cookie set from a URL that isn't potentially trustworthy, such as plain http://example.com, per RFC 6265bis §5.7 step 13. https: and wss: URLs are still accepted, and so are localhost and loopback addresses while allowSecureOnLocal is enabled (the default). setCookie() now rejects with Cookie is Secure but this is not a secure connection, or drops the cookie silently when ignoreError: true is passed.

  • Breaking

    This changes behavior that existing v6 code may rely on. To keep storing Secure cookies no matter which origin set them, opt out with:

  • Breaking

    __Host- cookies now need an explicit Path=/ attribute. Having the default path come out as / is no longer enough.

  • Breaking

    Cookie.validate() now returns false for names that aren't valid HTTP tokens, such as empty names, names with separators or control characters, and non-ASCII names. Parsing and storage are unchanged.

  • Breaking

    fix: require explicit Path attribute for __Host- prefixed cookies

  • Breaking

    fix: validate cookie names against the HTTP token grammar

  • Breaking

    fix: reject Secure cookies set over untrustworthy origins

Release note

Notable changes

Secure cookies are rejected when set from an insecure origin (#656, #663)

CookieJar now refuses to store a Secure cookie set from a URL that isn't potentially trustworthy, such as plain http://example.com, per RFC 6265bis §5.7 step 13. https: and wss: URLs are still accepted, and so are localhost and loopback addresses while allowSecureOnLocal is enabled (the default). setCookie() now rejects with Cookie is Secure but this is not a secure connection, or drops the cookie silently when ignoreError: true is passed.

This changes behavior that existing v6 code may rely on. To keep storing Secure cookies no matter which origin set them, opt out with:

new CookieJar(store, { enforceSecureOriginOnStorage: false })

The opt-out applies only to storage. On retrieval, Secure cookies are still returned only for secure origins, the same as in v6.0.x. The setting survives serialize()/deserialize() and clone().

Other behavior changes

  • __Host- cookies now need an explicit Path=/ attribute. Having the default path come out as / is no longer enough (#608).

  • Cookie.validate() now returns false for names that aren't valid HTTP tokens, such as empty names, names with separators or control characters, and non-ASCII names. Parsing and storage are unchanged (#650).

  • An explicit SameSite=None is now kept when serializing with Cookie.toString() and getSetCookieStrings(); it used to be dropped (#639).

  • An IPv4 address in the Domain attribute is now accepted instead of being treated as a public suffix (#630).

Additions

  • New exported PrefixSecurityMode type for the prefixSecurity option (#659, #667).

  • The getCookiesSync, getCookieString*, getSetCookieStrings* and setCookieSync methods now accept a URL as well as a string, matching their async counterparts (#655).

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.