A string is run as code with eval, Function or a timer

tx0/ts:eval-like-callrecommendedwarningsecurity, cwe-95

What it finds

eval(code), new Function("a", body), setTimeout("refresh()", 100): these run a string as code. Whoever controls any part of the string controls what runs, with all the rights of the program, and the code cannot be checked, optimized or bundled ahead.

Reported are calls of the global eval, Function with or without new, and setTimeout and setInterval whose first argument is a string or template rather than a function. Strings that are literals without substitutions are reported too, since they are better written as code.

From the rule's source, eval_like_call.rs.

Example from the rule's tests
function run(code: string, name: string) {  eval(code);tx0 reports: eval runs a string as code  const f = new Function("a", code);tx0 reports: Function builds a function from strings of code  setTimeout(`refresh("${name}")`, 100);tx0 reports: a timer given a string runs it as code  setTimeout(() => f(name), 100);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:eval-like-call" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:eval-like-call] reason="..."

tx0 explain tx0/ts:eval-like-call shows the same in the terminal. Found a false positive? Report it.