How to securely load Lua scripts in subdirectories of mod?

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

How to securely load Lua scripts in subdirectories of mod?

by Wuzzy » Sat Nov 05, 2016 13:48

Hi!
I have trouble in getting .lua files to run if they are in a subdirectory of a mod.
When Mod Security is activated, Minetest does not allow me to load anything outside the mod directory. Not even subdirectories.
So, is there any way to load a script in a subdirectory without compromising mod security? I would hate to request an insecure environment or putting all Lua scripts in the top level.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: How to securely load Lua scripts in subdirectories of mo

by kaeza » Sun Nov 06, 2016 03:31

Can you paste your code?

I have tried a simple example, and found no issues:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- sub/sub.lua

print("SUB!")

-- init.lua

local MP = minetest.get_modpath("sectest")

print("Main before dofile") --> OK
dofile(MP.."/sub/sub.lua") --> OK
print("Main after dofile") --> OK

-- ERROR[Main]: Attempt to access external file
-- /home/user/foobar.lua with mod security on.
dofile("/home/user/foobar.lua")


Edit: Just in case:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
# git describe
0.4.14-272-g595932a
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: How to securely load Lua scripts in subdirectories of mo

by Wuzzy » Sun Nov 06, 2016 13:47

Oops, maybe it's because of using loadfile instead of dofile. Does loadfile have more restrictions than dofile?

PS: I am talking about the QA-Block mod [qa_block]. This mod currently breaks with enabled mod security, and I wanted to figure out what to do about it. This mod uses loadfile to load scripts from a subdirectory.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

bell07
Member
 
Posts: 140
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: How to securely load Lua scripts in subdirectories of mo

by bell07 » Mon Nov 07, 2016 07:33

The issue with qa_block was the files are readed at runtime and not in init-stage. Now I implement a compatibility mode with reading all files at init (and blow up the RAM). But what is the reason to restrict the usual runtime more then the init stage? I see no security win to be not allowed read something if I can read the same thing before in init stage?
 

bell07
Member
 
Posts: 140
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: How to securely load Lua scripts in subdirectories of mo

by bell07 » Wed Nov 09, 2016 12:26

Maybe my question was indiscernibly in the last post so I ask again: What is the reason to disallow reading of files in mod directory after the init stage? I do not see a security benefit on it.

I see to restrict "dofile" or "loadfile" does sense. The restriction prevents "hackers" to execute custom code during the server runs. But I see no reason to restrict just the reading trough io.open().

Maybe it make sense instead to disallow execution of loadstring() to get more security. Currently I can free type and execute typed code at runtime in qa_block in secured Minetest, but I cannot load the lua files as a text.

The pcall() should not be restricted. Is is just an other way to call already known (precompiled) functions.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 71 guests

cron