API security

API request schema and content type validation

Input to execution: document, filter, code arranged to illustrate api request schema and content type validation.

Schema validation establishes which data structures and content types an endpoint is willing to process. Understanding API request schema and content type validation helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Input validation defines the structures, sizes and meanings an application expects to receive. It must happen before information influences a sensitive operation. Validation does not replace safe interpreter APIs, output encoding or permission checks, because those controls address different boundaries.

Effective input validation controls enforce business or functional expectations around the type of data the application expects to receive. This ensures good data quality and reduces the attack surface. However, it does not remove or replace the need to use correct encoding, parameterization, or sanitization when using the data in another component or for presenting it for output.

In this context, "input" could come from a wide variety of sources, including HTML form fields, REST requests, URL parameters, HTTP header fields, cookies, files on disk, databases, and external APIs.

Why it matters

Consider a realistic failure: a loosely typed field accepts nested input that changes query behaviour.

Untrusted input can change application behaviour, consume excessive resources or reach data and execution paths outside the intended feature. The practical result depends on where the value is used and which privileges are available there.

An API review follows the server-side behaviour behind the interface. Direct requests, alternate methods and background operations can reveal boundaries that the normal frontend journey does not exercise.

How penetration testers check for it

Exercise required fields, types, lengths, formats and unsupported content types.

  • Confirm that every HTTP response with a message body contains a Content-Type header field that matches the actual content of the response, including the charset parameter to specify safe character encoding according to IANA Media Types, such as "text/", "/+xml" and "/xml".
  • Confirm that only user-facing endpoints (intended for manual web-browser access) automatically redirect from HTTP to HTTPS, while other services or endpoints do not implement transparent redirects. This is to avoid a situation where a client is erroneously sending unencrypted HTTP requests, but since the requests are being automatically redirected to HTTPS, the leakage of sensitive data goes undiscovered.
  • Confirm that any HTTP header field used by the application and set by an intermediary layer, such as a load balancer, a web proxy, or a backend-for-frontend service, cannot be overridden by the end-user. Example headers might include X-Real-IP, X-Forwarded-*, or X-User-ID.
  • Confirm that only HTTP methods that are explicitly supported by the application or its API (including OPTIONS during preflight requests) can be used and that unused methods are blocked.
  • Confirm that per-message digital signatures are used to provide additional assurance on top of transport protections for requests or transactions which are highly sensitive or which traverse a number of systems.
  • Confirm that input is validated to enforce business or functional expectations for that input. This should either use positive validation against an allow list of values, patterns, and ranges, or be based on comparing the input to an expected structure and logical limits according to predefined rules. For L1, this can focus on input which is used to make specific business or security decisions. For L2 and up, this should apply to all input.
  • Confirm that the application is designed to enforce input validation at a trusted service layer. While client-side validation improves usability and should be encouraged, it must not be relied upon as a security control.
  • Confirm that the application ensures that combinations of related data items are reasonable according to the pre-defined rules.
  • Compare parsing across components and alternate request formats.
  • Use controlled invalid inputs to establish effects rather than assumptions.

How to fix it

Use explicit schemas and reject unexpected structures before business processing.

  • Use explicit schemas and canonical representations.
  • Prefer safe parsers and parameterised interpreter interfaces.
  • Reject unexpected structures before sensitive processing.
  • Apply resource bounds and predictable failure handling.

Blocking a few known attack strings is not a complete validation strategy. The intended data model and downstream interpretation determine which protections are needed.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss your APIs and integrations.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo