Skip to content

Commit 0754f5d

Browse files
committed
fix(command-injection): judge option values by what the option does
Review of the first version: a constant prefix refuted the value of an option that runs it (sh -c "echo $x", ssh -o ProxyCommand=..., find -exec), and ssh operands after the host, a remote shell command, were read as plain operands. A value an established option takes is now judged by what the option does with it, whatever its prefix: run it (high), keep it as data (git commit -m, gh --title: refuted), or an effect not established (medium); after an option the model does not describe, the finding stays for review. Operands a program runs as a command (ssh after the host, the program of sudo, env, xargs, timeout..., arguments of a batch file) are high. The option model also covers cmd /c and powershell -Command, shell flags grouped with -c, tar -I, the program given by a constant executable=, sys.executable, git.exe and python3.12; shell given at its position is read; -- counts anywhere before the input, and ssh is no longer taken to end its options there. Refs #208
1 parent 3a60f1e commit 0754f5d

3 files changed

Lines changed: 274 additions & 72 deletions

File tree

‎docs/usage.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ variable is not treated that way yet.
115115

116116
| Rule | Reached sink |
117117
|---|---|
118-
| `command-injection` | Shell or process execution (`os.system`, `subprocess` with a string, …), judged on what the input controls in the command. A string a shell runs, a string naming the program or the program itself is `high`. An element of an argument list run without a shell can only be read as an option: `medium`, or `high` when a documented option of the program runs a command it chooses (`git push --receive-pack=…`, `ssh -o ProxyCommand=…`, `sh -c`). A constant prefix that keeps the input from being an option (`f"v{version}"`), or an operand after `--` for a program that honours it, is refuted. A value after an option that may take one, where the program's options are not known, stays a hotspot to review. |
118+
| `command-injection` | Shell or process execution (`os.system`, `subprocess` with a string, …), judged on what the input controls in the command. A string a shell runs, a string naming the program, the program itself, or an operand the program runs as a command (after the host for `ssh`, the program of `sudo`, `env`, `xargs`, `timeout`…, any argument of a batch file) is `high`. Otherwise an element of an argument list run without a shell can only be read as an option: `medium`, or `high` when a documented option of the program runs a command it chooses (`git push --receive-pack=…`, `ssh -o ProxyCommand=…`). A value a documented option takes is judged by what the option does with it, whatever its prefix: run it (`sh -c`, `cmd /c`, `python -c`: `high`), keep it as data (`git commit -m`: refuted). After an option the rule does not know, the finding stays a hotspot to review. A constant prefix that keeps a standalone input from being an option (`f"v{version}"`), or an operand after `--` for a program that honours it, is refuted. |
119119
| `code-injection` | The code `eval` or `exec` runs; the globals and locals passed with it are data. `dangerous-eval` reports every such call, this rule the ones attacker input reaches. |
120120
| `sql-injection` | A database statement (`cursor.execute`, SQLAlchemy `text`, Django `raw`, …). Parameters of a parameterised query are not statements. |
121121
| `nosql-injection` | A NoSQL query, such as a MongoDB filter, given attacker input that may hold a structure: a JSON body giving `{"$ne": null}` matches any value. The input that may hold a structure is JSON, the raw bodies a `json.loads` decodes, files, WebSocket messages and standard input. Text cannot hold an operator: form fields, query parameters, headers, cookies, URL parameters, the command line, the environment, and an entry-point parameter annotated with scalars (`str`, `int`, `Optional[str]`, `Annotated[str, Query()]`, `list[str]`, …), which FastAPI validates. A Django, REST framework, aiohttp or tornado view reads a request object: its text attributes (`GET`, `POST`, `headers`, `query_params`, `query`, `match_info`, `arguments`, …) and the URL parameters after it are text, its body, files and `data` are not. Limits: a helper function the request is passed to reads it as a whole; the keys of a dict are not followed, so a string concatenated into `$where` is not reported. The analyzer ships no NoSQL sink: model plugins declare them. |

0 commit comments

Comments
 (0)