You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[ISSUE]: Incorrect Content-Type Validation Logic in middleware.py #395
Description:
In safe_request_handler() decorator in backend/middleware.py, when require_json=True is set, it still incorrectly validates and allows application/x-www-form-urlencoded as valid content type:
# In safe_request_handler (lines 117-122):ifvalidate_content_typeandrequest.methodnotin ['GET', 'HEAD']:
ct=request.content_typeifnotctorct.split(';')[0].strip() notin ['application/json']:
logger.warning(f"Content-Type validation failed for {request.path}")
returninvalid_json_error("Invalid or missing Content-Type header")
The logic not in ['application/json'] is correct, but when require_json=True is passed explicitly, it should strictly validate JSON only, not the broader type list. However, there's also another part that incorrectly allows urlencoded even when JSON is required.
Steps to fix:
Open backend/middleware.py
Find the safe_request_handler() function
Modify the Content-Type validation to be more explicit when require_json=True:
ifvalidate_content_typeandrequest.methodnotin ['GET', 'HEAD']:
ct=request.content_typeallowed= ['application/json'] ifrequire_jsonelse ['application/json', 'application/x-www-form-urlencoded']
ifnotctorct.split(';')[0].strip() notinallowed:
logger.warning(f"Content-Type validation failed for {request.path}")
returninvalid_json_error("Invalid or missing Content-Type header")
Activity
Aditya8369 commentedon May 1, 2026
@devanshi14malhotra please assign me