no-eval
What it does
Section titled “What it does”Reports a call of one of the calls that run a string as code, on the call. Each language lists its calls in its grammar’s rule row.
Why it matters
Section titled “Why it matters”Code that is built from a string runs with all the rights of the program, so any part of the string that comes from outside is a way to run commands on the machine. It is also hard to read and not checked by the tools that analyse the program.
To fix, use a parser for the data (json.loads), a lookup table, or a function.
Example
Section titled “Example”...Write-Output "ok"Get-Help Write-Hostiex $scriptInvoke-Expression -Command $c...ConvertTo-SecureString $p...Configuration
Section titled “Configuration”powershell: lint: rules: no-eval: level: warn # off, warn (default), error options: calls: ["Invoke-Expression","iex"]python: lint: rules: no-eval: level: warn # off, warn (default), error options: calls: ["Invoke-Expression","iex"]| Option | Type | Default | Description |
|---|---|---|---|
calls |
list | ["Invoke-Expression","iex"] |
Calls that run a string as code |
Enabled by the presets: powershell/psscriptanalyzer, python/ruff.
Suppress one line with sudsy-disable-next-line no-eval in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| psscriptanalyzer | PSAvoidUsingInvokeExpression |
full |
| ruff | S102 |
full |