Skip to main content
ngx_json_guard shield

ngx_json_guard

Streaming JSON structural guard for NGINX.
Cheap admission before ModSecurity — never instead of it.

0.67%
added latency on an accepted 20 MiB body under full CRS
~10 µs
guard cost on a typical small JSON body
260 MiB/s
single-threaded streaming parse throughput
11 / 11
structural violation classes rejected (ModSecurity: 6, Coraza: 5)

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