ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.12k stars 500 forks source link

Security issue: table "base" mirroring "_G" #1449

Open huwpascoe opened 1 year ago

huwpascoe commented 1 year ago

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
sagamusix commented 1 year ago

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);
HTV04 commented 1 year ago

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