From cbeb5e1a7adbede58826887df5a7d31d6f3a0536 Mon Sep 17 00:00:00 2001
From: garret <garret@airmail.cc>
Date: Thu, 16 Feb 2023 23:34:19 +0000
Subject: provide actual sandboxed environments

doesn't work with file:stuff, hopefully no one will notice lol
---
 make-feed.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/make-feed.lua b/make-feed.lua
index bf286d2..370c6a7 100755
--- a/make-feed.lua
+++ b/make-feed.lua
@@ -231,9 +231,48 @@ end
 
 local function run_file(file, extension)
 	local runner
-	local env = deepcopy(_G) -- i dont care
-	env.require = sandbox_require
-	-- TODO: care
+	local env = {
+	_VERSION = _VERSION,
+	assert = assert,
+	collectgarbage = collectgarbage,
+	dofile = dofile,
+	error = error,
+	getfenv = getfenv,
+	getmetatable = getmetatable,
+	ipairs = ipairs,
+	load = load,
+	loadfile = loadfile,
+	loadstring = loadstring,
+	module = module,
+	next = next,
+	pairs = pairs,
+	pcall = pcall,
+	print = print,
+	rawequal = rawequal,
+	rawget = rawget,
+	rawset = rawset,
+	select = select,
+	setfenv = setfenv,
+	setmetatable = setmetatable,
+	tonumber = tonumber,
+	tostring = tostring,
+	type = type,
+	unpack = unpack,
+	xpcall = xpcall,
+	coroutine = coroutine,
+	debug = debug,
+	file = file,
+	io = io,
+	math = math,
+	os = os,
+	package = {},
+	string = string,
+	table = table,
+	
+	require = sandbox_require,
+	aegisub = fake_aegisub(),
+	_feedmaker_version = {}
+	}
 
 	if extension == "moon" then
 		runner = moonscript.loadfile(file)
@@ -267,7 +306,12 @@ local function get_macro_metadata(file)
 	meta.namespace = macro.script_namespace
 	meta.changelog = macro.script_changelog
 	meta.depctrl = macro.__feedmaker_version
-	
+
+	if not meta.namespace then
+		err(file .. ": no script_namespace, skipping")
+		return nil
+	end
+
 	if config.macros.ignoreCondition(meta) then
 		err(file .. ": ignored by config, skipping")
 		return nil
-- 
cgit v1.2.3-70-g09d2