mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Fix potential security issue(s), documentation on minetest.deserialize() (#9369)
Also adds an unittest
This commit is contained in:
parent
ef09e8a4d6
commit
8d6a0b917c
3 changed files with 39 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
_G.core = {}
|
||||
|
||||
_G.setfenv = function() end
|
||||
_G.setfenv = require 'busted.compatibility'.setfenv
|
||||
|
||||
dofile("builtin/common/serialize.lua")
|
||||
|
||||
|
@ -25,4 +25,20 @@ describe("serialize", function()
|
|||
local test_out = core.deserialize(core.serialize(test_in))
|
||||
assert.same(test_in, test_out)
|
||||
end)
|
||||
|
||||
it("strips functions in safe mode", function()
|
||||
local test_in = {
|
||||
func = function(a, b)
|
||||
error("test")
|
||||
end,
|
||||
foo = "bar"
|
||||
}
|
||||
|
||||
local str = core.serialize(test_in)
|
||||
assert.not_nil(str:find("loadstring"))
|
||||
|
||||
local test_out = core.deserialize(str, true)
|
||||
assert.is_nil(test_out.func)
|
||||
assert.equals(test_out.foo, "bar")
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue