# PATCH /domains/{name}/modsec

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

UrbeStack release 0.2.35 API operation in the domains group.

Set a domain's ModSecurity mode or its owner's choice

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

Supply mode, choice, or both. The domain's owner, the reseller who manages the owner, and administrators can set choice. Only administrators can set mode. The API returns 403 if another caller supplies mode and 400 if neither field is supplied or a mode value is invalid.

If the owner has a choice, the weaker of that choice and the administrator's mode for the domain takes effect. Otherwise, the administrator's mode applies.

UrbeStack saves the settings and, when modsec.managed is enabled, updates the domain's Apache virtual host and ModSecurity configuration as needed. UrbeStack tests the Apache configuration only if it changes and reloads Apache if the test passes. If Apache rejects the configuration, UrbeStack restores the previous configuration and discards the changes. The response contains the same details as GET /domains/{name}/modsec.

## As a command

- [urbestack-domain-modsec-set](https://urbestack.com/docs/commands/urbestack-domain-modsec-set.md): Sets the ModSecurity mode or the owner's choice for a domain.

## Parameters

- `name` (path, DomainName, required)

## Request body

JSON.

- `choice` (string, one of off, logging, blocking or null): Owner's ModSecurity mode, accepted only while the administrator's mode for the domain is logging or blocking and the choice is no stronger. Both null and a value equal to the administrator's mode clear the choice.
- `mode` (string, one of off, logging, blocking or null): Administrator's ModSecurity mode for the domain, which can raise or lower the server mode. Use null to make the domain inherit the server mode again.

## 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/domains/example.com/modsec" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "choice": "off",
    "mode": "off"
  }'
```

Response, 200 OK:

```
{
  "allowed": "off",
  "choice": {
    "at": "text",
    "mode": "off"
  },
  "customized": true,
  "disabled_rules": {
    "by_owner": 1,
    "max": 1,
    "total": 1
  },
  "domain": "example.com",
  "in_force": "off",
  "locked": true,
  "managed": true,
  "own": {
    "at": "text",
    "by": "text",
    "mode": "off"
  },
  "owner": "text",
  "server": {
    "by_hand": "off",
    "mode": "off"
  }
}
```

## Errors

- 400: A ModSecurity mode is off, logging or blocking
- 400: Domain name required
- 400: Domain name too long
- 400: Invalid domain name
- 400: Nothing to set: give a mode, a choice or both
- 400: Nothing to set: give mode, choice or both
- 401: Authentication required
- 403: A domain's own mode is set by an administrator
- 404: Domain '<name>' not found
- 409: ModSecurity is off for <name> by the administrator, so its owner's choice would change nothing
- 409: The administrator allows up to <NAMES>{<base>} for <name>; its owner may lower that, not raise it
