Content-Type and Accept Header Exploits
What you'll learn: How attackers manipulate Content-Type and Accept headers to trick APIs into processing data in dangerous ways or bypassing security checks.
What Are These Headers?
The Content-Type header tells the server what format the request body is in (like application/json or application/xml). The Accept header tells the server what format the client wants in the response. APIs use these to decide which parser to invoke—and that's where vulnerabilities arise.
How the Attack Works
Imagine a restaurant kitchen that changes cooking methods based on labels on food containers. If you mislabel raw chicken as "salad," it might skip proper cooking and cause problems.
Similarly, attackers can:
- Claim JSON but send XML – Set
Content-Type: application/jsonwhile actually sending XML containing XXE payloads, hoping the server's XML parser runs without proper validation - Force alternate parsers – Request
Accept: application/xmlwhen the API only validates JSON responses, potentially exposing sensitive data the XML serializer includes - Trigger parsing errors – Send malformed content with mismatched Content-Type to cause crashes or bypass input validation entirely
- Bypass validation – If validation logic only checks JSON but the server also accepts XML, send the attack payload as XML to evade detection
Real-World Example
An API validates that JSON input has no admin privileges set. An attacker sends:
Content-Type: application/xml
But the validation layer only runs on JSON. The backend accepts XML too—validation bypassed, unauthorized privilege escalation achieved.
Why This Matters
These headers control which code path executes. Different parsers have different vulnerabilities, validation levels, and behaviors. Mismatched expectations create security gaps.
Key Takeaway: Always validate that Content-Type matches actual content, enforce strict parser selection, and apply validation consistently across all supported formats—never trust client-declared headers to determine security controls.