Prompt

How do I validate API schemas and block unexpected requests?

Technology / Cybersecurity1 observationLast seen Oct 29, 2026

Latest observation

Oct 29, 2026OpenAI APIWeb search: off

To validate API schemas and block unexpected requests, you typically want request validation at your API boundary plus strict schema enforcement.

Core approach

1) Define an explicit schema

Use a schema format such as:

  • OpenAPI for REST APIs
  • JSON Schema for request/response bodies
  • GraphQL schema for GraphQL APIs
  • Protobuf / Avro for RPC/event-based APIs

Your schema should specify:

  • required fields
  • types
  • enums
  • formats/patterns
  • min/max lengths and ranges
  • allowed additional properties: ideally false for strictness

Example JSON Schema idea:

{
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" }
  },
  "additionalProperties": false
}

2) Validate at the API gateway or server middleware

Block requests before business logic runs.

Common places:

  • API gateway: Kong, Apigee, AWS API Gateway, NGINX with validation plugins
  • Backend middleware: Express, FastAPI, Spring, Django, etc.
  • Service mesh / proxy: Envoy, Istio with ext_authz/WASM filters

Validation should cover:

  • URL/path params
  • query params
  • headers
  • request body
  • content type
  • size limits

3) Reject unknown fields and invalid types

To block unexpected requests:

  • set additionalProperties: false
  • reject unknown query/body parameters
  • fail on type coercion when possible
  • require exact enum values
  • validate nested objects recursively

This helps prevent:

  • accidental client bugs
  • mass assignment vulnerabilities
  • hidden/unexpected input being processed

4) Validate content type and method

Only accept what you expect:

  • Content-Type: application/json
  • correct HTTP methods per route
  • reject text/plain, multipart/form-data, etc. unless needed

5) Enforce strict response schemas too

Validate responses as well, especially in microservices or public APIs:

  • catches accidental contract drift
  • prevents leaking fields
  • supports consumer-driven contracts

6) Log and monitor rejections

When rejecting requests:

  • return 400 Bad Request or 422 Unprocessable Entity
  • log schema violations
  • include route, validation error, and request metadata
  • rate-limit repeated invalid attempts if needed

7) Use tooling

Depending on your stack:

Node.js

  • ajv
  • zod
  • joi
  • express-openapi-validator

Python

  • pydantic / FastAPI validation
  • jsonschema

Java

  • Bean Validation (jakarta.validation)
  • Spring @Valid
  • OpenAPI validators

Go

  • go-playground/validator
  • OpenAPI middleware

API gateways

  • Kong schema validation plugins
  • AWS API Gateway models/validators
  • Apigee policies

8) Prefer “deny by default”

A good rule:

  • only accept documented endpoints
  • only accept documented fields
  • only accept documented methods
  • reject everything else

Example: express + JSON Schema

import express from "express";
import Ajv from "ajv";

const app = express();
app.use(express.json());

const ajv = new Ajv({ allErrors: true, removeAdditional: false });

const schema = {
  type: "object",
  required: ["name", "email"],
  additionalProperties: false,
  properties: {
    name: { type: "string" },
    email: { type: "string", format: "email" }
  }
};

const validate = ajv.compile(schema);

app.post("/users", (req, res) => {
  const valid = validate(req.body);
  if (!valid) {
    return res.status(400).json({ errors: validate.errors });
  }
  res.json({ ok: true });
});

Best practice checklist

  • Define schemas for every route
  • Reject unknown fields
  • Validate all input sources
  • Enforce content type and size limits
  • Validate before business logic
  • Return clear 4xx errors
  • Log violations
  • Keep schemas versioned and tested

If you want, I can show you how to do this in a specific framework like FastAPI, Express, Spring Boot, or AWS API Gateway.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.