Data sent with the Content-Type: application/json header in JSON format is usually expected by modern web APIs. Some applications, on the other hand, are loosely configured and support Content-Type: application/xml for endpoints that are intended to consume JSON.
Accepting unexpected or inconsistent content types may appear innocuous at first, but it can pose security risks, particularly if the backend tries to parse or interpret XML input in an unexpected way.
Attackers may take advantage of client-side or server-side XML parsing vulnerabilities (such as XXE (XML External Entity injection), XEE (XML Entity Expansion), or data tampering) if an endpoint intended for JSON accepts and parses XML.
An attacker can more easily get around content inspection filters, carry out format confusion attacks, or misuse parsing logic to obtain private information.
Allowing incorrect or unexpected content types can lead to:
To strengthen endpoint security and enforce predictable API behavior, the following best practices should be implemented: