Repository navigation
D3D12-LUA-WRITE-FILE-PATH-NORMALIZATION: check mod.json and blocked extensions on normalized path - #2683
Conversation
…normalized path (D3D12-LUA-WRITE-FILE-PATH-NORMALIZATION) write_file() previously checked lower == "mod.json" and the blocked executable extension list against the raw name string before safe_relative() normalized Path::components(). Because Path::components() strips trailing '/' and interior '.', names such as "mod.json/", "mod.json/.", "evil.exe/", or "sub/evil.dll/." bypassed both checks and wrote mod.json or blocked executables into the mod folder. Normalize with safe_relative(name) first and inspect the normalized relative path's file_name() and extension() instead. Includes a Red -> Green unit test covering all bypass forms. AI-assisted: Antigravity (Gemini 4 Neon)
|
Verified by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1 (
Not covered: Windows path forms (backslashes, drive letters, alternate data streams); this ran on macOS, where only AI-assisted: Claude Code |
|
@bobcatchris could you merge current OreoFR's red/green (macOS) is on the current head The merge changes the head, so the red/green will need to be run again on the new one. AI-assisted: yes |
AI-assisted: Claude Sonnet 5.5
|
@MoonEyes merged current Checked on the new head (Windows 11, Ryzen 7 7800X3D, Rust 1.98.1,
OreoFR's red/green is on the old head AI-assisted: Claude Sonnet 5.5 |
|
@OreoFR could you run your red/green again on the new head AI-assisted: yes |
|
Native Windows red/green on the new head
A local probe (not part of the PR) calls
So with the backslash, drive, stream and trailing-dot/space forms all caught, the one Windows form that still reaches the manifest is its 8.3 short name. NTFS gives The U+017F and superscript-digit device names came out as ordinary files on this Windows build, with no device opened and nothing aliased. GPUs tested: n/a (CPU/file-system tests). AI-assisted: yes. |
|
@bobcatchris on the 8.3 short-name case from my check above ( AI-assisted: yes |
|
@Kal0s-design thanks for the check and the fix. I will not cherry-pick it: this PR stays at the trailing-slash scope it was verified at, and an 8.3 short name is a different input that deserves its own red/green. Please open yours as D3D12-LUA-WRITE-FILE-SHORT-NAMES with \Depends on: #2683; I will not touch that function in the meantime. AI-assisted: Claude Sonnet 5.5 |
|
@bobcatchris understood, thanks. I'll open D3D12-LUA-WRITE-FILE-SHORT-NAMES as its own PR with AI-assisted: yes |
KelboLive
left a comment
There was a problem hiding this comment.
Reviewed at 910468f42 on Windows 11 in an own worktree. The claim holds: both gates now run on safe_relative(name) (api.rs:512-530), so mod.json/ and evil.exe/ are caught after normalization, and restoring the raw-string deny-list makes the new test fail on evil.exe/ — the mutant is killed. cargo test -p leonida-lua is 36/36, check_no_game_data passes, and merge-tree is clean (590 behind main, but api.rs has not changed since the merge base).
One regression introduced by the rewrite: Path::extension() returns None when the name is only a dot plus the extension, so .exe, sub/.bat and .ps1 are writable again. I verified it by adding .exe to the test's bad list — it fails — while the old rsplit_once('.') refused them, and Windows itself treats .exe as extension exe. Fix: derive the suffix from the normalized file name's last .-separated segment (or reject a leading-dot component outright) and add .exe / sub/.exe cases to the same test. The 8.3 short-name (MOD~1.JSO) case can stay in the follow-up where it already is.
Everything else about the change is right: normalization before both gates, the top-level case-insensitive mod.json check, and inside() still doing the escape/link check afterwards.
VERIFY-2683 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game filesVerdict: PASS, and this one closes a hole that lets a mod do two things it is not allowed to do. On Head 1. What was wrong
let lower = name.to_ascii_lowercase();
let extension = lower.rsplit_once('.').map_or("", |(_, e)| e);
if lower == "mod.json" || [ "exe", "dll", "bat", … ].contains(&extension) { … }
// crates/leonida-lua/src/manifest.rs:78
pub fn safe_relative(path: &str) -> Result<PathBuf, String> { … }
// `Path::components()` normalises "." away and ignores a trailing separator,
// so "mod.json/." and "mod.json/" both come out as the single component "mod.json".So the check looked at one string and the write went to another. 2. What that let a mod do — measured on
|
|
@KelboLive Fixed in
AI-assisted: Gemini 4 Neon (including an independent read-only reviewer pass). |
Claimed in #2570 as
D3D12-LUA-WRITE-FILE-PATH-NORMALIZATION(#issuecomment-7266797979).What and why
In
d3d12/crates/leonida-lua/src/api.rs,write_file()validatedlower == "mod.json"and the executable extension deny-list (exe,dll,bat,cmd,com,ps1,vbs,msi,scr,lnk,sys,reg,hta,jar) against the rawnamestring beforeinside()calledsafe_relative(name).Because Rust's
Path::components()strips trailing/and interior., a mod could pass"mod.json/","mod.json/.","evil.exe/","evil.exe/.","sub/evil.dll/", or"sub/evil.bat/."— bypassing both checks and overwritingmod.jsonor writing blocked executables directly into the mod folder.This change normalizes
namewithsafe_relative(name)?first and checks the normalized relative path'sfile_name()(when at the mod root) andextension()case-insensitively.Verification (Red -> Green)
Hardware / OS: native Windows 11 Pro (
10.0.26200), pinned toolchainrustc 1.98.1.api::tests::write_file_blocks_manifest_and_executables_after_path_normalizationfailed immediately on"mod.json/"(mod.json/was allowed and overwrotemod.json).main40e7fe69d):cargo test -p leonida-lua --lib—36 passed; 0 failed(0.50s).api.rs.python -I scripts/check_no_game_data.py d3d12/crates/leonida-lua/src/api.rs— PASS.AI-assisted: Antigravity (Gemini 4 Neon)