Using ast and whitelists to make python's eval() safe?

后端 未结 2 1683
醉话见心
醉话见心 2021-02-04 18:23

OK. I know the experts have spoken and you should not ever use python\'s eval() on untrusted data, ever. I\'m not smarter than the rest of the world, and s

相关标签:
2条回答
  • 2021-02-04 18:56

    Zope has a thing called RestrictedPython, you may want to check it, at least to validate your approach or possibly reuse their code. It is configurable and re-usable.

    Here's my other answer to a similar question.

    0 讨论(0)
  • 2021-02-04 19:10

    Try asteval, seems like the thing you need. Otherwise there is this safe eval

    0 讨论(0)
提交回复
热议问题