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

Only check Cookie paths when sending requests #322

Merged
merged 2 commits into from
Sep 12, 2022

Conversation

christhesoul
Copy link
Contributor

@christhesoul christhesoul commented Sep 6, 2022

Hey wonderful Rack::Test folks 👋

I come with little open source contribution experience, but plenty of gratitude for the folks that do and positive intent.

This PR aims to resolve a cookie issue where I believe the Rack::Test implementation differs from the cookie specification.

I've done some testing and checked the spec, in these cases it's possible to set a cookie with a path parameter different to the current path of the browser. The cookie will only be sent to the server when the browser makes a request to that path.

Even though the Set-Cookie header supports the Path attribute, the Path attribute does not provide any integrity protection because the user agent will accept an arbitrary Path attribute in a Set-Cookie header. For example, an HTTP response to a request for http://example.com/foo/bar can set a cookie with a Path attribute of "/qux".

The above is taken from https://httpwg.org/specs/rfc6265.html#rfc.section.8.6

In the current implementation of Rack::Test the same valid? method is performed when setting and sending cookies. The validity rules should differ; the path validity can be ignored when setting cookies.

This PR is an attempt to demonstrate the problem, double check on my interpretation of the spec, and propose a solution.

Thanks in advance for your time.

Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! I agree with the principle of only checking paths when sending and not when receiving. Please see inline comment for a possible change to the implementation.

I'm currently traveling to RubyKaigi, but I should be able to merge and test this next week.

@christhesoul
Copy link
Contributor Author

Hey @jeremyevans – thank you for taking a look ... but I can't see the suggested change anywhere. 🤔

I know Github has been hiccuping a bit today, so maybe it just got lost?! Happy to make some changes – I just don't know what they are!

Safe travels.

@jeremyevans
Copy link
Contributor

@christhesoul Sorry about that, not sure why the inline comment didn't get submitted. I think it is best to not introduce new methods for this, and just move the path check from valid? to matches?. What are your thoughts on that? In any case, we cannot move valid? from public to private visibility, as that breaks the public API.

@christhesoul
Copy link
Contributor Author

@jeremyevans Good idea! And the change seems much simpler as a result. I like it. Let me know what you think.

Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@jeremyevans jeremyevans merged commit 48ca371 into rack:main Sep 12, 2022
@christhesoul
Copy link
Contributor Author

My pleasure!

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

Successfully merging this pull request may close these issues.

None yet

2 participants