File tree Expand file tree Collapse file tree 4 files changed +20
-3
lines changed
oauth2_provider/contrib/rest_framework Expand file tree Collapse file tree 4 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ Kristian Rune Larsen
8383Lazaros Toumanidis
8484Ludwig Hähne
8585Łukasz Skarżyński
86+ Madison Swain-Bowden
8687Marcus Sonestedt
8788Matias Seniquiel
8889Michael Howitz
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222* #1425 Remove deprecated ` RedirectURIValidator ` , ` WildcardSet ` per #1345 ; ` validate_logout_request ` per #1274
2323
2424### Fixed
25+ * #1443 Query strings with invalid hex values now raise a SuspiciousOperation exception (in DRF extension)
2526### Security
2627
2728## [ 2.4.0] - 2024-05-13
Original file line number Diff line number Diff line change 11from collections import OrderedDict
22
3+ from django .core .exceptions import SuspiciousOperation
34from rest_framework .authentication import BaseAuthentication
45
56from ...oauth2_backends import get_oauthlib_core
@@ -23,10 +24,18 @@ def authenticate(self, request):
2324 Returns two-tuple of (user, token) if authentication succeeds,
2425 or None otherwise.
2526 """
27+ if request is None :
28+ return None
2629oauthlib_core = get_oauthlib_core ()
27- valid , r = oauthlib_core .verify_request (request , scopes = [])
28- if valid :
29- return r .user , r .access_token
30+ try :
31+ valid , r = oauthlib_core .verify_request (request , scopes = [])
32+ except ValueError as error :
33+ if str (error ) == "Invalid hex encoding in query string." :
34+ raise SuspiciousOperation (error )
35+ raise
36+ else :
37+ if valid :
38+ return r .user , r .access_token
3039request .oauth2_error = getattr (r , "oauth2_error" ,{})
3140return None
3241
Original file line number Diff line number Diff line change @@ -415,3 +415,9 @@ def test_authentication_none(self):
415415auth = self ._create_authorization_header (self .access_token .token )
416416response = self .client .get ("/oauth2-authentication-none/" , HTTP_AUTHORIZATION = auth )
417417self .assertEqual (response .status_code , 401 )
418+
419+ def test_invalid_hex_string_in_query (self ):
420+ auth = self ._create_authorization_header (self .access_token .token )
421+ response = self .client .get ("/oauth2-test/?q=73%%20of%20Arkansans" , HTTP_AUTHORIZATION = auth )
422+ # Should respond with a 400 rather than raise a ValueError
423+ self .assertEqual (response .status_code , 400 )
You can’t perform that action at this time.
0 commit comments