# PATCH /security/modsec/rules/{id}

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

UrbeStack release 0.2.35 API operation in the security group.

Update a custom ModSecurity rule

- Who may call it: administrator
- Token scope, any of: security, all
- Answers: 200 OK

Provide at least one of text, note, or enabled. The API returns 400 if none is supplied or if id, text, or note fails validation. If text specifies a different rule number, that number must be unused by other custom rules and becomes the rule's new id. Numbers from 90000 onward are reserved for UrbeStack and the bundled rule set.

Enabling a rule or replacing the text of a rule that will remain enabled requires UrbeStack to manage ModSecurity and Apache to load the module. UrbeStack tests Apache's configuration before applying the change. If Apache rejects it, UrbeStack keeps the previous rule and returns Apache's error. You can disable a rule even if Apache would reject its text. The response contains the updated rule.

## As a command

- [urbestack-modsec-rule-set](https://urbestack.com/docs/commands/urbestack-modsec-rule-set.md): Changes the custom ModSecurity rule selected by --rule.

## Parameters

- `id` (path, integer, 1 to 89999, required): Number of the custom rule to delete.

## Request body

JSON.

- `enabled` (boolean): Whether to enable or disable the rule. Use true to enable it or false to disable it.
- `note` (string, up to 200 characters): Single-line description of the rule's purpose, up to 200 characters, with no ASCII control characters. Use an empty string to clear the note.
- `text` (string, up to 8000 characters): One SecRule or SecAction directive or one complete chain in ModSecurity syntax, up to 8000 characters. Put id:N on the first directive with a number from 1 to 89999, and include the chain action on each directive in a chain except the last.

## 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 PATCH "$API/security/modsec/rules/1" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": true,
    "note": "added by hand",
    "text": "text"
  }'
```

Response, 200 OK:

```
{
  "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: --enabled is on or off
- 400: A rule is named by its number
- 400: Nothing to set: give text, note or enabled
- 400: Nothing to set: give the text, what it is for, or on or off
- 400: Say which rule: --rule NUMBER
- 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 <new.rule_id> is already another custom rule
