How do I prevent malicious javascript in V8 (with Python)

我的梦境 提交于 2019-12-11 01:17:45

问题


I'm using PyV8 to run untrusted javascript. How can I detect and kill javascript that has inifinite, or long running loops in it? I'd like to tell v8 to run javascript and fail with a timeout if it's not finished in 0.1 of a second.


回答1:


if it's python, you can use Interrupting cow:

from interruptingcow import timeout

try:
    with timeout(5, exception=RuntimeError):
        # perform a potentially very slow operation
        pass
except RuntimeError:
    print "didn't finish within 5 seconds"

https://bitbucket.org/evzijst/interruptingcow



来源:https://stackoverflow.com/questions/11637075/how-do-i-prevent-malicious-javascript-in-v8-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!