Nginx + ModSecurity Per-Route Request-Body Contracts

    1

    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

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    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

    1. Wrote contracts/stage1.json: profile shop-api, host shop.example.com, route POST exact /api/auth/login, media application/json, cap 4096. validate -> ok, 1 route.
    2. Rendered the candidate from the live baseline and wrote the plan: baseline sha256 7c0f..., candidate sha256 2e9a..., deployed: false, authenticated_workflows_verified: false.
    3. 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.json must 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.com now, 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    python3 curl nginx modsecurity

    Permissions

    Terminal / Shell
    Network Access
    Read Files
    Write Files

    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.

    Listed18 days ago

    What's inside

    Frequently Asked Questions

    This skill creates a targeted activation plan that enables ModSecurity body inspection for specific, validated routes rather than globally, preventing the common outages caused by undocumented media types or oversized payloads.

    The skill is designed for Python 3.9+ environments and is optimized for libmodsecurity v3 with OWASP CRS 4; it requires standard CLI tools like curl for its regression probing functionality.

    The 128 KiB limit is a safety gate designed to ensure high performance and prevent buffer exhaustion on shared edge nodes, keeping inspection focused on high-risk API and form data.

    You receive the Python-based contract validator, the rule renderer for generating specific 4xx gates, and the verification scripts used for regression probing and post-deployment monitoring.

    The skill uses hash-bound activation plans to detect if your Nginx configuration has drifted from the known state, ensuring you don't deploy new rules onto a compromised or manually altered policy.

    New in Security