CVE-2025-68158: Authlib: 1-click Account Takeover
Authlib is a Python library which builds OAuth and OpenID Connect servers. In version 1.6.5 and prior, cache-backed state/request-token storage is not tied to the initiating user session, so CSRF is possible for any attacker that has a valid state (easily obtainable via an attacker-initiated authentication flow). When a cache is supplied to the OAuth client registry, FrameworkIntegration.setstatedata writes the entire state blob under state{app}{state}, and getstatedata ignores the caller’s session altogether. This issue has been patched in version 1.6.6.
Other sources
Authlib is a Python library which builds OAuth and OpenID Connect servers. In versions 1.0.0 through 1.6.5, cache-backed state/request-token storage is not tied to the initiating user session, so CSRF is possible for any attacker that has a valid state (easily obtainable via an attacker-initiated authentication flow). When a cache is supplied to the OAuth client registry, FrameworkIntegration.setstatedata writes the entire state blob under state{app}{state}, and getstatedata ignores the caller’s session altogether. This issue has been patched in version 1.6.6.
— MITRE
I am writing to you from the Security Labs team at Snyk to report a security issue affecting Authlib, which we identified during a recent research project.
We have identified a vulnerability that can result in a 1-click Account Takeover in applications that use the Authlib library. (5.7 CVSS v3: AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:N/A:N)
Description
Cache-backed state/request-token storage is not tied to the initiating user session, so CSRF is possible for any attacker that has a valid state (easily obtainable via an attacker-initiated authentication flow). When a cache is supplied to the OAuth client registry, FrameworkIntegration.setstatedata writes the entire state blob under state{app}{state}, and getstatedata ignores the caller’s session altogether. \[1\]\[2\]
py def getcachedata(self, key): value = self.cache.get(key) if not value: return None try: return json.loads(value) except (TypeError, ValueError): return None [snip] def getstatedata(self, session, state): key = f"state{self.name}{state}" if self.cache: value = self.getcachedata(key) else: value = session.get(key) if value: return value.get("data") return None
authlib/integrations/base\client/framework\integration.py:12-41
Retrieval in authorize\access\token therefore succeeds for whichever browser presents that opaque value, and the token exchange proceeds with the attacker’s authorization code. \[3\]
py def authorizeaccesstoken(self, kwargs): """Fetch access token in one step.
:return: A token dict. """ params = request.args.todict(flat=True) state = params.get("oauthtoken") if not state: raise OAuthError(description='Missing "oauthtoken" parameter')
data = self.framework.getstatedata(session, state) if not data: raise OAuthError(description='Missing "requesttoken" in temporary data')
params["requesttoken"] = data["requesttoken"] params.update(kwargs) self.framework.clearstatedata(session, state) token = self.fetchaccesstoken(params) self.token = token return token
authlib/integrations/flask\client/apps.py:57-76
This opens up the avenue for Login CSRF for apps that use the cache-backed storage. Depending on the dependent app’s implementation (whether it somehow links accounts in the case of a login CSRF), this could lead to account takeover.
\[1\] https://github.com/authlib/authlib/blob/260d04edee23d8470057ea659c16fb8a2c7b0dc2/authlib/integrations/flask\client/apps.py\#L35
\[2\] https://github.com/authlib/authlib/blob/260d04edee23d8470057ea659c16fb8a2c7b0dc2/authlib/integrations/base\client/framework\integration.py\#L33
\[3\] https://github.com/authlib/authlib/blob/260d04edee23d8470057ea659c16fb8a2c7b0dc2/authlib/integrations/flask\client/apps.py\#L57
Proof of Concept
Let’s think of an app \- AwesomeAuthlibApp. Let’s assume that the AwesomeAuthlibApp has internal logic that, when an already logged-in user performs a callback request, links the newly provided SSO identity to the already existing user that made the request.
Then, an attacker can get account takeover inside the app by performing the following actions:
1\. They start an SSO OAuth flow, but stop it right before making the callback call to AwesomeAuthlibApp; 2\. The attacker tricks a logged-in user (via phishing, a drive-by attack, etc.) to perform a GET request with the attacker's state value and grant code to the AwesomeAuthlibApp callback. Because Authlib doesn’t check whether the state token is linked to the session performing the callback, the callback is processed, the grant code is sent to the provider, and the account linking takes place.
After the GET request is performed, the attacker's SSO account is linked with the victim's AwesomeAuthlibApp account permanently.
Suggested Fix
Per the OAuth RFC \[4\], the state should be tied to the user’s session to stop exactly such scenarios. One straightforward method of mitigating this issue is to keep storing the state in the session even when caching.
Another method would be to hash the session ID (or another per-user secret from the session) into the cache key. This way, the state will be stored inside the cache, but it is still linked to the session of the user that initiated the OAuth flow.
[4] https://www.rfc-editor.org/rfc/rfc6749#section-10.12
— GitHub
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2025-68158?
CVE-2025-68158 has a high severity due to the potential for Cross-Site Request Forgery (CSRF) attacks.
How do I fix CVE-2025-68158?
To fix CVE-2025-68158, upgrade Authlib to version 1.6.6 or later, which addresses the CSRF vulnerability.
What is the impact of CVE-2025-68158 on my application?
The impact of CVE-2025-68158 includes the risk of unauthorized actions being performed on behalf of users due to CSRF vulnerabilities.
Which versions of Authlib are affected by CVE-2025-68158?
Versions of Authlib up to and including 1.6.5 are affected by CVE-2025-68158.
Can CVE-2025-68158 be exploited without user interaction?
Yes, CVE-2025-68158 can be exploited by an attacker without user interaction, given that the attacker can obtain a valid state.