Where it sits
The guard answers one narrow question before anything expensive runs: is this well-formed JSON with a sane structure? Content inspection stays where it belongs.
What you get
Structural admission, not detection
Well-formedness plus configurable limits — depth, key/string/number lengths, token counts, object and array widths. Malformed JSON gets a 400, structurally abusive JSON a 413. Eleven NGINX directives, sane defaults.
The body survives, bit-for-bit
Validation is read-only over NGINX's own request-body buffers and temp files. ModSecurity still inspects every byte — an SQLi planted at the tail of a 20 MiB document is still blocked, verified by SHA-256 digests at the upstream.
Streaming, bounded memory
A non-recursive finite state machine walks NGINX's body buffers (temp files in 64 KiB reads) with a fixed 16,600-byte parser state. No DOM, no body retention — memory never grows with body size.
Runs before your WAF
A PREACCESS layer in front of ModSecurity + CRS or Coraza — so you can keep full body inspection enabled and drop partial processing, instead of choosing between safety and coverage.
Quick start
load_module modules/ngx_http_json_guard_module.so;
location /api/ {
json_guard on; # that's it — defaults are sane
proxy_pass http://app;
}Not a WAF. No signatures, no CRS rules, no SQLi or XSS detection — those stay in ModSecurity.
Why it was built