# PATCH /security/modsec

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

UrbeStack release 0.2.35 API operation in the security group.

Change the server's ModSecurity mode or who manages it

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

Provide mode, managed, or both. The API returns 400 if neither field is supplied or either value is invalid. The API also accepts 1 and 0 for managed, meaning true and false respectively. While the administrator manages ModSecurity, UrbeStack saves the mode for use when it takes over.

When UrbeStack manages ModSecurity, it includes OWASP CRS if the server or any domain uses logging or blocking, unless another rule set uses overlapping rule numbers. When a change affects Apache's configuration, UrbeStack tests it and reloads Apache immediately. If Apache rejects the configuration, UrbeStack restores the previous configuration, discards the change, and returns Apache's error.

The response includes the same status information as GET /security/modsec and a set object with the results of the changes.

## As a command

- [urbestack-modsec-set](https://urbestack.com/docs/commands/urbestack-modsec-set.md): Sets the server's ModSecurity mode, changes who manages ModSecurity, or does both.

## Request body

JSON.

- `managed` (boolean): Whether UrbeStack manages ModSecurity. Set true to apply UrbeStack's configuration and queue installation if the module is missing, or false to remove UrbeStack's configuration and return control to the administrator.
- `mode` (string, one of off, logging, blocking): Server mode, which defaults to off and disables inspection for domains that follow the server mode. Use logging to inspect every request and log those that would be refused, or blocking to allow matching requests to be refused.

## 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" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "managed": true,
    "mode": "off"
  }'
```

Response, 200 OK:

```
{
  "by_hand": {
    "directive": "text",
    "file": "urbestack-panel-20260909T101500Z.json.enc",
    "line": 1,
    "mode": "text"
  },
  "decided": true,
  "disabled_rules": {
    "by_administrators": 1,
    "by_owners": 1,
    "domains": 1,
    "gone": 1,
    "server": 1,
    "total": 1
  },
  "domains": {
    "customized": 1,
    "in_force": {
      "blocking": 1,
      "logging": 1,
      "off": 1
    },
    "lowered": 1,
    "own_mode": 1,
    "total": 1
  },
  "files": {
    "loader": "text",
    "ours": "text",
    "ours_written_at": "text",
    "packaged": "text",
    "yours": "text"
  },
  "installed": true,
  "limits": {
    "request": 1,
    "request_without_files": 1
  },
  "loaded": true,
  "managed": true,
  "mode": "off",
  "mode_set": {
    "at": "text",
    "by": "text"
  },
  "module": {
    "file": "urbestack-panel-20260909T101500Z.json.enc",
    "package": "basic",
    "version": "0.0.1"
  },
  "other_rule_set": {
    "file": "urbestack-panel-20260909T101500Z.json.enc"
  },
  "own_rules": {
    "enabled": 1,
    "file": "urbestack-panel-20260909T101500Z.json.enc",
    "total": 1
  },
  "packaged_active": true,
  "rule_set": {
    "included": true,
    "name": "alice",
    "version": "0.0.1"
  },
  "set": {},
  "state": "managed",
  "wordpress_exclusions": {
    "version": "0.0.1"
  }
}
```

## Errors

- 400: '<zone>' is not a zone this machine knows: timedatectl list-timezones names them
- 400: --managed is true or false
- 400: A ModSecurity mode is off, logging or blocking
- 400: A new job is queued or running
- 400: Domain name required
- 400: Domain name too long
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid boolean
- 400: Invalid domain name
- 400: Invalid port
- 400: Invalid setting key
- 400: Job parameters must be an object
- 400: Nothing to set: give --mode, --managed or both
- 400: Nothing to set: give mode, managed or both
- 400: PHP <version> cannot be the default: it is hidden from new choices on this server
- 400: PHP <version> cannot be the default: it is not installed on this server
- 400: Unknown job type
- 400: Unknown setting '<key>'
- 400: jobs.keep_days (<keep>) may not be smaller than jobs.show_days (<show>): a job cannot be shown longer than it is kept; 0 keeps them for good
- 400: managed is true or false
- 401: Authentication required
- 404: Setting '<key>' not found
- 409: <key> cannot take that value: <SECOND>{<k>}{on} <sp> (<k>). <SECOND>{<k>}{move}, or choose another
- 409: <key> cannot take that value: the panel listens on port <port> (panel.port). Move the panel first, or choose another
- 409: <s.subject> cannot take port <port>: 
- 409: <s.subject> cannot take port <port>: <why>
- 409: <s.subject> cannot take port <port>: it is the panel's port (panel.port)
- 409: A change is already armed for revert (
- 409: Sharing is required with this license.
- 409: The panel cannot take port <port>: 
- 409: The panel cannot take port <port>: <why>
- 409: These are the nameservers of a distribution network with several nodes, and every node lists the same ones. To remove a nameserver or move it to another node, use the actions beside its name on DNS zones › Nameservers & addresses, or urbestack-dns-nameserver
