Nginx + ModSecurity Per-Route Request-Body Contracts
Turning on ModSecurity request-body inspection for every write on a shared edge breaks uploads, WebSockets, authoring text and undocumented media types on day one.
$29
Works with the AI Agents you already use
Nginx + ModSecurity Per-Route Request-Body Contracts
Example session with this skill installed
We run ModSecurity with the OWASP CRS on our Nginx edge for GET/HEAD only. Turn on request-body inspection for POST /api/auth/login (JSON, 4 KB) on shop.example.com without risking the other 20 sites.
- Read your context and instructions
- Compiled the nginx + modsecurity
Summary
Stage 1 planned for one route; nothing deployed yet.
What I did
- Wrote
contracts/stage1.json: profileshop-api, hostshop.example.com, routePOST exact /api/auth/login, mediaapplication/json, cap 4096.validate-> ok, 1 route. - Rendered the candidate from the live baseline and wrote the plan: baseline sha256 7c0f..., candidate sha256 2e9a...,
deployed: false,authenticated_workflows_verified: false. - Probed all 21 registered hostnames and saved
before.json.
For you to do, in this order
- Replace the policy file only if its hash is still 7c0f...;
nginx -t; graceful reload; confirm the master PID is unchanged. verify_hosts.py --compare before.jsonmust report 0 regressions.- Log in once with the test account; expect 200.
tail -n 20000 access.log | check_write_outcomes.py --contracts contracts/stage1.json --host shop.example.comnow, at 15 minutes and at 1 hour. Any 400/403/413/415 on the route: restore the previous policy bytes and reload.
Stage 2 (the 16 KB JSON prefix route) is rendered cumulatively from the same baseline once stage 1 has a clean hour.
Connects securely to your tools. The creator never sees your data.
About this skill
Turning on ModSecurity request-body inspection for every write on a shared edge breaks uploads, WebSockets, authoring text and undocumented media types on day one. This kit keeps the engine off for writes by default and enables it for one reviewed route at a time, with the media types and body cap taken from the application's source, a rollback trigger defined before activation, and no request body ever logged.
body_contracts.py: baseline renders a GET/HEAD-only policy scoped to registered hostnames with the OWASP CRS at paranoia 1, audit and debug logging off and rule 920170 removed; validate checks a contract document (application profiles bound to the hosts they register, canonical exact or segment-prefix paths, POST/PUT/PATCH/DELETE, JSON, form, multipart or +json media, cap 1..131072, no overlapping routes, budgets); render turns contracts into per-route selector rules plus shared gates (415 for unsupported or missing media on a non-empty body, 400 for duplicate Content-Type or parser errors, 413 for declared or received length over the route cap or a partial body) with unique ids, refusing a changed or already-rendered baseline; plan binds baseline, candidate, registry, receipt and contracts by SHA-256 and states deployed: false.
verify_hosts.py: probes every registered hostname before and after a change; a success turning into failure, a sub-400 turning 400+, or anything turning 403 is a regression (exit 1). check_write_outcomes.py: counts statuses on contract routes from a bounded access-log tail or JSON lines; any 400/403/413/415 exits 1; no line echoed.
Reference: the staged activation order (observe, review from source, contract, plan, exact-file activation, observe, roll back) and the contract schema with the emitted rules explained. 10 offline tests. Python 3.9+ stdlib; the probe uses curl.
Requires libmodsecurity v3 and CRS 4. Body inspection limit of 128 KiB. Rule IDs 1000700-1000899 must be available. No automated Nginx reloading.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 18 days ago
Requires
Permissions
Reads your policy, registry and contract files and writes candidate and plan files you name. verify_hosts.py sends HTTPS GET requests to the hostnames in your registry only. Nothing installs, reloads or edits the live policy.