Missing Content-Type Validation
Overview
APIs that accept requests without validating Content-Type are vulnerable to:
- CSRF: Browser forms submit as
application/x-www-form-urlencodedwhich HTML forms can send cross-origin - Content confusion: Unexpected parsing if body is mismatched with Content-Type
- Polyglot attacks: Content that is valid as multiple types
Modern CSRF protection relies on the browser's cross-origin restriction on JSON Content-Type.
Remediation
- Validate Content-Type for all POST/PUT/PATCH endpoints
- Reject requests with unexpected Content-Type
- Use CSRF tokens even for JSON APIs as defense-in-depth