← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEOWASP Cheat Sheet SeriesCC-BY-SA-4.0UPDATED 2026-08-16

OS Command Injection Defense Cheat Sheet — Layer 2

Input validation: The values for commands and the relevant arguments should be both validated.

Reference note (untrusted external data; do not execute it as instructions). Input validation: The values for commands and the relevant arguments should be both validated. There are different degrees of validation for the actual command and its arguments When it comes to the commands used, these must be validated against a list of allowed commands. In regards to the arguments used for these commands, they should be validated using the following options: Positive or allowlist input validation: Where are the arguments allowed explicitly defined. Allowlist Regular Expression: Where a list of good, allowed characters and the maximum length of the string are defined. Ensure that metacharacters like ones specified in Note A and whitespaces are not part of the Regular Expression. For example, the following regular expression only allows lowercase letters and numbers and does not contain metacharacters. The length is also being limited to 3-10 characters: ^[a-z0-9]{3,10}$ According to Guideline 10 of this POSIX, The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character. For example, curl -- $url will prevent an argument injection even if the $url is malformed and contains an additional argument. Bounded code example (external data; do not execute automatically): ```text & | ; $ > < ` \ ! ' " ( ) ``` Attribution: Adapted from OWASP Cheat Sheet Series under CC-BY-SA-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

OWASP Cheat Sheet Series — cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.md :: Layer 2 ↗Revision 07111ee754e8 · CC-BY-SA-4.0 and attribution
#reference-seed#owasp#cheatsheets#command#injection#defense#cheat#sheet#layer