App protection
Use these routes to read and set who can reach an HTTP application: allowed IPs, blocked IPs, countries, robots and exempt paths. For the console walkthrough, see App protection.
Authentication and permissions
Accepts an organization API Key (x-api-key: znf_... or Authorization: Bearer znf_...) or a user token with x-organization-id.
| Route | Permission on project:<project-id> | Limit |
|---|---|---|
GET /v1/project/:id/protection | project.metrics.read | 100 requests per minute |
PUT /v1/project/:id/protection | project.network.update | 10 requests per minute |
PATCH /v1/project/:id/protection/blocks | project.network.update | 30 requests per minute |
POST /v1/project/:id/protection/cache/purge | project.network.update | 5 requests per minute |
owner has full access. To change settings, the project must be on a plan with capabilities.network_access: true in the GET /v1/project/plans catalog.
Read the protection
GET /v1/project/:id/protection{
"status": "success",
"data": {
"protection": {
"trusted_ips": [{ "cidr": "203.0.113.10/32", "description": "Office" }],
"countries": { "mode": "block", "codes": ["RU"] },
"user_agents": { "presets": ["ai"], "terms": ["BadBot"] },
"exempt_paths": ["/api/webhooks"],
"rate_limits": [{ "id": "login", "path_prefix": "/login", "methods": ["POST"], "rate": "10r/m", "burst": 5 }],
"cache": { "mode": "headers", "version": 3 },
"challenge": { "under_attack": false, "paths": ["/signup"] }
},
"network_access": {
"ingress_white_list": [{ "cidr": "0.0.0.0/0", "description": "Any IP" }],
"ingress_black_list": [{ "cidr": "198.51.100.7/32", "description": "Abuse" }]
}
}
}protection is null when nothing has been configured. network_access carries the lists from Network access.
Set the protection
PUT /v1/project/:id/protectionThe call replaces the configuration, with one exception: an absent rate_limits, cache or challenge keeps what is already stored. To clear one, send rate_limits: [], cache: { "mode": "off" } or challenge: { "under_attack": false, "paths": [] }.
| Field | Type | Required | Description |
|---|---|---|---|
protection.trusted_ips | array | Yes | Allowed IPs, up to 200 items; { "cidr", "description" } in IPv4 or IPv6 |
protection.countries.mode | string | Yes | block (block the listed) or allow_only (allow only the listed) |
protection.countries.codes | array | Yes | ISO country codes, up to 50 |
protection.user_agents.presets | array | Yes | Categories: ai, seo, tools, empty |
protection.user_agents.terms | array | Yes | Up to 20 terms of 2 to 40 characters (letters, digits, space and . _ / -), matched as text, case-insensitively |
protection.exempt_paths | array | Yes | Up to 10 path prefixes, such as /api/webhooks, exempt from country and robot rules. Each prefix starts with / and is up to 101 characters (letters, digits and . _ ~ / -) |
protection.rate_limits | array | No | Up to 5 per-route limit rules. Each: id (1 to 8 lowercase letters or digits, unique in the project), path_prefix (same format as exempt_paths), methods (optional; GET, POST, PUT, PATCH, DELETE; empty or absent applies to all), rate (10r/m, 60r/m, 10r/s or 50r/s, per IP) and burst (integer from 0 to 100) |
protection.cache.mode | string | No | off, headers (honors the application's Cache-Control and Expires) or static (also stores .js, .css, .png, .jpg, .jpeg, .gif, .svg, .webp, .ico, .woff, .woff2 for 1 hour) |
protection.cache.version | number | No | Read-only: the value sent is ignored. Goes up on every cache purge and every successful deploy |
protection.challenge.under_attack | boolean | No | true challenges every browser page GET |
protection.challenge.paths | array | No | Up to 10 path prefixes (same format as exempt_paths) challenged even without under-attack mode |
ingress_black_list | array | No | Blocked IPs, up to 200 items; { "cidr", "description" } in IPv4 or IPv6 |
{
"protection": {
"trusted_ips": [{ "cidr": "203.0.113.10/32", "description": "Office" }],
"countries": { "mode": "block", "codes": ["RU"] },
"user_agents": { "presets": ["ai", "seo"], "terms": ["BadBot"] },
"exempt_paths": ["/api/webhooks"],
"rate_limits": [{ "id": "login", "path_prefix": "/login", "methods": ["POST"], "rate": "10r/m", "burst": 5 }],
"cache": { "mode": "headers" },
"challenge": { "under_attack": false, "paths": ["/signup"] }
},
"ingress_black_list": [{ "cidr": "198.51.100.7/32", "description": "Abuse" }]
}{
"status": "success",
"data": {
"protection": {
"trusted_ips": [{ "cidr": "203.0.113.10/32", "description": "Office" }],
"countries": { "mode": "block", "codes": ["RU"] },
"user_agents": { "presets": ["ai", "seo"], "terms": ["BadBot"] },
"exempt_paths": ["/api/webhooks"],
"rate_limits": [{ "id": "login", "path_prefix": "/login", "methods": ["POST"], "rate": "10r/m", "burst": 5 }],
"cache": { "mode": "headers", "version": 3 },
"challenge": { "under_attack": false, "paths": ["/signup"] }
},
"network_access": {
"ingress_white_list": [{ "cidr": "0.0.0.0/0", "description": "Any IP" }],
"ingress_black_list": [{ "cidr": "198.51.100.7/32", "description": "Abuse" }]
}
}
}The response carries the applied protection and IP lists, in the same format as the read. The same applies to quick blocks.
The rules take effect in 1 to 2 seconds, without restarting instances.
Block or unblock quickly
PATCH /v1/project/:id/protection/blocks| Field | Type | Required | Description |
|---|---|---|---|
op | string | Yes | add or remove |
type | string | Yes | ip, country or user_agent |
value | string | Yes | The IP (an IP without a prefix becomes /32 or /128), the country code or, for user_agent, a category name (ai, seo, tools, empty) |
curl -X PATCH "https://api.zenifra.com/v1/project/6650f1a2b3c4d5e6f7a8b9c0/protection/blocks" \
-H "x-api-key: znf_..." \
-H "Content-Type: application/json" \
-d '{"op": "add", "type": "ip", "value": "203.0.113.7"}'Purge the cache
POST /v1/project/:id/protection/cache/purgeInvalidates all of Zenifra's cache for the project and responds with the same body as the read, with protection.cache.version incremented. It takes no body. Every successful deploy does the same when cache.mode is not off.
curl -X POST "https://api.zenifra.com/v1/project/6650f1a2b3c4d5e6f7a8b9c0/protection/cache/purge" \
-H "x-api-key: znf_..."With cache.mode set to off, the response is 409 PROTECTION_CACHE_OFF.
Limit, cache and challenge
- Limit: above the rate and tolerance, the request gets
429. Counting is per IP and per server, so the limit is approximate. A trusted IP is never limited. - Cache:
GETandHEADonly..jsand.cssfiles may also be kept at the network edge; deploys and the purge apply to Zenifra's cache. Responses withSet-Cookieand requests withAuthorizationor a cookie are never stored. The response carriesX-CachewithHIT,MISSorBYPASS. - Challenge: only a browser's page
GET. API calls, webhooks and certificates are never challenged, nor are trusted IPs and exempt paths. The proof takes about 1 second and the cookie is valid for 24 hours. The/.zenifra/prefix is reserved.
These features require the same plan as the rest of the protection, starting with Premium Plus. On another plan the API returns PROTECTION_NOT_AVAILABLE_ON_PLAN when changing.
Order of evaluation
- The certificate validation path always passes.
- Allowed IP passes.
- Private project: anyone outside the allow list gets
404("Application not found"). - Blocked IP:
403with the "Access blocked by the site owner" page. - Exempt path passes.
- Country. An unknown country is never blocked.
- Robot.
Protection rules do not apply to previews. Country data uses IP Geolocation by DB-IP, under CC BY 4.0.
Errors
| Code | Situation |
|---|---|
400 PROTECTION_INVALID_VALUE | Invalid value; the field is in field. Includes a sixth limit rule, a rate outside the list, burst outside 0 to 100, an invalid path or method |
400 NETWORK_RULES_LIMIT_EXCEEDED | More items than a list's limit |
400 PROTECTION_BLOCKS_EVERYONE | Quick block of 0.0.0.0/0 or ::/0; to make the project private, use IP access control |
403 PROTECTION_NOT_AVAILABLE_ON_PLAN | The plan does not allow blocking IPs |
404 | Project not found |
409 PROTECTION_COUNTRY_MODE_CONFLICT | Quick country block or unblock while the configuration is allow_only |
409 PROTECTION_CACHE_OFF | Cache purge with cache.mode set to off |
409 | Project with private exposure |
422 | The project is a preview or is not an HTTP application |
429 | Request limit exceeded |
Next steps
- See the IP lists in Application network access.
- Follow the console walkthrough in App protection.
Last updated on
Application network access
Restrict through the Zenifra API which IP ranges can reach a public HTTP application, using allow and block lists in IPv4 CIDR notation with per-list limits.
Project billing
Read a project's hourly usage and billing entries through the Zenifra API, with period and status filters, totals by category, and pagination for reports.