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
83
83
Lazaros Toumanidis
84
84
Ludwig Hähne
85
85
Łukasz Skarżyński
86
+ Madison Swain-Bowden
86
87
Marcus Sonestedt
87
88
Matias Seniquiel
88
89
Michael 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
22
22
* #1425 Remove deprecated ` RedirectURIValidator ` , ` WildcardSet ` per #1345 ; ` validate_logout_request ` per #1274
23
23
24
24
### Fixed
25
+ * #1443 Query strings with invalid hex values now raise a SuspiciousOperation exception (in DRF extension)
25
26
### Security
26
27
27
28
## [ 2.4.0] - 2024-05-13
Original file line number Diff line number Diff line change 1
1
from collections import OrderedDict
2
2
3
+ from django .core .exceptions import SuspiciousOperation
3
4
from rest_framework .authentication import BaseAuthentication
4
5
5
6
from ...oauth2_backends import get_oauthlib_core
@@ -23,10 +24,18 @@ def authenticate(self, request):
23
24
Returns two-tuple of (user, token) if authentication succeeds,
24
25
or None otherwise.
25
26
"""
27
+ if request is None :
28
+ return None
26
29
oauthlib_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
30
39
request .oauth2_error = getattr (r , "oauth2_error" , {})
31
40
return None
32
41
Original file line number Diff line number Diff line change @@ -415,3 +415,9 @@ def test_authentication_none(self):
415
415
auth = self ._create_authorization_header (self .access_token .token )
416
416
response = self .client .get ("/oauth2-authentication-none/" , HTTP_AUTHORIZATION = auth )
417
417
self .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