sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

Security issue: table "base" mirroring "_G"

Open huwpascoe opened this issue 2 years ago • 2 comments

Using

sol::state lua;
lua.open_libraries(sol::lib::base);

creates a mirror of _G at top level called "base". which is undocumented AFAIK.

print(base == _G)

true

huwpascoe avatar Jan 31 '23 14:01 huwpascoe

While I don't quite see the security issue here, it would definitely make more sense to call luaL_requiref(L, "_G", luaopen_base, 1); instead of luaL_requiref(L, "base", luaopen_base, 1); for sol::lib::base.

Or even better, just use the constants provided by Lua itself, although I don't know how well that works for compatibility with older Lua version / LuaJIT / etc:

luaL_requiref(L, LUA_GNAME, luaopen_base, 1);
luaL_requiref(L, LUA_COLIBNAME, luaopen_coroutine, 1);
luaL_requiref(L, LUA_TABLIBNAME, luaopen_table, 1);
luaL_requiref(L, LUA_IOLIBNAME, luaopen_io, 1);
luaL_requiref(L, LUA_OSLIBNAME, luaopen_os, 1);
luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1);
luaL_requiref(L, LUA_MATHLIBNAME, luaopen_math, 1);
luaL_requiref(L, LUA_UTF8LIBNAME, luaopen_utf8, 1);
luaL_requiref(L, LUA_DBLIBNAME, luaopen_debug, 1);

sagamusix avatar Feb 02 '23 19:02 sagamusix

Bumping this issue, why is a base table created? Shouldn't it just go to _G like in linit.c?

htv04 avatar Feb 16 '23 02:02 htv04