tough-cookie
6.1.0 · 6 Nov 2026BSD-3-Clause202.3M / weekRepositorynpmAtom feed
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
PrefixSecurityModetype for theprefixSecurityoption. - The
getCookiesSync,getCookieString*,getSetCookieStrings*andsetCookieSyncmethods now accept aURLas well as astring, 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
Securecookies are rejected when set from an insecure origin - Breaking
CookieJarnow refuses to store aSecurecookie set from a URL that isn't potentially trustworthy, such as plainhttp://example.com, per RFC 6265bis §5.7 step 13.https:andwss:URLs are still accepted, and so arelocalhostand loopback addresses whileallowSecureOnLocalis enabled (the default).setCookie()now rejects withCookie is Secure but this is not a secure connection, or drops the cookie silently whenignoreError: trueis passed. - Breaking
This changes behavior that existing v6 code may rely on. To keep storing
Securecookies no matter which origin set them, opt out with: - Breaking
__Host-cookies now need an explicitPath=/attribute. Having the default path come out as/is no longer enough. - Breaking
Cookie.validate()now returnsfalsefor 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 explicitPath=/attribute. Having the default path come out as/is no longer enough (#608).Cookie.validate()now returnsfalsefor 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=Noneis now kept when serializing withCookie.toString()andgetSetCookieStrings(); it used to be dropped (#639).An IPv4 address in the
Domainattribute is now accepted instead of being treated as a public suffix (#630).
Additions
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.