-
Notifications
You must be signed in to change notification settings - Fork 184
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
Cookie overflow fix #150
Cookie overflow fix #150
Conversation
Tests appear to be more brittle than I'd have suspected. Might need to revisit the byte length prefix encoding design. |
Test failures were because the cookie max size shifted and test cases were expressed in terms of that constant. |
One option I'm considering is this:
I don't know if it's critical or not for anyone with an existing install to clear out existing cookies. The cookies would eventually expire anyway, so explicit clears may not be strictly necessary, but we did run into some issues in our testing w/ existing cookies, so I'm throwing it out there as an option. |
This should be ready to review. Let me know if you'd like me to clear the old cookies or not. |
One high level comment - I think I'd rather we separate out the overflow cookie store than change the behavior of the existing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above for requested changes!
I like the idea, it feels a bit cleaner in some respects, but I worry there are practical concerns. Were you thinking that we'd swap cookie store implementations depending on provider somehow? Setup code for cookie store is here:
Presumably The alternative solution of putting it in the hands of the person deploying SSO by making it a config switch increases documentation burden. It's already pretty rough to get a provider set up and working as intended, so I'm a little nervous about adding to the pile of things you need to consider when setting up. One possibility might be to make it a config switch but just have it be the default, so you only have a documentation burden if you need to turn it off for some reason? |
What provider specific information, other than the name of the provider do you think would be necessary? |
I suppose that's true. If it could be managed entirely by the provider switch ( |
Hi! Could we move forward with this ? It's blocking the Azure Ad implementation. Regards. |
While yes, it's blocking Azure AD, as I mentioned in that PR, I don't think cookie splitting in practice is great. Some part of that is simply that the failure scenario is pretty opaque to the user. Browsers just drop the cookie on the floor, which sends them into an authentication loop. Debugging can be a challenge too because, if you don't have checkboxes for preserving logs set, the error message telling you your cookie was too big only happens on a page behind a redirect, so you never see the error in the console unless you're actively looking specifically for it. Meanwhile browsers measure cookie limits in really surprising ways, and I've had to repeatedly reduce the max bytes-per-cookie limit for weird edge cases we keep hitting. It's super painful to deal with and I'd rather just use Redis for sessions. |
We've found that running with cookie splitting tends to result in a lot of tribal "knowledge" of "did you try clearing your cookies?" whenever someone reports something isn't working. I don't believe this is a good long term end state for things to land in. |
516715f
to
0f41c0f
Compare
@sporkmonger I totally agree but unfortunately, unless someone starts to implement #158, that's the only solution we currently have. |
We've been running this in production for some time and I think I can confidently say that this approach is a bad idea. I'm going to close this PR now that #158 is underway. |
Problem
Azure AD (#118) produces massive 3kb tokens. Storing them directly inside cookies produces around 5kb of cookie after compression (#95) and encryption. Browsers typically limit sites to only 4096 bytes (or in some cases, very slightly less) per cookie, with about 110 bytes or so being used up by the cookie name and various attributes. So in practice, you can only store about 3986ish bytes per cookie, which the Azure AD provider goes way past.
Solution
Since we don't want to maintain server-side state, I've implemented a cookie store that automatically spans the data being stored across multiple cookies when needed, using a byte length prefix in the first cookie. It uses
~
as the delimiter between the cookie length prefix and the spanned cookie value since it's not used by any base64 encoding and also not escaped in URLs, HTTP headers, or HTML forms. The prefix is simply a base64 encoded binary serialization of the integer byte length.Notes
The prefix length isn't signed or encrypted and could be altered by a malicious client, however altering it should't do anything beneficial. It should just result in an error (all error conditions covered in test cases).