-
Notifications
You must be signed in to change notification settings - Fork 364
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 Pollution #217
Comments
I have the same issue. |
Also an issue. Followed sample to the letter and getting the same errors as the people who have reported above. Will this issue even get acknowledged? |
Hi there! Sorry it took us so long to address this. I want to start by apologizing to all of you for all the wait. I understand this is a serious issue and want to shed some light on why we built it like this and ask for feedback on some solutions we're thinking for the future. Why are we using cookie in the first place?For the past few years, Auth0.js had a few issues (#990, #897, #820, #816 and more) when dealing with local storage. With that being said, the experience you shared in this issue is not the experience we want you to have and we'd like to better understand in what scenarios are you seeing this happen in production. I'm specifically asking about the production environment because that's where this issue is less likely to appear, considering how the sdk behaves regarding cookies. Taking a step back, this is how the cookie is handled in the SDK:
What that means is that the only two ways of getting all those cookies created without them being cleaned up are:
Of course, neither of those situations are perfect, but the tradeoff we decided to do is: we provided a solution that is super reliable in production (no There's no 100% perfect solution for this. I had an idea to limit the amount of transactions to 15. So, every new transaction after the 14th, will clear the oldest transaction etc. But then, what about folks that use a large Now, what I want to hear from you to help move this forward is:
|
We haven't even made it to production because of this issue. It occurs randomly when the user has auth'd in before, or after logging out. The only "solution" is to manually delete the cookies, close the browser tab, and then try to log back in. I use quotes because it doesn't even work all of the time. We tried to manually delete every cookie when the user logs out and that also seems to limit the 400 occurrence but its not foolproof. I'm fine for limiting the transactions if it will solve this issue as it basically makes our application unusable for end users. |
For me we were experiencing what @mannikf was but it was because we were using a |
Thank you so much for your patience and following up with this issue. @mannikf Can you share a step-by-step guide on how to reproduce this in your case? As stated before, the only time we add a new cookie is when @paulfalgout I don't fully understand what happened in your scenario. After the migration guide, did something started to fail and that's why you saw a large amount of cookie entries? |
Yep so in implicit flow you don't need to set the web origin as it won't be used. In this lib if you setup a wildcard in your web origin, then loginWithRedirect will succeed but getTokenSilently will fail. We don't currently use a landing page or the universal login. We either prompt=none or if that fails we prompt=login and set the connection |
@paulfalgout Ah, perfect. But once you get redirected back to your application, you still call As part of this specific feedback, I'll talk with the dashboard team to see if we can improve the user experience when adding a Thank you so much for the feedback! |
yep we would call that.. FWIW the initial login worked fine, it was always something with That said, the migration change is publicly available RoundingWell/care-ops-frontend@d0e6117 but the process of migration was squashed into the end results commit, so probably not that illuminating. |
one additional complication to throw into the mix.. during development we were often already logged in through the implicit grant code, then we'd update the test environment to the migration, which wasn't necessarily as clean as if we had logged out prior to the code update... so I don't know how that may have added to the issue. |
@paulfalgout maybe that was the case then.. Auth0.js uses cookies even for silent authentication or popup authentication so the pollution would be bigger. spa-js only add cookies for |
I followed the tutorial basically to the letter. We have noticed this happening different ways. One user reported it after logging in, using it for awhile, then not using it till the next day and the cookies were all filled up. |
@kevinfmanning did you reproduce this by yourself? Do you use |
per the example loginWithRedirect is called once in the PrivateRoute.js We do have multiple routes that all need secured in our App.js and in the example it only has one PrivateRoute. How do you propose having many routes all be secured and only have loginWithRedirect being called once? |
I started using the SDK today, and quickly came across HTTP 400 errors with webpack-dev-server due to this cookie proliferation. With my project, the cookies were not getting removed on logout or when redirecting back. I looked at the code for logout, and the only cookie it removes is the So I installed es-cookie, and just added this before every call to logout or loginWithRedirect: //Since I'm not using cookies for anything else.
for (const key of Object.keys(Cookies.getAll())) {
Cookies.remove(key);
} Just curious, is there any reason why the solution to this issue couldn't be just looking at the cookie keys and removing the auth0 ones before logging out or executing the actual redirect when logging in? Edit: Realized I wasn't using Looking in the code in 1.3.1 for 💭 I had previously added some code to remove the redirect querystring parameters from my URL using |
@krisdages Could you tell us a bit more about how you're using the library? I'm interested in things like the workflow, which methods you're calling and at what points. A timeline, if you will. For everyone else, could you all make sure that you're calling If you are calling this method at the right time and getting this cookie pollution issue, please let us know. |
It appears that handleRedirectCallback was throwing an "Invalid state" error. Because I am using hash-based routing, the callback is the root of my app, and the route is being added as a hash.
When parsing the state off the querystring, the value of state is showing up as
Looks like it's looking for the querystring in As a workaround for now, I am adding an extra parameter to the querystring after state but before the hash, and it seems to be working. |
@krisdages Can I ask which version of If you're not using the latest version, could you try that and let us know how you get on? |
Is there any example with this on multiple private routes? The one given includes just one PrivateRoute and we want to have more. I think the loginWithRedirect is getting called for everyone that we have listed in our app. |
@stevehobbsdev Will do. I was on 1.3.1 Update - 1.3.2 did fix my issue with state + hash. |
Found another situation that could cause the cookie fillup. If there is an error status in the redirect querystring, handling the callback throws an Error, which is good :) When the error was persistent (e.g. due to a bad rule), this caused a redirect loop that after about 10-11 rapid cycles resulted in an oversized cookie and a 400 error returned from the dev server. |
@krisdages you're absolutely right! we're not cleaning the state when there's an error: https://github.com/auth0/auth0-spa-js/blob/master/src/Auth0Client.ts#L248 We'll get this fixed ASAP! Thanks for reporting. |
Ah this error issue matches what we were seeing as well. We'd get an error because of the domain origin and immediately try again. |
👋 We released 1.4.0 to try and alleviate this issue. If anyone who was afflicted by this has any feedback that it has now solved their issue or not, that would be very much appreciated! |
I have tried to manually remove the cookies with name 'a0.spajs.xxx' before calling the method contains
|
Thanks @NevenLiang . The feeling at the moment is that we're going to build this into the SDK for you behind an option that you can turn on. I can assume the code snippet you supplied worked for you? |
@stevehobbsdev Yes, it works. I have sawn the source code. IMO, |
I appreciate the simpler API compared to the older Auth0.js, but the cookie pollution in spa-js is extreme. If you're proxying frontend requests (to avoid CORS issues), you're sending the
auth0.txn
andauth0.is.authenticated
cookies to your webserver. To make matters worse, because of #26, you'll add anotherauth0.txn
cookie for every single login flow within a 24 hour window. Here's a quick screenshot that shows the absurdity.Even without the login testing, the user is going to always send at least two auth0 cookies to the server on every request.
Is there any reason we're using cookies over session/localStorage? Seems like it'd be trivial to rewrite
storage.ts
and just clean up expired keys onsave()
.The text was updated successfully, but these errors were encountered: