IFS and whitespace command injection bypass
An IFS command injection bypass lets an attacker run a multi-argument command even when the space character is filtered. Because the shell's internal field separator (IFS) defaults to space, tab and newline, constructs like `${IFS}` or `$IFS$9` reconstruct the separator the filter removed, so a command and its arguments still parse correctly.
How it works
Some naive filters block or strip the literal space to stop `cat /etc/passwd`. In Bourne-style shells, IFS (internal field separator) controls how the shell splits words, and it includes space, tab and newline by default. Expanding `${IFS}` yields a separator without typing a space.
`$IFS$9` is a common idiom: `$IFS` expands to the separator and `$9` is a positional parameter that is usually empty, so it acts as a delimiter between the variable name and the next token. A literal tab, a brace list `{cat,/etc/passwd}` (brace expansion inserts the comma as a separator), or input redirection `<` can serve the same purpose.
Representative payloads
Illustrative fragments for authorized testing. The injected marker commands (id, whoami) are harmless proofs of execution — swap in your engagement’s agreed markers.
cat${IFS}/etc/passwdLinux / Unix${IFS} supplies the field separator so cat receives /etc/passwd as a separate argument without a literal space.
cat$IFS$9/etc/passwdLinux / Unix$IFS$9 idiom: $9 (typically empty) terminates the variable name, leaving the separator intact.
{cat,/etc/passwd}Linux / UnixBrace expansion turns the comma into an argument separator — no spaces needed.
cat</etc/passwdLinux / UnixInput redirection reads the file into cat's stdin, avoiding a space-separated argument entirely.
When it works
- A filter blocks the literal space but not $, {, } or tab characters.
- Input reaches a Bourne-style shell that honours IFS and brace expansion (bash, sh, dash).
When it fails
- No shell is involved, so ${IFS} is passed as literal characters.
- An allowlist rejects $ and braces, or the value is constrained to a safe shape.
Detection
Flag ${IFS}, $IFS$9, brace-comma lists and redirection in inputs, and process command lines that reference IFS.
Signals to look for
- Parameters containing ${IFS}, $IFS, {cmd,arg} patterns, or stray tabs.
- Command lines in process telemetry that include IFS expansions.
- Space-free command strings that still invoke multi-argument utilities.
Where to look
Remediation
The correct fix: Run commands without a shell using an argv array; IFS and brace expansion are shell features and vanish when no shell parses the input.
Principles
- Shell-free execution makes ${IFS} and brace tricks inert literal text.
- Do not rely on blocking spaces — there are many ways to separate arguments.
- Validate inputs to an allowlist where the value has a known shape.
Safe APIs by runtime
execFile/spawn with an args array (no shell).
execFile("cat", [safePath]);subprocess.run([...], shell=False).
subprocess.run(["cat", safe_path])Not a fix: Filtering the space character. ${IFS}, $IFS$9, tabs, braces and redirection all reconstruct word splitting without a literal space.
For the full secure-coding matrix across languages, see the command injection prevention guide.