Input Validation
Cheat sheet · https://pcornel.dk/topic.php?topic=5220
Answer
Input validation checks that data is in the expected format, type and range before a script or service uses it, and rejects anything else. It prevents errors and injection, but it does not replace authorisation or safe command construction.
Remember
- Input validation ≠ authorization; a well-formed target name can still be outside the caller's allowed scope.
- Validation ≠ sanitization automatically; rewriting hostile input can create a different valid but unintended value.
- Regex match ≠ semantic validity; dates, IPs, paths and identifiers may require parser or target-aware checks.
- Escaping one shell ≠ safe execution everywhere; command construction and API parameterization are separate boundaries.
First checks
- Regex/allowlist validation — format
[ValidateSet()]/[ValidatePattern()] in PowerShell— built-in validation- Reject and exit non-zero on invalid input — safety
Verify in this order
input → validation → accept/reject
Where it usually breaks
Passing validation proves only that input meets the implemented validation contract; it does not prove authorization, business intent or safety of the downstream execution mechanism.
Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.
Input Validation scripting boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Input / runtime | Effective inputs, runtime, working context and dependency versions are explicit | Hidden defaults, stale environment, wrong interpreter/path or unvalidated input |
| Logic / execution | Branch/function/module decisions and external actions expose per-operation results | Swallowed failures, shell reinterpretation, blind retries or last-result-wins behavior |
| Result / proof | Exit/exception/log evidence is correlated with independent target read-back | Process success or printed output treated as target success |
| Recovery / troubleshooting | First failed boundary is preserved, changed minimally and retested | Random edits, catch-all suppression or evidence destroyed before diagnosis |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5220