-
Notifications
You must be signed in to change notification settings - Fork 55
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
Race conditions at scale leading to security issues. #186
Comments
Hi @parikls, thank you so much for reporting this, I was foolishly convinced this was resolved by introducing the context manager (you should be using |
@tomasvotava the context manager won't help in this case unfortunately. Currently the workaround which works - is to create a new
Thanks in advance! P.S. I think I can confirm that the above approach solved the issue completely. At least we had the same amount of requests during the weekend, and 0 errors in a sentry. |
@tomasvotava UPD: faced the same issue yesterday even with the provider creation per request. Probably some more shared state exist somewhere? Maybe on a class level? I haven't yet investigated this deeply, but want to keep you updated |
@parikls thanks a lot for keeping me up to date, I am afraid I cannot post a fix without changing the behavior of how access_token is retrieved (it cannot be on the instance if the instance is to be reusable), and so I will have to make some changes. |
@tomasvotava my SSO provider has a
|
Ok, thanks for clarifying that, I was really hoping there was an error on your side, to be honest 😄 I know security isn't laughable thing, I assure you I take it seriously, I am just trying to gather as much intel as I can before moving on to solution, so that I can be sure that I actually resolve it properly this time. You are being very, very helpful, thanks! |
@tomasvotava np =)
And will post an update in a day or two |
@tomasvotava FYI after adding a lock - issue is fully resolved |
@parikls thanks for letting me know, my planned solution does basically the same, but it will require everyone to change from using |
hey @tomasvotava just wondering if there are plans to release #189 . From what I've seen last release was in may and last commit on master was merging #194. Worth a 1.6.0 for a new release? Happy to help |
Sometimes all I need is a kick in my butt, I'll do it tomorrow <3 thanks for providing the boot |
My use case:
Users are logging in via an SSO, and after that I'm using the access token of the logged-in user to obtain additional information from the provider.
In my view I'm getting the access token using the provider property, e.g.
provider.access_token
. But when I'm running the code on a big scale (we have hundreds of thousands users) - sometimes one user can obtain the access token of the other user, which leads to serious security issues. This happens rarely, and only if multiple users are logging-in at the same time (microseconds differences).After investigating the source codes of the fastapi-sso, I've figured out that the problem is actually with the provider implementation.
SSOBase
class is stateful and aprocess_login
coro has multiple awaits after fetching the token, so when there are multiple simultaneous users are logging in via the sso - this leads to a race condition, and the first user will obtain the token of the last user.My code which I'm currently using.
lifespan.py
api.py
I've wrote a very quick and dirty test case for the fastapi-sso to prove that this is actually an issue:
The text was updated successfully, but these errors were encountered: