Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

= http: introduce parsing rules for invalid cookies #925

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ajknoll
Copy link

@ajknoll ajknoll commented Aug 25, 2014

resolves #737

This fix introduces the ability to parse cookies headers with some valid and some invalid cookie pairs. This will allow Spray to gracefully handle (by discarding) cookies hanging around from the old Netscape style (see http://curl.haxx.se/rfc/cookie_spec.html), while still only constructing HttpCookies from RFC-valid cookies.

I've made this fix using the testing style found in the existing HttpHeaderSpec. However, I believe more comprehensive test coverage can be accomplished, and I've put together an example in atlassian@4a376f4 ; if that looks acceptable, please let me know and I'll open a PR from the branch with those tests instead :)

Avi Knoll added 2 commits August 20, 2014 15:42
 spray#737

This approach will skip invalid cookies, but does not change the API
surface. In particular, there is no RawHeader for the invalid cookies.
 spray#737

The parsing is expected to throw out cookie pairs that pass the
permissive syntax but not the strict syntax. Any cookies that pass the
strict syntax should be returned.
@ajknoll ajknoll changed the title = http: introduce parsing rules for invalid cookies #737 = http: introduce parsing rules for invalid cookies Aug 25, 2014
@sirthias
Copy link
Member

sirthias commented Sep 1, 2014

Thanks for this PR!
We'll take a look at it during our current migration work from spray to akka-http.

Caspar Krieger added 2 commits December 30, 2014 17:35
…ookies

Conflicts:
	spray-http/src/main/scala/spray/http/parser/CookieHeaders.scala
Due to spray#869, a comma is a valid separator, and so everything after the
first comma in a cookie's value (there shouldn't be commas in the cookie
value, but a user agent is required to be tolerant of them according to
RFC6265) is silently discarded.

This isn't a breaking change because without this fix, any cookie
containing a comma in the value would result in *all* the cookies being
discarded (albeit with a log message, which now will not appear).

Correct behaviour would require not allowing commas as a separator.
@caspark
Copy link

caspark commented Dec 30, 2014

PR updated to fix merge conflict from #869. Note the behaviour (documented in commit notes and as a test) resulting from having commas in cookie values.

Commas in cookie values are technically illegal according to the grammar, yet RFC6265 requires user agents to handle them and send them back as is (more notes on comma handling in cookies).

As mentioned in the commit notes, Spray currently handles a bad cookie of the form a=1,2 by throwing away all cookies; this PR will ensure all other cookies are parsed and the bad cookie is parsed as a=1. (I also have a preferred alternative which throws away the whole bad cookie - which is incompatible with treating commas as a cookie separator, as per #869 - so let me know if you'd prefer that instead.)

Anyway, this is ready to be merged; it's still a big improvement over the current state of "bad cookie" handling.

@sirthias
Copy link
Member

Thanks again for this PR, @ajknoll and @caspark!
(And sorry for taking so long to get back to it!)

I think this is a nice fix, which we'll definitely want to merge and port to Akka HTTP.
However, we'd need you, @ajknoll, to first accept the Typesafe CLA. This shouldn't take longer than 30 seconds.
Thanks again!

@jrudolph
Copy link
Member

I'd like to know if the concern I voiced in #737 about

being lenient may lead to ambiguities like in #702 where we need to employ a non-standard reading of backquoted doublequotes to be able to finish parsing

is tested and addressed in this PR.

I think we also need more test coverage, discussion, and documentation what exactly to expect in the erroneous or ambiguous cases like the one reported in #869 and #702.

@caspark
Copy link

caspark commented Feb 11, 2015

@jrudolph re your voiced concern, I don't think this introduces any further ambiguity.

There are tests added by this PR which demonstrate what happens when:

  1. A cookie has an invalid name: the cookie with invalid name is completely discarded and other cookies are parsed properly.
  2. A cookie has an invalid value (specifically, a comma in the value): everything after the comma is discarded for that cookie and other cookies are parsed properly.

We're happy to add any extra tests you'd like to see (@ajknoll has already offered extra property-based tests in his initial comment), discuss with other people (if you tell us who you want this discussed with), and/or update documentation (if you give us a pointer to the file(s) to update).

@jrudolph
Copy link
Member

@caspark thanks for giving your opinions and your contribution. Adding no further ambiguity is certainly good. :)

I agree that we need to make a decision about how to proceed. I think we need to collect all cases that we have seen up to now and need to make sure we find a solution we can keep and improve on for a while.

@ajknoll
Copy link
Author

ajknoll commented Feb 23, 2015

@sirthias I've accepted the CLA. Glad to hear this is going ahead :) Please feel free to use the ScalaCheck tests as well if additional verification is needed, as suggested by @caspark.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http: support partial parsing of cookie header
4 participants