The Greedy Regex — JavaScript Bug Hunt
Inspired by Cloudflare's 2019 global outage — a single greedy regex in the WAF pinned every CPU on the edge.
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Regex, Parsing
- Modelled on: Cloudflare · 2019
- Visible tests: the first assignment wins; value keeps everything after the first equals; tokens with invalid keys are skipped
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical)
- Ticket: BUG-WAF-711
- Reported by: edge team
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- the first assignment wins — expected {"key":"score","value":"5"} but got {"key":"score=5 action","value":"block"}
- value keeps everything after the first equals — expected {"key":"expr","value":"a==b"} but got {"key":"expr=a=","value":"b other"}
- tokens with invalid keys are skipped — expected {"key":"mode","value":"strict"} but got {"key":"9bad=1 mode","value":"strict"}
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by Cloudflare's 2019 global outage — a single greedy regex in the WAF pinned every CPU on the edge. Beyond the meltdown, greedy patterns are just wrong-answer machines.
ruleParser.js extracts the FIRST key=value token from a firewall rule line. The shipped pattern grabs the wrong things.
Bug report
BUG-WAF-711 · Priority: Critical · Reported by: edge team
extractAssignment(line) spec:
- scan whitespace-separated tokens; the first token containing "=" wins
- key = the part before the FIRST "=", value = everything after it
- keys are lowercase letters/underscores only, else keep scanning
- no such token -> null
Observed: on "score=5 action=block", the greedy pattern returns key "score=5 action" value "block".
Logs
[waf] parse("score=5 action=block") -> { key: "score=5 action", value: "block" }The code as shipped
src/waf/ruleParser.js (editable)
// Extracts the first key=value assignment from a rule line.
exports.extractAssignment = function (line) {
var m = line.match(/(.*)=(.*)/);
if (!m) return null;
return { key: m[1], value: m[2] };
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.