@@ -170,6 +170,28 @@ describe("cookie module", function()
170
170
assert .same (" " , s :lookup (" example.com" , " /" , true , false ))
171
171
assert .same (" foo=bar" , s :lookup (" example.com" , " /" , true , true ))
172
172
end )
173
+ describe (" tough cookies" , function ()
174
+ it (" enforces __Secure- prefix" , function ()
175
+ local s = http_cookie .new_store ()
176
+ assert .falsy (s :store (" example.com" , " /" , true , false , nil , http_cookie .parse_setcookie (" __Secure-foo=bar; Secure" )))
177
+ assert .falsy (s :store (" example.com" , " /" , true , false , nil , http_cookie .parse_setcookie (" __Secure-foo=bar" )))
178
+ assert .falsy (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" __Secure-foo=bar;" )))
179
+ assert .truthy (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" __Secure-foo=bar; Secure" )))
180
+ end )
181
+ it (" enforces __Host- prefix" , function ()
182
+ local s = http_cookie .new_store ()
183
+ -- Checks secure flag
184
+ assert .falsy (s :store (" example.com" , " /" , true , false , nil , http_cookie .parse_setcookie (" __Host-foo=bar; Secure" )))
185
+ assert .falsy (s :store (" example.com" , " /" , true , false , nil , http_cookie .parse_setcookie (" __Host-foo=bar" )))
186
+ assert .falsy (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" __Host-foo=bar;" )))
187
+ -- Checks for host only flag
188
+ assert .falsy (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" __Host-foo=bar; Secure; Domain=example.com" )))
189
+ -- Checks that path is /
190
+ assert .falsy (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" __Host-foo=bar; Secure; Path=/path" )))
191
+ -- Success case
192
+ assert .truthy (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" __Host-foo=bar; Secure" )))
193
+ end )
194
+ end )
173
195
describe (" cookie fixing mitigation" , function ()
174
196
it (" ignores already existing path" , function ()
175
197
local s = http_cookie .new_store ()
0 commit comments