Skip to content

Commit ff3386c

Browse files
authored
BB2-3484: Long term fix for scope creep (#1259)
* Long term fix for scope creep * Updated string check * Updated scope gate * Fix revoke and tests * Fix tests * Shuffle allow checks * status * error msg update * Error respoonse * Errors sorted * less redundant * examine scope erasure in postman * Revert short-term fix * Kill print * Tweaked error handling * Tweaked error handling * Cleanup
1 parent 101bffb commit ff3386c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

apps/dot_ext/views/authorization.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
IntrospectTokenView as DotIntrospectTokenView,
2121
)
2222
from oauth2_provider.models import get_application_model
23+
from oauthlib.oauth2 import AccessDeniedError
2324
from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError
2425
from urllib.parse import urlparse, parse_qs
2526
import html
@@ -179,13 +180,19 @@ def form_valid(self, form):
179180
refresh_token_delete_cnt = 0
180181

181182
try:
183+
if not scopes:
184+
# Since the create_authorization_response will re-inject scopes even when none are
185+
# valid, we want to pre-emptively treat this as an error case
186+
raise OAuthToolkitError(
187+
error=AccessDeniedError(state=credentials.get("state", None)), redirect_uri=credentials["redirect_uri"]
188+
)
182189
uri, headers, body, status = self.create_authorization_response(
183190
request=self.request, scopes=scopes, credentials=credentials, allow=allow
184191
)
185192
except OAuthToolkitError as error:
186193
response = self.error_response(error, application)
187194

188-
if allow is False:
195+
if allow is False or not scopes:
189196
(data_access_grant_delete_cnt,
190197
access_token_delete_cnt,
191198
refresh_token_delete_cnt) = remove_application_user_pair_tokens_data_access(application, self.request.user)

0 commit comments

Comments
 (0)