Edge Rules
Edge rules are an ordered list of rules on a project. Each one matches a request on its path, address, country, headers or other attributes, and then blocks it, allows it, challenges the visitor, redirects it or only logs it. The Temps proxy checks them on every request, before the request reaches your app.
Edge rules are in Temps from v0.1.0-beta.58, and this page describes v0.1.0-beta.62. The temps edge-rules CLI commands are in the Temps source but not in the published @temps-sdk/cli (0.1.38 does not have them). Use the console or the API, or build the CLI from the repository.
Typical uses are blocking scanners that probe for /wp-login.php or /.env, limiting /admin to your office network, challenging traffic from cloud hosting networks, and redirecting a path to another host.
How rules are evaluated
Rules are checked top to bottom, and the first rule that decides the request wins. A request that no rule decides continues as normal.
- Where it sits. Edge rules run before the project's IP access list and rate limits, then Shield and any password wall. A rule that allows a request skips the remaining edge rules only. See Request flow.
- Scope. A rule applies to every environment of the project, or to one environment. Rules for other environments are skipped.
- Disabled rules are kept but never evaluated.
- Log-only rules and
logactions record a match and keep evaluating, so a later rule can still decide. - A
challengerule is skipped for a visitor who already holds a clearance, and evaluation continues with the next rule. - An
allowrule that tests the path is skipped when the path is ambiguous (for example one that needs normalizing to read), because the app might read it differently. Anonegroup cannot invert this check.
Changes apply within seconds of saving. There are no drafts.
Conditions
A rule's match is a tree of conditions joined by groups. A group is all (every child matches), any (at least one matches) or none (no child matches). Groups can nest up to 4 levels, and an empty group matches everything.
| Field | Matches | Operators |
|---|---|---|
| Client IP | The client address, resolved through trusted proxies | in_cidr |
| Country | Two-letter ISO country code (GeoIP) | eq, in |
| Continent | AF, AN, AS, EU, NA, OC or SA (GeoIP) | eq, in |
| Network (ASN) | The autonomous system number (GeoIP) | eq, in |
| Hosting provider network | Whether the address belongs to a hosting or cloud network (GeoIP) | eq |
| Host | The host in lower case, without the port | eq, in, ends_with, glob |
| Path | The path without the query, normalized | starts_with, eq, in, ends_with, contains, glob, regex |
| Raw path | The path exactly as received | contains, glob, regex |
| Method | GET, HEAD, POST, PUT, PATCH, DELETE or OPTIONS | eq, in |
| Query parameter | A parameter, named by a key | exists, not_exists, eq, contains, glob, regex |
| Header | A request header, named by a key (case-insensitive name) | exists, not_exists, eq, in, contains, glob, regex |
| Cookie | A cookie, named by a key | exists, not_exists, eq |
| User agent | The User-Agent header | contains, glob, regex |
| TLS fingerprint (JA4) | The JA4 fingerprint (HTTPS only) | eq, in |
| Bot class | human, search_engine, ai_crawler, ai_agent or unknown_bot | eq, in |
glob:*matches any run of characters, including/.regex: Rust syntax, which runs in linear time and has no look-around or back-references.- Case: hosts, methods, countries and the enumerated fields always compare without case. For free-text fields, set
case_insensitiveon the condition. - GeoIP: country, continent, ASN and hosting-provider conditions need the GeoIP database. Without it they never match.
- Spoofable headers: a client can set
X-Forwarded-For,X-Real-IP,Forwarded,CF-Connecting-IP,True-Client-IPandX-Client-IPto anything. Use the Client IP field to match an address. - The path is normalized: percent-escapes of unreserved characters are decoded, other escapes are upper-cased, and repeated slashes are collapsed. Use Raw path to test what was sent.
Actions
| Action | What it does |
|---|---|
block | Answers with an error. The status is 400–499, and the body is plain text of up to 1024 bytes (empty for a short default). |
allow | Stops evaluating edge rules and passes the request on. It does not bypass rate limits, Shield (including attack mode) or a password wall. |
challenge | Serves the proof-of-work challenge unless the visitor holds a clearance. The same challenge page as Shield, at 18 bits. A request that is not a page load gets 429 with Retry-After, and a page load over plain HTTP gets 426. It does not depend on the project's Shield mode. |
redirect | Redirects with status 301, 302, 307 or 308. The target is a path starting with / or an absolute http(s) URL with a fixed host. {path} inserts the visitor's normalized path and {query} the raw query string, for example https://docs.example.com{path}?{query}. |
log | Records the match and keeps evaluating. |
A redirect target is checked so a visitor cannot change where it goes: after a host there must be /, ?, # or {path}, and a path target cannot start with //, /\ or /{path}. Only {path} and {query} are allowed as placeholders, and a target is at most 2048 bytes.
Roll a rule out safely
Every rule has a mode: enforce acts on matches, and log only evaluates the rule and records the match but never acts.
- A new rule starts in log-only mode in the API, the CLI and the console's examples. Create it, watch the match count on the rules list, test it against sample requests, and only then switch it to enforce.
- Test a request first. The console's Test request sheet, the API and
temps edge-rules testrun a sample request against the saved rules and show the outcome for each rule: disabled, other environment, not reached, no match, logged, challenge passed or decided. - Rules are saved without drafts, so do the testing before enforcing.
The console offers four examples, each starting in log-only mode: block CMS and secret-file probes, restrict /admin to your office network, challenge traffic from hosting networks, and redirect /docs to a docs site.
Manage rules
In the console: open the project, then Settings, Security & access, Edge rules. The list shows each rule in order, whether it is Enforced or Log only, and its match count. Add a rule from scratch or from an example, move rules up and down to reorder them, and switch a rule between log only and enforce.
With the API (all paths under /api):
| Route | Purpose |
|---|---|
GET /projects/{project_id}/edge-rules | List the rules in order |
GET /projects/{project_id}/edge-rules/{rule_id} | Read one rule |
POST /projects/{project_id}/edge-rules | Create a rule: name (optional, up to 80 characters), enabled, mode (enforce or log_only, default log_only), environment_id (omit for all), expression, action and position |
PATCH /projects/{project_id}/edge-rules/{rule_id} | Change parts of a rule |
DELETE /projects/{project_id}/edge-rules/{rule_id} | Delete a rule |
PUT /projects/{project_id}/edge-rules/order | Set the order of the rules |
POST /projects/{project_id}/edge-rules/evaluate | Dry-run a sample request and get the trace |
# Block probes for secret files, in log-only mode first
curl -X POST "https://your-temps-instance.com/api/projects/{project_id}/edge-rules" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Block secret-file probes",
"mode": "log_only",
"expression": {
"combinator": "any",
"children": [
{"kind": "condition", "field": "path", "op": "glob", "values": ["/.env*"]},
{"kind": "condition", "field": "path", "op": "glob", "values": ["/.git*"]}
]
},
"action": {"type": "block", "status": 404}
}'
An invalid rule is refused with 400 and a list of issues, each attached to the condition that caused it. Changing a rule that someone else changed in the meantime returns 409 (Edge Rule Changed) with the current revision.
With the CLI (built from the source; every command takes --project-id):
| Command | What it does |
|---|---|
temps edge-rules list and get <rule-id> | Show the rules in evaluation order, or one rule |
create, update <rule-id>, delete <rule-id> | Change rules. create takes --name, --expression, --action, --environment-id, --mode, --disabled and --position, or a --file with the rule |
move <rule-id> --to <n> | Move a rule to a 1-based position |
enable, disable, enforce, log-only <rule-id> | Switch a rule on or off, or between enforce and log only |
test --url <url> | Dry-run a request, with --method, --header, --ip, --country, --continent, --asn, --user-agent, --bot-class, --environment-id and --cleared, against the saved rules or a --file |
export and apply --file <path> | Print the rules as a file, or apply a file of rules, with --dry-run to show the plan first |
Limits
| Limit | Value |
|---|---|
| Rules per project | 100 |
| Conditions per rule | 32 |
| Nesting depth of groups | 4 |
Values in an in list | 64 |
CIDR ranges in an in_cidr condition | 1000 |
| Length of one value | 256 bytes |
* wildcards in a glob | 8 |
regex conditions across a project | 32 |
Pattern conditions across a project (every regex and glob, plus case-insensitive starts_with, ends_with and contains) | 256 |
| Rule name | 80 characters |
| Block body | 1024 bytes |
| Redirect target | 2048 bytes |
A project that reaches 100 rules gets 409 (Edge Rule Limit Reached) when it adds another.
Permissions and audit
| Permission | What it allows |
|---|---|
edge_rules:read | List and read rules, and run a dry run |
edge_rules:write | Create, change, delete and reorder rules |
The Admin and User roles have both. The Platform Admin and Reader roles have edge_rules:read. Permissions are narrowed to the project. See Authorization.
These actions are recorded in the audit log: EDGE_RULE_CREATED, EDGE_RULE_UPDATED, EDGE_RULE_DELETED and EDGE_RULES_REORDERED.
Requests that an edge rule blocks, challenges or redirects are recorded in the request log with a routing status of edge_rule_blocked, edge_rule_challenged or edge_rule_redirected. Matches of log-only rules are counted on the rules list.