You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JWT aud validation raises "Invalid audience" for audience=None #389
The issue demonstrates that calling _validate_aud with claims that include an aud string and with audience=None ends up raising JWTClaimsError with message "Invalid audience".
From the code path referenced, the likely root cause is the check if audience not in audience_claims: which assumes audience is comparable against audience_claims even when audience is None. If the function is intended to accept audience=None to mean “no audience check” or to behave differently, this check will incorrectly raise.
Proposed next steps / PR plan:
Confirm intended behaviour for audience=None in the project docs (should it mean “skip audience validation” or “require that the token has no audience”?). If the intended behaviour is “skip audience validation”, we should short-circuit early when audience is None.
Add a unit test reproducing the failure (claims with aud as str, audience=None should not raise if behaviour is to skip validation; or should raise a clearer error if None is invalid).
Implement a fix (example options):
If audience=None should skip validation:
Add at the top of _validate_aud: if audience is None: return (and document this).
If audience=None is invalid input:
Raise a more explicit TypeError/ValueError explaining audience must be str or sequence.
Run test suite and open a PR referencing this issue.
Before I open a PR: can you confirm the intended semantics of audience=None? If you prefer, I can open a draft PR that implements the “skip validation when audience is None” approach together with tests so maintainers can review.
Activity
Faitholo commentedon Nov 6, 2025
Hi,
I'll like to work on this issue.
The issue demonstrates that calling
_validate_audwith claims that include anaudstring and withaudience=Noneends up raising JWTClaimsError with message "Invalid audience".From the code path referenced, the likely root cause is the check
if audience not in audience_claims:which assumesaudienceis comparable againstaudience_claimseven whenaudienceisNone. If the function is intended to acceptaudience=Noneto mean “no audience check” or to behave differently, this check will incorrectly raise.Proposed next steps / PR plan:
Before I open a PR: can you confirm the intended semantics of audience=None? If you prefer, I can open a draft PR that implements the “skip validation when audience is None” approach together with tests so maintainers can review.