Security & Validation
Applies to
Gatewayruntime for API, AI, and MCP gateways
Hosting
Managed EdgeManaged DedicatedSelf-Hosted

Request Validation Policy

The Request Validation policy validates incoming requests against your OpenAPI schema definitions, ensuring that all requests conform to your API's expected structure and data types before they reach your backend services.

With this policy, you'll benefit from:

  • Data Integrity Protection: Prevent malformed or invalid data from reaching your backend systems
  • Automatic Schema Enforcement: Leverage your existing OpenAPI definitions for validation without additional code
  • Comprehensive Validation: Validate request bodies, query parameters, path parameters, and headers
  • Detailed Error Responses: Return clear, actionable error messages that help API consumers fix invalid requests
  • Developer-Friendly Experience: Improve the developer experience by providing immediate feedback on request issues
  • Reduced Backend Errors: Minimize crashes and unexpected behavior caused by invalid input data
  • API Contract Enforcement: Ensure all API consumers adhere to your documented API contract

When configured, any requests that do not conform to your OpenAPI schema will be rejected with a 400: Bad Request response containing a detailed error message (in JSON) explaining why the request was not accepted.

Configuration

The configuration shows how to configure the policy in the 'policies.json' document.

JSONconfig/policies.json
{ "name": "my-request-validation-inbound-policy", "policyType": "request-validation-inbound", "handler": { "export": "RequestValidationInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "includeRequestInLogs": false, "logLevel": "info", "validateBody": "reject-and-log", "validateHeaders": "none", "validatePathParameters": "log-only", "validateQueryParameters": "log-only" } } }

Policy Configuration

  • name <string> - The name of your policy instance. This is used as a reference in your routes.
  • policyType <string> - The identifier of the policy. This is used by the Zuplo UI. Value should be request-validation-inbound.
  • handler.export <string> - The name of the exported type. Value should be RequestValidationInboundPolicy.
  • handler.module <string> - The module containing the policy. Value should be $import(@zuplo/runtime).
  • handler.options <object> - The options for this policy. See Policy Options below.

Policy Options

The options for this policy are specified below. All properties are optional unless specifically marked as required.

  • validateBody <string> - The action to perform when validation fails. Allowed values are none, log-only, reject-and-log, reject-only. Defaults to "none".
  • validateQueryParameters <string> - The action to perform when validation fails. Allowed values are none, log-only, reject-and-log, reject-only. Defaults to "none".
  • validatePathParameters <string> - The action to perform when validation fails. Allowed values are none, log-only, reject-and-log, reject-only. Defaults to "none".
  • validateHeaders <string> - The action to perform when validation fails. Allowed values are none, log-only, reject-and-log, reject-only. Defaults to "none".
  • logLevel <string> - The log level to use when logging validation errors. Allowed values are error, warn, info, debug. Defaults to "info".
  • includeRequestInLogs <boolean> - Whether to include the request in the logs. Defaults to false.

Using the Policy

The Request Validation Inbound policy validates incoming requests against your OpenAPI schema definitions. This ensures that all requests to your API conform to your specified data structure and types before they reach your backend services.

How It Works

This policy automatically validates incoming requests based on the OpenAPI schemas defined in your API specification. It checks:

  • Request Bodies: Validates JSON/XML payloads against your schema definitions
  • Query Parameters: Ensures query parameters match expected types and constraints
  • Path Parameters: Validates URL path parameters against defined patterns
  • Headers: Verifies required headers are present and conform to specifications

When a request fails validation, the policy returns a detailed 400 Bad Request response with specific information about which part of the request failed validation and why.

Configuration

The policy requires minimal configuration as it automatically uses your existing OpenAPI schemas. You can enable or disable validation for specific parts of the request (body, query parameters, headers) through the policy options.

OpenAPI Schema Example

Here's an example of how to specify a schema for validation in a request body in your OpenAPI specification:

JSONCode
"requestBody": { "description": "user to add to the system", "content": { "application/json": { "schema": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }, "required": [ "name", "age" ] } } } }

Advanced Validation

The policy supports the full range of OpenAPI schema validation features, including:

  • Type validation (string, number, boolean, array, object)
  • Format validation (date, date-time, email, etc.)
  • Pattern matching with regular expressions
  • Numeric constraints (minimum, maximum, multipleOf)
  • String constraints (minLength, maxLength)
  • Array constraints (minItems, maxItems, uniqueItems)
  • Required properties
  • Enum values
  • Complex schemas with allOf, anyOf, oneOf, and not

Compatibility date 2026-11-06

From compatibility date 2026-11-06, the policy validates requests against the rules your OpenAPI document declares. For how to adopt the date in an existing project, see Compatibility dates.

  • JSON Schema dialect: Validation follows the dialect a schema declares in $schema or jsonSchemaDialect. It supports JSON Schema 2020-12, 2019-09, draft-07, and draft-06. In draft-07 and draft-06, keywords next to a $ref other than annotations are ignored, as those dialects specify.
  • Formats: Standard formats such as date-time, email, hostname, ipv4, ipv6, uri, uuid, and the OpenAPI numeric formats are checked as their specifications define them. url, binary, password, and unknown formats aren't checked, so format: "url" doesn't reject an invalid URL. Use format: "uri" or a pattern instead.
  • Patterns: A pattern is a Unicode regular expression. A pattern such as ^\p{L}+$ matches café.
  • Own properties only: required and properties look only at properties the request sets, so {} doesn't satisfy "required": ["constructor"].
  • Parameter coercion: Query, path, and header values arrive as strings, and the policy still coerces them to the declared type. A query string ?limit=5 is valid for { "type": "integer" }.
  • Path item parameters: Parameters declared on a path item, rather than on an operation, are validated in every location the policy checks. An operation parameter with the same name and in overrides the path item's.

Before this date, a request that carried a parameter declared on the path item failed with Validator not found when the policy validated that location. From this date, that error no longer occurs for those parameters. A request that breaks the parameter's schema is handled like any other validation failure: a 400 response with reject-only or reject-and-log, and a log entry without rejecting the request with log-only.

JSONCode
"/users/{id}": { "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "integer", "minimum": 1 } } ], "post": { "…": "…" } }

With validatePathParameters set to reject-only, POST /users/3 succeeds and POST /users/0 returns a 400 because id is below the minimum.

A schema that declares a dialect other than those four fails the build and names where the dialect is declared.

Read more about how policies work

Last modified on