|
1 | 1 | local sandbox = {
|
2 |
| - _VERSION = "kong-lua-sandbox 1.0", |
| 2 | + _VERSION = "kong-lua-sandbox 1.1", |
3 | 3 | _DESCRIPTION = "A pure-lua solution for running untrusted Lua code.",
|
4 | 4 | _URL = "https://github.com/kong/kong-lua-sandbox",
|
5 | 5 | _LICENSE = [[
|
@@ -43,7 +43,6 @@ local BASE_ENV = {}
|
43 | 43 |
|
44 | 44 | -- List of unsafe packages/functions:
|
45 | 45 | --
|
46 |
| --- * string.rep: can be used to allocate millions of bytes in 1 operation |
47 | 46 | -- * {set|get}metatable: can be used to modify the metatable of global objects (strings, integers)
|
48 | 47 | -- * collectgarbage: can affect performance of other systems
|
49 | 48 | -- * dofile: can access the server filesystem
|
@@ -74,8 +73,8 @@ math.sin math.sinh math.sqrt math.tan math.tanh
|
74 | 73 | os.clock os.difftime os.time
|
75 | 74 |
|
76 | 75 | string.byte string.char string.find string.format string.gmatch
|
77 |
| -string.gsub string.len string.lower string.match string.reverse |
78 |
| -string.sub string.upper |
| 76 | +string.gsub string.len string.lower string.match string.rep |
| 77 | +string.reverse string.sub string.upper |
79 | 78 |
|
80 | 79 | table.insert table.maxn table.remove table.sort
|
81 | 80 |
|
@@ -104,16 +103,13 @@ end)
|
104 | 103 |
|
105 | 104 | -- auxiliary functions/variables
|
106 | 105 |
|
107 |
| -local string_rep = string.rep |
108 |
| - |
109 | 106 | local function sethook(f, key, quota)
|
110 | 107 | if type(debug) ~= 'table' or type(debug.sethook) ~= 'function' then return end
|
111 | 108 | debug.sethook(f, key, quota)
|
112 | 109 | end
|
113 | 110 |
|
114 | 111 | local function cleanup()
|
115 | 112 | sethook()
|
116 |
| - string.rep = string_rep -- luacheck: no global |
117 | 113 | end
|
118 | 114 |
|
119 | 115 | -- Public interface: sandbox.protect
|
@@ -161,8 +157,6 @@ function sandbox.protect(code, options)
|
161 | 157 | sethook(timeout, "", quota)
|
162 | 158 | end
|
163 | 159 |
|
164 |
| - string.rep = nil -- luacheck: no global |
165 |
| - |
166 | 160 | local t = table.pack(pcall(f, ...))
|
167 | 161 |
|
168 | 162 | cleanup()
|
|
0 commit comments