Awesome Reviewers

Reviewer · Security

Harden security validation logic

Security-critical validation and filtering code (command blocklists, path sandboxing, input-size caps, parsing helpers) must be treated as adversarial surfaces, not ordinary logic, and verified from both directions:

Instruction

Security-critical validation and filtering code (command blocklists, path sandboxing, input-size caps, parsing helpers) must be treated as adversarial surfaces, not ordinary logic, and verified from both directions:

  1. Bypass coverage: for every pattern or regex meant to block a dangerous operation, add tests proving the exact escalation vector (wrappers, quoting, path prefixes, case, separators) is still blocked after the change. E.g. when anchoring a bare blocklist word like su with a word-boundary regex, explicitly test that su -, su root -c id, and echo hi; su remain blocked, and that wrapper forms (nice reboot, timeout 5 sudo id, sh -c 'sudo id') are also caught — don’t rely on an old substring check being “probably still equivalent”.
  2. False-positive coverage: equally test that the tightened pattern doesn’t reject legitimate input. A shared anchor can’t serve two conflicting needs (e.g. su must not match su-exec/su.sh, while mkfs must match mkfs.ext4) — give each word its own anchor when the boundary semantics differ, and record benign cases (grep -r sudo config/, nice -n 5 make) as regression tests.
  3. Regex performance: when alternatives in a repeated group overlap (e.g. \w+=\S*, -\S*, \d\S* can all match the same token), catastrophic backtracking is possible. Benchmark the matcher against adversarial input sized at the maximum allowed length before merging; prefer mutually-exclusive alternatives over bounding the quantifier, since a bound can itself be bypassed.
  4. Validate what you act on: when a check resolves a path (e.g. via os.path.realpath) to verify it stays inside a sandbox, use that same resolved value for the actual I/O, or explicitly document the TOCTOU window where a symlink swapped in after validation could escape it. Also normalize case (os.path.normcase) when comparing paths on case-insensitive filesystems to avoid false refusals.
  5. Scope limit changes deliberately: when relaxing a size/length cap or unifying a parsing helper used by multiple call sites, check whether the old behavior (e.g. unbounded ast.literal_eval, a 512-char cap) protected other callers in ways the new code no longer does, and either extend the fix everywhere or explicitly document/defer the gap rather than silently narrowing coverage for one call site while leaving others exposed.

Any change to blocklists, allowlists, sandboxes, or size limits should ship with explicit “still blocked” and “still allowed” test cases, not just the scenario that motivated the change.