Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update request cookie parser to handle zero or more spaces between semicolons #7312

Merged
merged 3 commits into from Nov 9, 2023

Conversation

mrdziuban
Copy link
Contributor

@mrdziuban mrdziuban commented Nov 6, 2023

This updates the cookie header parser to handle zero or more spaces between semicolons, whereas the current code only handles a single space. For example, these are both currently invalid, but are considered valid with these changes:

Cookie: foo=bar;baz=quux
Cookie: foo=bar;  baz=quux

While this technically goes against the HTTP spec, I have seen it happen (and just had to fix a bug in production because of it 😅) and there seems to be precedent for going a little off spec, e.g. by handling trailing semicolons in request cookies and by handling zero or more spaces in Set-Cookie headers.

@mergify mergify bot added series/0.23 PRs targeting 0.23.x module:core labels Nov 6, 2023
@armanbilge
Copy link
Member

and there seems to be precedent for going a little off spec

Can we also find some precedent in any other HTTP implementations? e.g. Netty, Pekko, the JDK.

@mrdziuban
Copy link
Contributor Author

Can we also find some precedent in any other HTTP implementations? e.g. Netty, Pekko, the JDK.

Sure thing! I forked both pekko and netty and added tests. I found that both actually handle zero or more spaces after semicolons, do you think we should do the same here?

@armanbilge
Copy link
Member

I found that both actually handle zero or more spaces after semicolons, do you think we should do the same here?

Aha, thanks for checking that! Yes, while we're here I suppose we can handle that case too 🙃

Mandatory speech from Ross in #7104 (comment).

@mrdziuban mrdziuban changed the title Update request cookie parser to handle 1 or more spaces between semicolons Update request cookie parser to handle zero or more spaces between semicolons Nov 7, 2023
@mrdziuban
Copy link
Contributor Author

I suppose we can handle that case too

Done! Ross' comments definitely resonate, I would much prefer to fix whatever is going wrong on my user's end that results in multiple spaces, but my debugging so far leads me to believe it's an issue in a proprietary corporate firewall so my chances of that seem slim 😬

val cookieString = (RequestCookie.parser ~ (
(char(';') *> char(' ').rep0).soft *> RequestCookie.parser
).rep0).map { case (head, tail) =>
Cookie(NonEmptyList(head, tail))
}

// We also see trailing semi-colons in the wild, and grudgingly tolerate them here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a comment similar to this one esp. since the implementation no longer matches the comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 added a comment

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Hopefully someone else can sign-off on this too.

@armanbilge armanbilge merged commit d484623 into http4s:series/0.23 Nov 9, 2023
17 checks passed
@mrdziuban mrdziuban deleted the request-cookie-multi-space branch November 9, 2023 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:core series/0.23 PRs targeting 0.23.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants