# POST /security/modsec/rules

First published 19 Nov 2026 (release 0.2.30) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the security group.

Add a custom ModSecurity rule

- Who may call it: administrator
- Token scope, any of: security, all
- Answers: 201 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

- [urbestack-modsec-rule-add](https://urbestack.com/docs/commands/urbestack-modsec-rule-add.md): Adds a server-wide custom ModSecurity rule from standard input.

## Request body

JSON.

- `text` (string, up to 8000 characters, required): 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.
- `enabled` (boolean): Whether the rule is enabled. The default is true, and false saves the rule disabled.
- `note` (string, up to 200 characters): Single-line description of the rule's purpose, up to 200 characters, with no ASCII control characters.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
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

- 400: note is one line of up to 200 characters
- 400: text is the rule, as the engine reads it, up to 8000 characters
- 401: Authentication required
- 409: Rule <id> is already a custom rule: change that one, or give this one another number
