Reviewer · Security
Security validation consistency
When writing security-sensitive validation logic (command blocklists, path sandboxing, input sanitizers), treat it as an adversarial surface: both false negatives (bypasses) and false positives (blocking legitimate use) are bugs, and each change must be backed by tests for both directions.
When writing security-sensitive validation logic (command blocklists, path sandboxing, input sanitizers), treat it as an adversarial surface: both false negatives (bypasses) and false positives (blocking legitimate use) are bugs, and each change must be backed by tests for both directions.
Concretely:
- Normalize consistently. If one check lowercases or case-folds its input, every other check in the same validation path must use the same normalization (or document why it diverges). Mixing
cmd_lowerwith rawcommand, or mixingstr.lower()withre.IGNORECASE, creates silent gaps between checks that are easy to miss in review. - Validate the value you actually use. Don’t compute a safety decision on one representation (e.g.
os.path.realpath()) and then perform the operation on a different, unresolved one (e.g. the original path string) — that reopens the exact vulnerability the check was meant to close (TOCTOU). If full resolution isn’t feasible, document the residual window explicitly. - Anchor patterns precisely, per-token. A shared boundary/anchor (e.g. a trailing
\b) that works for one blocked token can silently fail for another (suvssu-execvsmkfs.ext4). Give each pattern its own anchor when their surrounding-character requirements differ, and add regression tests for the specific boundary characters (-,.,_) that previously caused confusion. - When narrowing a blocklist to reduce false positives (e.g. replacing blunt substring matches with anchored regexes), re-verify you haven’t reopened known attack vectors (wrapper commands like
nice,timeout,sh -c,env,xargs, command substitution$(...), quoting/escaping). Add explicit “still blocked” tests for every case the old implementation caught, not just “no longer false-positives” tests for the new one. - Make validation failures self-describing. Error messages should name the specific pattern/word/path that triggered the rejection so callers (including LLM agents) can self-correct, and so reviewers can tell which rule fired.
Example of the anchoring pitfall to avoid:
# BAD: one shared \b cannot satisfy both requirements
WORDS = ("su", "mkfs")
REGEX = re.compile(r"\b(?:su|mkfs)\b") # blocks su-exec; misses mkfs.ext4 intent
# GOOD: anchor per-word based on actual boundary semantics
WORDS = (r"su(?![\w.-])", r"mkfs") # su-exec/su.sh allowed, mkfs.ext4 still blocked
Every security-relevant validator should ship with a test matrix covering: (a) the exact bypasses it was added to fix, (b) the legitimate inputs it must not block, and (c) known evasion techniques (wrappers, quoting, case variants, symlinks, path casing) relevant to that validator’s domain.</description>