I am building a website where I have a need that user should be able to evaluate some expression based from the value in DB tables, instead of using tools like pyparsing etc
It's completely unsafe to use eval
, even with built-ins emptied and blocked -- the attacker can start with a literal, get its __class__
, etc, etc, up to object
, its __subclasses__
, and so forth... basically, Python introspection is just too strong to stand up to a skilled, determined attacker.
ast.literal_eval is safe, if you can live by its limitations...