-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(socialaccount): JWT: Prevent replay using JTI
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
|
||
from allauth.socialaccount.internal.jwtkit import verify_and_decode | ||
from allauth.socialaccount.providers.apple.client import jwt_encode | ||
from allauth.socialaccount.providers.oauth2.client import OAuth2Error | ||
|
||
|
||
def test_verify_and_decode(enable_cache): | ||
now = timezone.now() | ||
payload = { | ||
"iss": "https://accounts.google.com", | ||
"azp": "client_id", | ||
"aud": "client_id", | ||
"sub": "108204268033311374519", | ||
"hd": "example.com", | ||
"locale": "en", | ||
"iat": now, | ||
"jti": "a4e9b64d5e31da48a2037216e4ba9a5f5f4f50a0", | ||
"exp": now + timedelta(hours=1), | ||
} | ||
id_token = jwt_encode(payload, "secret") | ||
for attempt in range(2): | ||
try: | ||
verify_and_decode( | ||
credential=id_token, | ||
keys_url="/", | ||
issuer=payload["iss"], | ||
audience=payload["aud"], | ||
lookup_kid=False, | ||
verify_signature=False, | ||
) | ||
assert attempt == 0 | ||
except OAuth2Error: | ||
assert attempt == 1 |