File tree 2 files changed +7
-8
lines changed
2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -603,17 +603,16 @@ pub type CookieAttributes {
603
603
604
604
/// Helper to create sensible default attributes for a set cookie.
605
605
///
606
- /// NOTE these defaults ensure you cookie is always available to you application.
607
- /// However this is not a fully secure solution.
608
- /// You should consider setting a Secure and/or SameSite attribute.
606
+ /// Note these defaults may not be sufficient to secure your application.
607
+ /// You should consider setting the SameSite field.
609
608
///
610
609
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Attributes
611
- pub fn cookie_defaults() {
610
+ pub fn cookie_defaults(scheme: Scheme ) {
612
611
CookieAttributes(
613
612
max_age: option.None,
614
613
domain: option.None,
615
614
path: Some("/"),
616
- secure: False ,
615
+ secure: scheme == Https ,
617
616
http_only: True,
618
617
same_site: option.None,
619
618
)
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import gleam/atom
2
2
import gleam/dynamic
3
3
import gleam/string_builder
4
4
import gleam/uri . { Uri }
5
- import gleam/http
5
+ import gleam/http . { Http , Https }
6
6
import gleam/option . { None , Some }
7
7
import gleam/should
8
8
@@ -836,7 +836,7 @@ pub fn set_resp_cookie_test() {
836
836
|> should . equal ( Ok ( "k1=v1" ) )
837
837
838
838
http . response ( 200 )
839
- |> http . set_resp_cookie ( "k1" , "v1" , http . cookie_defaults ( ) )
839
+ |> http . set_resp_cookie ( "k1" , "v1" , http . cookie_defaults ( Http ) )
840
840
|> http . get_resp_header ( "set-cookie" )
841
841
|> should . equal ( Ok ( "k1=v1; Path=/; HttpOnly" ) )
842
842
@@ -860,7 +860,7 @@ pub fn set_resp_cookie_test() {
860
860
861
861
pub fn expire_resp_cookie_test ( ) {
862
862
http . response ( 200 )
863
- |> http . expire_resp_cookie ( "k1" , http . cookie_defaults ( ) )
863
+ |> http . expire_resp_cookie ( "k1" , http . cookie_defaults ( Http ) )
864
864
|> http . get_resp_header ( "set-cookie" )
865
865
|> should . equal (
866
866
Ok ( "k1=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; MaxAge=0; Path=/; HttpOnly" ) ,
You can’t perform that action at this time.
0 commit comments