Warm tip: This article is reproduced from stackoverflow.com, please click
python eval code-injection

Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')

发布于 2020-03-27 10:27:09

Why am I receiving an eval injection error?

 if len(sys.argv) > 1:
   eval(sys.argv[1])(logger, *sys.argv[2:])
Questioner
Maryam7
Viewed
35
shaik moeed 2019-07-03 23:09

Use ast.literal_eval instead of eval.

Code:

from ast import literal_eval as eval
if len(sys.argv) > 1:
     eval(sys.argv[1])(logger, *sys.argv[2:])

Eval is dangerous