Prompt
Why did my API schema checks miss an injection attack?
Latest observation
Schema checks often miss injection attacks because they verify shape, not meaning.
Common reasons:
-
The payload was valid JSON / valid according to the schema
A schema may say “this field is a string,” but it won’t know whether the string contains SQL, NoSQL, LDAP, shell, or template injection content. -
The dangerous value is semantically unsafe, not structurally invalid
Example:"name": "'; DROP TABLE users; --"is still a string, so schema validation passes. -
The attack happened after validation
Input might be transformed later by:- string concatenation into queries
- template rendering
- command execution
- dynamic filtering/sorting
- deserialization
-
The schema was too permissive
Fields likestring,object,additionalProperties: true, or free-formpatterns can allow malicious content. -
The real risk was in nested or edge-case fields
Checks may validate top-level fields but miss:- nested objects
- arrays of objects
- optional fields
- alternate parameter names
- query/path/header values outside the body schema
-
Type coercion or parser differences
One layer may interpret values differently than another. For example:"1"vs1- duplicate keys
- Unicode normalization
- encoded characters
- null bytes or escape sequences
-
Business-logic abuse isn’t schema-invalid
Even if there’s no classic injection, attackers can manipulate fields in ways the schema allows but the application logic didn’t anticipate.
What to do instead:
-
Use schema validation as only the first layer
It helps reject malformed input, but it is not injection protection. -
Use parameterized queries / safe APIs
Never build SQL, shell commands, or templates by concatenating raw input. -
Validate against allowlists where possible
Especially for:- enums
- IDs
- sort fields
- file paths
- callback URLs
-
Escape/encode only at the sink
Apply context-specific escaping when outputting into SQL, HTML, shell, etc. -
Add security testing beyond schema checks
Include:- payload fuzzing
- SAST/DAST
- injection test cases
- logging and alerting
-
Review all inputs, not just the request body
Check query params, headers, cookies, multipart fields, and path params.
If you want, I can help you diagnose this more precisely if you share:
- the schema format you use (OpenAPI/JSON Schema/etc.)
- the field that was exploited
- where that value was used in the backend.
Brands