Jump to content

Recommended Posts

My mod ([Hk]Config++ @ https://steamcommunity.com/sharedfiles/filedetails/?id=655377781 ) uses Lua to write files with configuration to filesystem, in order to persist settings across world resets on dedicated servers. This allowed me, for example, to store player ranks, locations, invites.

Recent security improvement (I hope!) appear to prevent that entirely by disabling successful use of io.open - example:


local file = io.open("hk_config_rwtest", "w")
if file and file ~= false then
    file:close()
end

local file_check = io.open("hk_config_rwtest", "rb")
if file_check == nil then
    log_d("hk_config.debug: failed to create a test file")
else
    file:close()

    local file_write_check = io.open("hk_config_rwtest", "w")
    if file_write_check ~= nil then
        file_write_check:write("test sentence\n")
        file_write_check:close()

        local file_readback_check = io.open("hk_config_rwtest", "rb")
        if file_readback_check ~= nil then
            for line in old_file:lines() do
                local fixed_line = line:gsub("\r", "")
                print(fixed_line)
            end
            file_readback_check:close()
        end
    end
end

leads to

[00:00:37]: KU_z0_G74kc	running text command:	hk_file	true	
[00:00:37]: 2025-05-15 23:19:48 Local time (UTC+2) [Hk]Config++ Debug: hk_config.debug: trying to create test file	
[00:00:37]: [string "../mods/workshop-960342576/init/commands.lu..."]:1512: invalid filepath
LUA ERROR stack traceback:
=[C]:-1 in (field) open (C) <-1--1>
../mods/workshop-960342576/init/commands.lua:1512 in (upvalue) fn (Lua) <1510-1546>
   player = 116295 - wortox (valid:true)
../mods/workshop-960342576/init/commands.lua:1762 in (field) fn (Lua) <1760-1764>
   _ = table: 0x7f47f82646f0
   caller = 116295 - wortox (valid:true)
scripts/usercommands.lua:41 in (global) HandleUserCmdQueue (Lua) <38-48>
   _ = 1
   cmd = table: 0x3cbe0cd0
scripts/update.lua:45 in () ? (Lua) <33-138>
   dt = 0.016726575791836
   server_paused = false

[00:00:37]: [string "../mods/workshop-960342576/init/commands.lu..."]:1512: invalid filepath
LUA ERROR stack traceback:
    =[C]:-1 in (field) open (C) <-1--1>
    ../mods/workshop-960342576/init/commands.lua:1512 in (upvalue) fn (Lua) <1510-1546>
    ../mods/workshop-960342576/init/commands.lua:1762 in (field) fn (Lua) <1760-1764>
    scripts/usercommands.lua:41 in (global) HandleUserCmdQueue (Lua) <38-48>
    scripts/update.lua:45 in () ? (Lua) <33-138>

(example uses https://steamcommunity.com/sharedfiles/filedetails/?id=960342576 with default options, debug execution can be issued by admin for example with /check command)

 

My question is, how to do it proper? If writes to arbitrary files are now off-limits, how could I at least store data in world save? This would let me add export/import commands, I suppose... although ability to store list of trusted players on server (that survives world reset) would be great!

6 hours ago, Hekkaryk said:

My mod ([Hk]Config++ @ https://steamcommunity.com/sharedfiles/filedetails/?id=655377781 ) uses Lua to write files with configuration to filesystem, in order to persist settings across world resets on dedicated servers. This allowed me, for example, to store player ranks, locations, invites.

Recent security improvement (I hope!) appear to prevent that entirely by disabling successful use of io.open - example:


local file = io.open("hk_config_rwtest", "w")
if file and file ~= false then
    file:close()
end

local file_check = io.open("hk_config_rwtest", "rb")
if file_check == nil then
    log_d("hk_config.debug: failed to create a test file")
else
    file:close()

    local file_write_check = io.open("hk_config_rwtest", "w")
    if file_write_check ~= nil then
        file_write_check:write("test sentence\n")
        file_write_check:close()

        local file_readback_check = io.open("hk_config_rwtest", "rb")
        if file_readback_check ~= nil then
            for line in old_file:lines() do
                local fixed_line = line:gsub("\r", "")
                print(fixed_line)
            end
            file_readback_check:close()
        end
    end
end

leads to

[00:00:37]: KU_z0_G74kc	running text command:	hk_file	true	
[00:00:37]: 2025-05-15 23:19:48 Local time (UTC+2) [Hk]Config++ Debug: hk_config.debug: trying to create test file	
[00:00:37]: [string "../mods/workshop-960342576/init/commands.lu..."]:1512: invalid filepath
LUA ERROR stack traceback:
=[C]:-1 in (field) open (C) <-1--1>
../mods/workshop-960342576/init/commands.lua:1512 in (upvalue) fn (Lua) <1510-1546>
   player = 116295 - wortox (valid:true)
../mods/workshop-960342576/init/commands.lua:1762 in (field) fn (Lua) <1760-1764>
   _ = table: 0x7f47f82646f0
   caller = 116295 - wortox (valid:true)
scripts/usercommands.lua:41 in (global) HandleUserCmdQueue (Lua) <38-48>
   _ = 1
   cmd = table: 0x3cbe0cd0
scripts/update.lua:45 in () ? (Lua) <33-138>
   dt = 0.016726575791836
   server_paused = false

[00:00:37]: [string "../mods/workshop-960342576/init/commands.lu..."]:1512: invalid filepath
LUA ERROR stack traceback:
    =[C]:-1 in (field) open (C) <-1--1>
    ../mods/workshop-960342576/init/commands.lua:1512 in (upvalue) fn (Lua) <1510-1546>
    ../mods/workshop-960342576/init/commands.lua:1762 in (field) fn (Lua) <1760-1764>
    scripts/usercommands.lua:41 in (global) HandleUserCmdQueue (Lua) <38-48>
    scripts/update.lua:45 in () ? (Lua) <33-138>

(example uses https://steamcommunity.com/sharedfiles/filedetails/?id=960342576 with default options, debug execution can be issued by admin for example with /check command)

 

My question is, how to do it proper? If writes to arbitrary files are now off-limits, how could I at least store data in world save? This would let me add export/import commands, I suppose... although ability to store list of trusted players on server (that survives world reset) would be great!

I remember that currently, files can only be written to the 'unsafedata' folder and must end with '.txt', '.tex', '.xml', '.png', or '.json'

 

  • Health 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...