not (…)doesn't match a missing header, so a negated block rule fails open
3 hours ago
What happened
I use an edge rule as an origin lock: block every request that doesn't carry a secret header my CDN adds. I wrote it the obvious way:
{
"priority": 10,
"if": {
"and": [
{ "not": { "attr": "http.header", "key": "x-origin-auth", "op": "eq", "value": "<secret>" } },
{ "not": { "attr": "ipv4.src", "op": "in", "value": ["<allowed-ipv4>"] } }
]
},
"then": { "action": "block", "params": { "status": 403 } }
}Testing from an IP that isn't allowed, sending the request straight to Railway's edge (curl --resolve <domain>:443:<railway-edge-ip> https://<domain>/):
- Wrong header value:
403, as expected. - No header at all:
200. The request reached my service (server: railway-hikari, and the service's HTTP logs show it with the test IP as the source).
So the rule blocked a guessed secret but let through the most common case an origin lock exists for: a request that doesn't send the header at all.
The docs say a negative comparison against a missing header doesn't match. I read that as applying to neq, and expected not (eq) to match, because eq doesn't match and not flips it. The edge behaves as if a comparison against a missing header is "unknown" and not keeps it that way.
What fixed it
Allow the known cases, then block everything:
[
{ "priority": 10, "if": { "attr": "http.header", "key": "x-origin-auth", "op": "eq", "value": "<secret>" }, "then": { "action": "allow" } },
{ "priority": 20, "if": { "attr": "ipv4.src", "op": "in", "value": ["<allowed-ipv4>"] }, "then": { "action": "allow" } },
{ "priority": 30, "if": { "attr": "http.path", "op": "matches", "value": "/*" }, "then": { "action": "block", "params": { "status": 403 } } }
]After applying it: no header gives 403, wrong header gives 403, through the CDN gives 200. This also covers IPv6 clients, which have no IPv4 source to compare.
Suggestions
- Document how
nottreats a missing header or IPv4 source, next to the existing note on negative comparisons. A security rule that fails open is easy to miss: my rule looked right in the dashboard and my own tests passed. - Show the "allow, then block everything" pattern for origin locks (the common "only accept traffic from my CDN" setup) in the edge rules docs.
- Make rule hits visible. The 403s from the fixed rule don't appear in the service's HTTP logs, only requests that reached the service do, so I could only find the gap by testing from outside. Even a count per rule would help.
I haven't tested or or nested groups with missing attributes, so the "unknown" explanation is my reading of the two results above.
I wrote this post with help from an AI assistant (Claude). I ran the tests and checked the results myself.
0 Threads mention this feature
0 Replies