Pcornel
Automation · Scripting

Input Validation

Cheat sheet · https://pcornel.dk/topic.php?topic=5220

Back to the Topic

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

BoundaryHealthy evidenceSuspicious evidence
Input / runtimeEffective inputs, runtime, working context and dependency versions are explicitHidden defaults, stale environment, wrong interpreter/path or unvalidated input
Logic / executionBranch/function/module decisions and external actions expose per-operation resultsSwallowed failures, shell reinterpretation, blind retries or last-result-wins behavior
Result / proofExit/exception/log evidence is correlated with independent target read-backProcess success or printed output treated as target success
Recovery / troubleshootingFirst failed boundary is preserved, changed minimally and retestedRandom 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

Confirmation

Confirm action

Continue?