love.filesystem save-directory sandbox permission boundary
0 reputation · 14 Feb 2021, 09:02 UTC
0 reputation · 14 Feb 2021, 09:02 UTC
The goal is to let a LÖVE 1.1.x game write player data to a directory chosen by the user, outside the application’s save directory. love.filesystem resolves relative paths against the save directory or bundled archive and exposes no function to broaden or redirect the PhysicsFS sandbox. It is unclear whether an absolute path outside the save directory is rejected consistently across desktop and mobile, or whether the failure mode depends on the operating system and PhysicsFS build.
Because save-directory paths differ by platform and LÖVE version, hardcoding an absolute location is not portable. The design question is where the permission boundary falls and what behavior to expect when a write targets a path outside it.
Does love.filesystem.write return false or raise an error for an absolute path outside the save directory? Is the sandbox boundary enforced identically on Windows, macOS, Linux, Android, and iOS in LÖVE 1.1.x? Can the boundary be widened without modifying the engine or using platform-specific code?
35275 reputation · 14 Feb 2021, 20:55 UTC
The sandbox is enforced at the engine level (often via PhysicsFS or internal path wrapping). When you provide a path, LÖVE resolves it relative to the path returned by `love.filesystem.getSaveDirectory()`. If the path is absolute (e.g., `C:\Data` or `/home/user`), the engine identifies it as being outside the permitted scope and rejects the write.
There is no built-in function in `love.filesystem` to redirect or broaden the sandbox to an arbitrary user directory. The design philosophy prioritizes "write once, run anywhere" portability. To save data to a user-chosen location, you must bypass the filesystem module entirely:
To verify the behavior in your specific version and environment, run this snippet:
-- Attempt to write to an absolute path
local success = love.filesystem.write("/test_outbound.txt", "data")
if not success then
print("Sandbox blocked the absolute path.")
else
print("Warning: Sandbox bypassed or allowed.")
end
-- Attempt to escape via traversal
local escape_success = love.filesystem.write("../outside.txt", "data")
print("Traversal success:", tostring(escape_success))
Note: The user mentioned LÖVE 1.1.x, which is not a standard versioning scheme. This analysis applies to the 0.9.x through 11.x.x series.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 14 Feb 2021, 10:44 UTC
Assuming the target is LÖVE 11.x rather than a literal 1.1.x release, one useful distinction is that a false return from love.filesystem.write on an absolute path does not automatically mean PhysicsFS rejected it. On desktop, the PhysicsFS write-directory boundary is typically the first gate. On Android and iOS, the OS app sandbox can deny the write before PhysicsFS evaluates the path, so the error string may reflect an OS-level failure instead.
When verifying, log the error message with the return value and compare it against a relative ../outside.txt probe on the same build. Also keep in mind that love.filesystem.setIdentity relocates the whole sandbox; it does not create additional writable roots or allow arbitrary absolute paths outside it.