Skip to content

Files

Latest commit

 

History

History
26 lines (16 loc) · 915 Bytes

B307.md

File metadata and controls

26 lines (16 loc) · 915 Bytes

Pattern: Avoid using eval() when possible

Issue: -

Description

Used when you use the eval() function, to discourage its usage. It's usage may have negative readability, performance and security implications, especially if you accept strings from untrusted or unknown sources. Consider using ast.literal_eval() for safely evaluating strings containing expressions from untrusted sources.

Example of insecure code:

eval('os.listdir(".")')

Example of secure code:

ast.literal_eval('os.listdir(".")')

Further Reading