feat: Add RFC 6761–compliant localhost loopback checks so secure
cookies work on localhost (fixes: #1676)
#4038
+107
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes: #1676
Description
Contribution Checklist:
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
set to never be sent tolocalhost
.What Changed
New
trustworthy-util.js
isPotentiallyTrustworthy(url)
by checking:https
,wss
,file
127.0.0.1/8
and::1
localhost
and*.localhost
IsLocalhost
,IsLoopback
andHostNoBracketsPiece
, located at:IsLocalhost
IsLoopback
HostNoBracketsPiece
cookies.js
Update{ secure: isPotentiallyTrustworthy(url) }
option tocookieJar.getCookiesSync()
.tough-cookie
’s built-in:tough-cookie
does by default—plus treat localhost/loopback the same as modern browsers. No existing functionality is removed, only expanded.Testing this change
secure
cookie would not be sent to/getcookie
after it was set by/setcookie
due tosecure
being set toTrue
.secure
cookie would be sent to/getcookie
which mirrors the behavior of modern browsers.All modern browsers (Chrome et al.) and many other API testing clients (Postman et al.) handle
http://localhost
as a trustworthy origin. It only makes sense that this behavior also exists in Bruno.