Agent Wranglers

Injection Required

Never pass input to a shell

Run other programs without a shell, with input as separate arguments. Better still, use a library instead of a program.

How to do it

Call the program directly with an argument list, such as execFile in Node or subprocess.run([...]) in Python. Check input against an allow list, such as a known file name pattern. Put -- before user values, so they cannot pass as options.

Example

// Bad: the shell reads ; and $( )
exec(`gzip --keep ${fileName}`);
// Good: no shell, input is one argument, and -- ends the options
execFile('gzip', ['--keep', '--', fileName]);

How to check

Send AW-TEST; sleep 5 and $(sleep 5) wherever input might reach a program, such as file names and image tools. Replies come back at normal speed.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers security testing playbook: https://agentwranglers.se/playbook/adversarial-testing/injection/command-injection.