Get your free beta license ↗
API operation · security group
POST

/security/modsec/rules

First published 19 Nov 20260.2.30Unchanged since publication

Add a custom ModSecurity rule

Who may call it
AdministratorResellerCustomer
Token scope, any of
securityall
Answers201 Created

Adds a server-wide rule and returns the saved rule. UrbeStack tests Apache's configuration with the rule in place before applying it. If the test fails, the API returns 400 with Apache's error and discards the rule. The API also returns 400 if text or note fails validation.

A rule that passes the test can still block every request to every hosted site. The UrbeStack web interface remains reachable. To disable the rule, set enabled to false through PATCH /security/modsec/rules/{id}.

As a command

Run as root on the server

Request body

JSON· 3 fields
textstring, up to 8000 charactersRequired
One SecRule or SecAction directive or one complete chain in ModSecurity syntax, up to 8000 characters. Put id:N on the first directive with an unused number from 1 to 89999, and include the chain action on each directive in a chain except the last.
enabledboolean
Whether the rule is enabled. The default is true, and false saves the rule disabled.
notestring, up to 200 characters
Single-line description of the rule's purpose, up to 200 characters, with no ASCII control characters.

Example

See the API overview for how to set $API and $TOKEN.
Request
curl -sS -X POST "$API/security/modsec/rules" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": true,
    "note": "added by hand",
    "text": "text"
  }'
Response · 201 Created
{
  "apache": "text",
  "created_at": "2026-09-09T10:15:00Z",
  "created_by": "text",
  "enabled": true,
  "files_changed": 1,
  "note": "added by hand",
  "refuses": true,
  "rule": 1,
  "text": "text",
  "updated_at": "text",
  "updated_by": "text"
}

Errors

4 errors, each a status and a sentence
400note is one line of up to 200 characters
400text is the rule, as the engine reads it, up to 8000 characters
401Authentication required
409Rule <id> is already a custom rule: change that one, or give this one another number
Generated from release 0.2.35 (current) · the API’s own descriptionThis entry has been unchanged since it was first published in release 0.2.30 on 19 Nov 2026.
urbestack.com/docs/api/post-security-modsec-rules/