Skip to content

[ISSUE]: Inconsistent Content-Type validation between backend modules #523

Closed

Description

@Aditya8369

Description

There are multiple Content-Type validators (backend/security_parsers.py: validate_content_type / backend/middleware.py: validate_content_type_middleware / safe_request_handler inside same middleware). They don’t behave identically:
validate_content_type() checks request.content_type against allowed types and errors on missing header.
validate_content_type_middleware lowercases and strips parameters, but error message hardcodes “Expected: application/json”.
safe_request_handler builds a different allowed list depending on require_json.
This inconsistency can lead to endpoints behaving differently

Additional Context

Steps to reproduce:
Add/choose an endpoint that uses validate_content_type_middleware.
Send a request with header: Content-Type: application/x-www-form-urlencoded; charset=utf-8
Observe whether it is accepted/rejected.
Repeat against an endpoint using safe_request_handler(require_json=True) or different decorator ordering.
Compare responses—behavior will differ even though Content-Type is essentially “the same” header.

Activity

  1. Aditya8369 commented on May 15, 2026

    @Aditya8369
    ContributorAuthor

    @devanshi14malhotra please assign me under GSSoC

  2. added
    NSoC'26For issues and PRs which are a part of the Nexus Spring of Code open source event
    level:advancedGSSoC'26 advanced level PR/issue
    GSSoC'26For all issues/PRs related to GSSoC'2026 open source event
    on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GSSoC'26For all issues/PRs related to GSSoC'2026 open source eventNSoC'26For issues and PRs which are a part of the Nexus Spring of Code open source eventlevel310 pointslevel:advancedGSSoC'26 advanced level PR/issue

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions