Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
12.86k stars 479 forks source link

[assertions] allow cookie-attributes matched in case-insensitive #3265

Open thePanz opened 21 hours ago

thePanz commented 21 hours ago

What is the current bug behavior?

My server answers with the following:

    set-cookie: PHPSESSID=7f79194ea0bbd7f54b8a7da0a8d4d5b6; path=/; secure; httponly; samesite=lax

But the assertions

[Asserts]
cookie "PHPSESSID[Secure]" exists
cookie "PHPSESSID[HttpOnly]" exists

fails with:

   | cookie "PHPSESSID[Secure]" exists
   |   actual:   none
   |   expected: something

What is the expected correct behavior?

Allow to match on the secure attribute too (case insensitive)

Execution context

Possible fixes

Allow of case-insnsitive maches on the attribues? :shrug:
Not sure if the HTTP specs require to handle the attributes in a case-sensitive way, could not find any precise documentation for that

jcamiel commented 11 hours ago

Hi @thePanz

According to RFC6265, attribute name should be treated case-insensitively:

If the attribute-name case-insensitively matches the string "Secure", the user agent MUST append an attribute to the cookie-attribute-list with an attribute-name of Secure and an empty attribute-value.

I think we should follow the spec and fix the actual behavior. Thanks for the issue!

fabricereix commented 2 hours ago

Yes @thePanz, you are right, our cookie attribute query should be case-incentive to match the spec above and to be consistent with the browser.

I have tested the following response headers in Firefox

Set-Cookie: CamelCase=Value; Max-Age=1000; HttpOnly
Set-Cookie: lowercase=value; max-age=1000; httponly
Set-Cookie: UPPERCASE=VALUE; MAX-AGE-age=1000; HTTPONLY

The 3 of them have the same expiration and the HttpOnly attribute set to true.

fabricereix commented 2 hours ago

We can also note that we have already supported the case-insensitivity of the cookie attribute in the Hurl file:

The 2 queries below are equivalent:

cookie "CamelCase[HttpOnly]" exists
cookie "CamelCase[httponly]" exists