如何防止 V8 中的恶意 javascript(使用 Python) [英] How do I prevent malicious javascript in V8 (with Python)
本文介绍了如何防止 V8 中的恶意 javascript(使用 Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PyV8 运行不受信任的 javascript.如何检测和终止具有无限循环或长时间运行循环的 javascript?我想告诉 v8 运行 javascript,如果它没有在 0.1 秒内完成,则会因超时而失败.
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.
推荐答案
如果是python,可以使用Interrupting cow:
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
这篇关于如何防止 V8 中的恶意 javascript(使用 Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文