Awesome Reviewers

Reviewer · Security

Consistent security validation

Security-sensitive checks (command blocklists/allowlists, path sandboxing, input parsing) must validate the exact value that will actually be used downstream, and all validation logic for the same check must apply identical normalization rules. Divergence between what is validated and what is executed, or between differently-normalized copies of the same...

Instruction

Security-sensitive checks (command blocklists/allowlists, path sandboxing, input parsing) must validate the exact value that will actually be used downstream, and all validation logic for the same check must apply identical normalization rules. Divergence between what is validated and what is executed, or between differently-normalized copies of the same input, creates bypasses or false refusals that are hard to spot in review.

Concretely:

  • When a function resolves/normalizes a value for a safety check (e.g. os.path.realpath() for a sandbox check), return/use that same resolved value for the actual operation rather than the original unresolved string, to avoid TOCTOU-style gaps where the checked path and the acted-upon path differ.
  • Normalize comparisons for the filesystem/environment you run on (e.g. os.path.normcase for case-insensitive filesystems) so the same legitimate input isn’t inconsistently accepted or refused.
  • If several checks in the same function operate on lowercased vs. raw strings, or with/without re.IGNORECASE, make all checks consistent (pick one canonical form) — don’t let one check see cmd_lower while a sibling check sees the raw string; such divergence is exactly how blocklist bypasses (SUDO id, mixed-case evasion) sneak through.
  • When centralizing or hardening a security control (e.g. a shared parsing helper used by multiple call sites), apply the same hardening (length caps, sanitization) uniformly across all call sites, or explicitly scope and document why a given site is treated differently — don’t silently leave some paths less protected than others.
  • Anchor/boundary logic in blocklists (regex word boundaries, prefixes) must be validated against both the “must block” and “must allow” cases with explicit tests; a single shared anchor can’t simultaneously satisfy words needing a strict boundary (su vs su-exec) and words needing a loose one (mkfs vs mkfs.ext4) — give such words per-pattern anchors instead of one shared regex tail.
  • Known, intentionally-out-of-scope bypass classes (e.g. command substitution $(...), obfuscated encodings, unlisted wrapper commands) must be explicitly called out in code comments or the PR description, with a tracking issue, rather than left as an implicit assumption.

Example pitfall to avoid:

# BAD: check validates `resolved`, but the operation still uses `full_path`
resolved = os.path.realpath(full_path)
if not resolved.startswith(workspace_root):
    raise WorkspaceEscapeError(...)
return full_path  # downstream I/O uses this, not `resolved`

# GOOD: validate and act on the same value, or clearly document the gap
resolved = os.path.realpath(full_path)
if not resolved.startswith(workspace_root):
    raise WorkspaceEscapeError(...)
return resolved