-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add RFC 6761–compliant localhost loopback checks so secure cookies work on localhost (fixes: #382) #498
base: master
Are you sure you want to change the base?
feat: Add RFC 6761–compliant localhost loopback checks so secure cookies work on localhost (fixes: #382) #498
Conversation
@Chriss4123 thanks for this pull request! I try to review it by the end of the week. |
…tps and wss protocols.
@colincasey I've completed all the requested changes and also added a comment linking a potentially trustworthy origin and the notion of a "secure" connection in draft-ietf-httpbis-rfc6265bis-19. I'm ready for you to re-review the PR. |
Will look at the integration tests later and find what is causing these issues. Will let you know once all is good. |
Thanks @Chriss4123, I'll hold off on approval until it's clearer why |
fixes: #382
Description
This commit extends how cookies are treated in secure contexts by fully recognizing
localhost
and loopback IPs as trustworthy origins, matching the de facto behavior of all modern browsers and RFC 6761. Previously,tough-cookie
defaultedsecure
totrue
only forhttps:
andwss:
URLs, causing cookies withsecure
to not work withlocalhost
.What Changed
New
secureContext.ts
isPotentiallyTrustworthy(url)
by checking:https
orwss
127.0.0.1/8
and::1
localhost
and*.localhost
IsLocalhost
,IsLoopback
andHostNoBracketsPiece
, located at:IsLocalhost
IsLoopback
HostNoBracketsPiece
cookieJar.ts
Updatehttps
andwss
schemes:isPotentiallyTrustworthy
function which accounts for secure schemes,localhost
addresses and loopback addresses.No existing functionality is removed. Where the old check would return true, so does the new check. The only added functionality is treating
localhost
addresses and loopback addresses as secure contexts which was previously not present.All modern browsers (Chrome et. al) support secure cookies on localhost so it only makes sense
tough-cookie
supports this too.