This is an automated email from the ASF dual-hosted git repository. nickva pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/couchdb-gun.git
commit 879fc5b1151d1f8f516068302bcbc6039b2d2da6 Author: Loïc Hoguin <[email protected]> AuthorDate: Fri Oct 2 17:35:26 2026 +0200 Reject SameSite=None cookies that are not Secure Gun has no document, so a request is same-site. Strict, Lax and Default are stored. None requires Secure. --- src/gun_cookies.erl | 39 +++++++++++++++++++++++++++------------ test/rfc6265bis_SUITE.erl | 5 +++-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/gun_cookies.erl b/src/gun_cookies.erl index 19a68b5..7497574 100644 --- a/src/gun_cookies.erl +++ b/src/gun_cookies.erl @@ -287,18 +287,15 @@ set_cookie_secure_match({Mod, State}, Match) -> set_cookie2(Store, _URI, Attrs, Cookie0) -> Cookie = Cookie0#{same_site => maps:get(same_site, Attrs, default)}, - %% This is where we would perform the same-site checks. - %% - %% It seems that an option would need to be added to Gun - %% in order to define the "site for cookies" value. It is - %% not the same as the site identified by the URI. Although - %% I do wonder if in the case of server push we may consider - %% the requested URI to be the "site for cookies", at least - %% by default. - %% - %% The URI argument will be used if/when the above gets - %% implemented. - set_cookie3(Store, Attrs, Cookie). + %% Gun has no document, so a request is same-site (RFC6265bis 5.2). + %% SameSite=Strict, Lax and Default are therefore stored and sent. + %% SameSite=None still requires the Secure attribute. + case Cookie of + #{same_site := none, secure_only := false} -> + {error, samesite_none_requires_secure}; + _ -> + set_cookie3(Store, Attrs, Cookie) + end. set_cookie3(Store, Attrs, Cookie=#{name := Name, host_only := HostOnly, secure_only := SecureOnly}) -> @@ -961,4 +958,22 @@ wpt_secure_http_test() -> ok. %% WPT: secure/set-from-ws* (Anything special required?) + +%% SameSite=None is stored only when the cookie is also Secure. +samesite_none_requires_secure_test() -> + Https = #{scheme => <<"https">>, host => <<"example.org">>, path => <<"/">>}, + Http = Https#{scheme := <<"http">>}, + {error, samesite_none_requires_secure} = set_cookie( + gun_cookies_list:init(), Https, <<"a">>, <<"b">>, #{same_site => none}), + {error, samesite_none_requires_secure} = set_cookie( + gun_cookies_list:init(), Http, <<"a">>, <<"b">>, #{same_site => none}), + {ok, _} = set_cookie(gun_cookies_list:init(), Https, <<"a">>, <<"b">>, + #{same_site => none, secure => true}), + %% Secure is rejected first on an insecure request. + {error, secure_scheme_only} = set_cookie(gun_cookies_list:init(), Http, + <<"a">>, <<"b">>, #{same_site => none, secure => true}), + {ok, Store} = set_cookie(gun_cookies_list:init(), Http, <<"a">>, <<"b">>, + #{same_site => lax}), + {ok, [#{same_site := lax}], _} = query(Store, Http), + ok. -endif. diff --git a/test/rfc6265bis_SUITE.erl b/test/rfc6265bis_SUITE.erl index 3cbbe0f..c211614 100644 --- a/test/rfc6265bis_SUITE.erl +++ b/test/rfc6265bis_SUITE.erl @@ -317,13 +317,14 @@ wpt_attributes_ctl_httponly(Config) -> <<"testhttponly=t">> } end, "/cookies/attributes", Config). +%% None without Secure is not stored. wpt_attributes_ctl_samesite(Config) -> doc("Test cookie attribute parsing with control characters: " "in SameSite attribute value."), do_wpt_ctl_test(fun(CTL) -> { <<"testsamesite">>, <<"testsamesite=t; SameSite=No", CTL, "ne; SameSite=None">>, - <<"testsamesite=t">> + <<>> } end, "/cookies/attributes", Config). wpt_attributes_ctl_samesite2(Config) -> @@ -332,7 +333,7 @@ wpt_attributes_ctl_samesite2(Config) -> do_wpt_ctl_test(fun(CTL) -> { <<"testsamesite2">>, <<"testsamesite2=t; SameSite=None", CTL>>, - <<"testsamesite2=t">> + <<>> } end, "/cookies/attributes", Config). %% @todo Redirect cookie test.
