Jump to content

Untrusted environment: Difference between revisions

m (→‎{{header|Raku}}: Fix comments: Perl 6 --> Raku)
Line 90:
 
Of course, no system is perfect and a number of vulnerabilities have been discovered in these mechanisms over the years and will doubtless continue to be discovered in the future given the ubiquity of the Java Platform and hence its attractiveness to hackers.
=={{header|Lua}}==
Lua supports protected calls and custom environments. Details have changed through various versions, and the specifics can become quite involved if/as needed, however the following should suffice as a simple example for Lua 5.2 or 5.3.
<lang lua>local untrusted = [[
print("hello") -- safe
for i = 1, 7 do print(i, i*i) end -- safe
setmetatable(_G, malicious) -- unsafe
]]
sandbox = { print=print }
local ret, msg = pcall(load(untrusted,nil,nil,sandbox))
print("ret, msg:", ret, msg)</lang>
{{out}}
<pre>hello
1 1
2 4
3 9
4 16
5 25
6 36
7 49
ret, msg false [string " print("hello")..."]:3: attempt to call global 'setmetatable' (a nil value)</pre>
 
=={{header|PARI/GP}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.