Skip to content

Commit dc20015

Browse files
committed
Fix response_api_error() silently forcing 400 on every error
response_api_error() ignored its second positional status_code argument and always returned HTTP 400, so callers passing 401/403 were lying to clients about the actual error. Add a proper status_code keyword param and update call sites to use it.
1 parent fc9ce02 commit dc20015

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

source/app/blueprints/rest/api_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def wrapper(*args, **kwargs):
7272
user = _jwt_user()
7373

7474
if user == "invalid":
75-
return response_api_error("Invalid token", 401)
75+
return response_api_error("Invalid token", status_code=401)
7676

7777
if user is None:
7878
user = _legacy_token_user()
@@ -81,14 +81,14 @@ def wrapper(*args, **kwargs):
8181
user = _session_user()
8282

8383
if user is None:
84-
return response_api_error("Unauthorized", 401)
84+
return response_api_error("Unauthorized", status_code=401)
8585

8686
if (
8787
require_mfa
8888
and app.config.get("MFA_ENABLED")
8989
and not user.mfa_setup_complete
9090
):
91-
return response_api_error("MFA required", 403)
91+
return response_api_error("MFA required", status_code=403)
9292

9393
g.api_user = user
9494
return fn(*args, **kwargs)

source/app/blueprints/rest/endpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ def response_api_created(data):
6767
return response(201, data=data)
6868

6969

70-
def response_api_error(message, data=None):
70+
def response_api_error(message, data=None, status_code=400):
7171
content = {
7272
'message': message
7373
}
7474
if data:
7575
content['data'] = data
76-
return response(400, data=content)
76+
return response(status_code, data=content)
7777

7878

7979
def response_api_not_found():

source/app/blueprints/rest/v2/auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,21 @@ def oidc_exchange():
181181
session-based OIDC login has today.
182182
"""
183183
if not is_authentication_oidc():
184-
return response_api_error('OIDC authentication is not enabled', 400)
184+
return response_api_error('OIDC authentication is not enabled', status_code=400)
185185

186186
if not iris_current_user.is_authenticated:
187-
return response_api_error('Unauthorized', 401)
187+
return response_api_error('Unauthorized', status_code=401)
188188

189189
if not session.pop('oidc_authenticated', False):
190190
# The user has a valid session but it wasn't created via the OIDC
191191
# callback (or the marker has already been consumed by a prior
192192
# exchange). Do NOT mint tokens.
193-
return response_api_error('No pending OIDC exchange for this session', 403)
193+
return response_api_error('No pending OIDC exchange for this session', status_code=403)
194194

195195
user = users_get_active(iris_current_user.id)
196196
if user is None:
197197
session.clear()
198-
return response_api_error('User not active', 403)
198+
return response_api_error('User not active', status_code=403)
199199

200200
user_data = UserSchema(
201201
exclude=['user_password', 'mfa_secrets', 'webauthn_credentials']

0 commit comments

Comments
 (0)