Overview / Goal
Design detection logic and WAF tuning to minimize false positives for a JSON REST API with nested payloads by combining strict schema validation, contextual checks (headers/content-type), input normalization, anomaly scoring with thresholds, and a developer feedback loop to iteratively refine rules.
Schema validation
- Enforce JSON Schema at the WAF edge for required fields, types, nested object shapes, allowed enum values and max lengths. Reject or quarantine requests failing validation.
- Example checks: disallow additionalProperties, limit depth (e.g., maxDepth = 6), set stringPattern for known fields (UUIDs, emails).
- Return clear 4xx with debug ID to caller; log full payload for analysis.
Header & content-type checks
- Require Content-Type: application/json; charset=utf-8 and X-Requested-By or internal API key header where applicable.
- Validate Host, Origin, and Content-Length ranges. Drop or flag requests with mismatched content-type or missing auth headers.
Normalization
- Canonicalize JSON: remove insignificant whitespace, sort object keys for consistent hashing, normalize Unicode (NFC), trim strings, and coerce numeric formats.
- Decode any nested encoded blobs (base64) before analysis; treat large encoded fields as opaque until schema checks pass.
Anomaly detection & thresholds
- Compute per-request anomaly score combining:
- schema violations weight
- unexpected fields / additionalProperties
- unusual field cardinality or nesting delta vs. baseline
- rate per client/IP and per API key
- entropy of string fields (detect injection)
- Use adaptive thresholds: low-risk (score < 20) allow, medium (20–50) rate-limit or challenge, high (>50) block/quarantine.
- Maintain per-endpoint baselines; use rolling-window statistics; auto-adjust thresholds with exponential decay.
Feedback loop & tuning
- Provide developers with a dashboard of blocked/quarantined requests including payload, reason, and debug ID.
- Implement “submit false positive” API where developers can mark events; those events trigger:
- automatic rule suppression for identical safe patterns (with expiration)
- scheduled rule review workflow and unit test addition (sample payloads)
- Log labeled events into ML model retraining pipeline for improved anomaly scoring.
Operational controls & metrics
- Track false positive rate, true positive rate, time-to-fix, developer approvals. Start in monitoring mode with sampling blocks before full enforcement.
- Periodic reviews: weekly for high-volume endpoints, monthly for others.
This approach balances strict validation and normalization with adaptive anomaly scoring and an actionable developer feedback loop to reduce false positives while keeping strong protection.