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 log actions record a match and keep evaluating, so a later rule can still decide.
  • A challenge rule is skipped for a visitor who already holds a clearance, and evaluation continues with the next rule.
  • An allow rule 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. A none group 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.

FieldMatchesOperators
Client IPThe client address, resolved through trusted proxiesin_cidr
CountryTwo-letter ISO country code (GeoIP)eq, in
ContinentAF, AN, AS, EU, NA, OC or SA (GeoIP)eq, in
Network (ASN)The autonomous system number (GeoIP)eq, in
Hosting provider networkWhether the address belongs to a hosting or cloud network (GeoIP)eq
HostThe host in lower case, without the porteq, in, ends_with, glob
PathThe path without the query, normalizedstarts_with, eq, in, ends_with, contains, glob, regex
Raw pathThe path exactly as receivedcontains, glob, regex
MethodGET, HEAD, POST, PUT, PATCH, DELETE or OPTIONSeq, in
Query parameterA parameter, named by a keyexists, not_exists, eq, contains, glob, regex
HeaderA request header, named by a key (case-insensitive name)exists, not_exists, eq, in, contains, glob, regex
CookieA cookie, named by a keyexists, not_exists, eq
User agentThe User-Agent headercontains, glob, regex
TLS fingerprint (JA4)The JA4 fingerprint (HTTPS only)eq, in
Bot classhuman, search_engine, ai_crawler, ai_agent or unknown_boteq, 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_insensitive on 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-IP and X-Client-IP to 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

ActionWhat it does
blockAnswers with an error. The status is 400–499, and the body is plain text of up to 1024 bytes (empty for a short default).
allowStops evaluating edge rules and passes the request on. It does not bypass rate limits, Shield (including attack mode) or a password wall.
challengeServes 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.
redirectRedirects 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}.
logRecords 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 test run 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):

RoutePurpose
GET /projects/{project_id}/edge-rulesList the rules in order
GET /projects/{project_id}/edge-rules/{rule_id}Read one rule
POST /projects/{project_id}/edge-rulesCreate 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/orderSet the order of the rules
POST /projects/{project_id}/edge-rules/evaluateDry-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):

CommandWhat 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

LimitValue
Rules per project100
Conditions per rule32
Nesting depth of groups4
Values in an in list64
CIDR ranges in an in_cidr condition1000
Length of one value256 bytes
* wildcards in a glob8
regex conditions across a project32
Pattern conditions across a project (every regex and glob, plus case-insensitive starts_with, ends_with and contains)256
Rule name80 characters
Block body1024 bytes
Redirect target2048 bytes

A project that reaches 100 rules gets 409 (Edge Rule Limit Reached) when it adds another.


Permissions and audit

PermissionWhat it allows
edge_rules:readList and read rules, and run a dry run
edge_rules:writeCreate, 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.

Last updated

Was this page helpful?