Skip to content

Commit 73e0cb5

Browse files
Ensure a 403 is actually returned not a 500 when debug is set to false
1 parent eb306ce commit 73e0cb5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

apps/dot_ext/views/authorization.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.conf import settings
88
from django.contrib.auth import get_user_model
99
from django.contrib.auth.views import redirect_to_login
10-
from django.http import JsonResponse
10+
from django.http import HttpResponseForbidden, JsonResponse
1111
from django.http.response import HttpResponse, HttpResponseBadRequest
1212
from django.template.response import TemplateResponse
1313
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
@@ -154,7 +154,11 @@ def dispatch(self, request, *args, **kwargs):
154154
version = get_api_version_number_from_url(path_info)
155155
# If it is not version 3, we don't need to check anything, just return
156156
if version == Versions.V3:
157-
self.validate_v3_authorization_request()
157+
try:
158+
self.validate_v3_authorization_request()
159+
except AccessDeniedTokenCustomError as e:
160+
return HttpResponseForbidden(e)
161+
158162
# TODO: Should the client_id match a valid application here before continuing, instead of after matching to FHIR_ID?
159163
if not kwargs.get('is_subclass_approvalview', False):
160164
# Create new authorization flow trace UUID in session and AuthFlowUuid instance, if subclass is not ApprovalView
@@ -258,7 +262,7 @@ def validate_v3_authorization_request(self):
258262
)
259263
except ObjectDoesNotExist:
260264
raise AccessDeniedTokenCustomError(
261-
description='You do not have permission to perform this action.'
265+
description='Unable to verify permission.'
262266
)
263267

264268
def form_valid(self, form):
@@ -466,7 +470,7 @@ def validate_v3_token_call(self, request) -> None:
466470
)
467471
except ObjectDoesNotExist:
468472
return JsonResponse(
469-
{'status_code': 403, 'message': 'You do not have permission to perform this action.'},
473+
{'status_code': 403, 'message': 'Unable to verify permission.'},
470474
status=403,
471475
)
472476

0 commit comments

Comments
 (0)