Skip to content

no-eval

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.

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.

Reported
...
Write-Output "ok"
Get-Help Write-Host
iex $script
Invoke-Expression -Command $c
...
ConvertTo-SecureString $p
...
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.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
psscriptanalyzer PSAvoidUsingInvokeExpression full
ruff S102 full