Skip to content

Check for calls of functions susceptible to AST stack overflow #431

@naglis

Description

@naglis

Is your feature request related to a problem? Please describe.
It is possible to crash the Python interpreter by passing sufficiently large/complex string to ast.literal_eval, ast.parse, compile, dbm.dumb.open, eval or exec due to stack depth limitations in Python’s AST compiler.

My biggest issue is with ast.literal_eval which is recommended as a safe(r) alternative to eval by both the official documentation and bandit itself, so I suspect it is commonly[citation needed] used for parsing untrusted data where some evaluation is needed, instead of using eval, which might cause a false sense of security.

Describe the solution you'd like
Add the following functions to the calls blacklist:

  • ast.literal_eval
  • ast.parse
  • compile
  • dbm.dumb.open

Describe alternatives you've considered

Not sure about adding eval and exec as they are already covered by B307 and B102, respectively, and I'm not sure if duplicating them would make sense.

Additional context
References:

PR: #423

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions