gpt4 book ai didi

ruby - 为什么在沙盒代码时我在第 4 级得到 "Insecure operation ‘write’?

转载 作者:太空宇宙 更新时间:2023-11-03 16:11:36 25 4
gpt4 key购买 nike

我有以下 Ruby 代码:

测试用例.rb:

filename = "/absolute/path/to/Untrusted.rb"
thread = Thread.new do
$SAFE = 4
Kernel::load(filename, true)
end
thread.join

不可信.rb

#Untrusted code
puts "Untrusted!"

但是,当我尝试运行 Testcase.rb 时出现错误:

/Volumes/Data/Users/mike/Desktop/Testcase.rb:4:in `write': Insecure operation `write' at level 4 (SecurityError)
from /Volumes/Data/Users/mike/Desktop/Testcase.rb:7:in `join'
from /Volumes/Data/Users/mike/Desktop/Testcase.rb:7

删除 $SAFE=4 解决了这个问题,但我希望能够安全地运行不受信任的代码。关于为什么这不起作用的任何想法?

最佳答案

我试过你的代码,得到了和你一样的结果。然后我将 $SAFE 级别更改为 3,并收到此警告:

Insecure world writable dir /tmp in LOAD_PATH, mode 041777

我将正在加载的文件从/tmp 移动到一个不可写入的目录,然后警告消失了。然后将 $SAFE 级别更改为 4。

因此,请尝试确保加载文件的目录不是全局可写的。还可以尝试较低的安全级别,看看是否会收到有用的警告。

关于ruby - 为什么在沙盒代码时我在第 4 级得到 "Insecure operation ‘write’?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2381199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com