如何防止V8中的恶意javascript(使用Python)

时间:2012-07-24 18:29:46

标签: javascript python v8

我正在使用PyV8来运行不受信任的javascript。如何检测并杀死其中包含无限或长时间循环的javascript?我想告诉v8运行javascript并在超时时失败,如果它没有在0.1秒内完成。

1 个答案:

答案 0 :(得分:3)

如果是python,你可以使用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

相关问题