Is there a way to secure strings for Python's eval?

后端 未结 7 2067
悲哀的现实
悲哀的现实 2021-02-08 07:43

There are many questions on SO about using Python\'s eval on insecure strings (eg.: Security of Python\'s eval() on untrusted strings?, Python: make eval safe).

7条回答
  •  一生所求
    2021-02-08 07:58

    Assuming the named functions exist and are safe:

    if re.match("^(?:safe|soft|cotton|ball|[()])+$", code): eval(code)
    

提交回复
热议问题