mh0m@research:~$

Cross-tenant access tokens in authlib's ID-JAG grant

3 min read

I recently reported a security advisory in authlib, the Python library many Flask, Django and FastAPI apps use to build OAuth 2.0 and OpenID Connect servers and clients. It affects 1.9.0 to 1.9.3 and is fixed in 1.9.4, advisory GHSA-9qr6-8289-9j56. The advisory rates it Medium, since the attacker has to be a tenant whose IdP the server already trusts.

ID-JAG and multiple IdPs

ID-JAG, the Identity Assertion JWT Authorization Grant, is the IETF draft behind Cross-App Access. An app gets an access token for another app's API through an identity provider that the API's authorization server already trusts for single sign-on. The IdP signs a short-lived JWT naming the user, the client and the audience, and the client exchanges it for an access token. authlib added the grant in 1.9.0 as IDJAGGrant.

A SaaS authorization server usually trusts one IdP per customer, so it trusts several at once. That is the setup this issue needs.

The bug

The grant checks the signature with the key of the issuer named in iss, and checks the audience, the expiry, replay through jti, and that client_id matches the authenticated client. It then looks the user up from sub. Neither authenticate_user nor check_id_jag_permission receives the issuer, and the documented example resolves the user by sub alone:

# authlib/oauth2/drafts/id_jag.py, v1.9.3

# line 231: iss only picks the verification key
key = import_any_key(self.resolve_issuer_key(issuer, headers))
...
# line 189: sub alone picks the user
user = self.authenticate_user(claims["sub"])

# docs/oauth2/specs/id-jag.rst, v1.9.3
def authenticate_user(self, subject):
    return User.query.filter_by(sub=subject).first()

The draft says a sub is only unique within its issuer, in section 3.1, and requires a server that trusts several IdPs to resolve each issuer's identities to the right local account, in section 4.1. A server built from the example does not, so any trusted IdP can name a user of another tenant.

The lab

The PoC builds a server from the documented hooks, with two tenants, acme and evilcorp, and runs on 127.0.0.1. Evilcorp's administrator controls evilcorp's IdP signing key, as a tenant administrator does in a bring your own IdP setup, and signs this assertion:

{
  "iss": "https://idp.evilcorp.example",
  "sub": "00uACMEvictim42",
  "aud": "https://rs-as.lab.example",
  "client_id": "evil-app",
  "scope": "files:read"
}

The server issues an access token for 00uACMEvictim42, a user of acme, and the token reads acme's data. With a stricter policy, where each organization approves the clients that may act for its users, the attack needs a client that acme approved. It still works through such a client, for reads and for writes.

Lab run: authlib 1.9.3, and 1.9.4 with the old hook, issue tokens for the acme user. The 1.9.4 hook rejects them.

Fix

authlib 1.9.4 was released less than four hours after the report. It puts the verified claims in request.id_jag_claims and changes the documented example to look the user up by issuer and subject:

def authenticate_user(self, subject):
    issuer = self.request.id_jag_claims["iss"]
    return User.query.filter_by(issuer=issuer, sub=subject).first()

Upgrading alone does not change a hook you already wrote. The lab shows 1.9.4 with the old hook still issuing the token, while version scanners will report 1.9.4 as fixed. If your server copied the old example and trusts more than one IdP, update authenticate_user as well. A resolve_user(claims) hook that receives the claims directly is on main, not yet released.

Sources: PoC, lab and transcripts on GitHub · advisory GHSA-9qr6-8289-9j56.

Takeaway

When a server trusts several identity providers, a valid signature shows which provider vouched for the user, not that the user belongs to that provider. The lookup has to use the issuer together with the subject. Documentation examples are worth reviewing with the same care as the library code, since many servers copy them as written.

Coordinated disclosure. Reported privately on 2026-11-04 at 05:19 UTC. authlib 1.9.4 and the advisory followed at 09:04 UTC the same day. Thanks to the maintainer for the quick fix. The lab only runs on 127.0.0.1.

← back to posts