D3D12-LUA-WRITE-FILE-PATH-NORMALIZATION: check mod.json and blocked extensions on normalized path #2683
Closed
github-bot
wants to merge 4 commits from
github-bot/gh-2683 into main
AGit
pull from: github-bot/gh-2683
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2683
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2683"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@bobcatchris on GitHub · 2026-11-30 02:13 UTC · original
bobcatchris:fix/d3d12-lua-write-file-path-normalization→main· +59 −9 · 1 files · 4 commits · closed without mergingClaimed 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)
@OreoFR on GitHub · 2026-11-30 02:16 UTC · original
Verified by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1 (
cargo test -p leonida-lua), main182d0c174, PR head8f7f04d2f. MEASURED:api.rs+ only this PR's#[cfg(test)] mod tests): 35 passed, 1 failed:write_file_blocks_manifest_and_executables_after_path_normalizationpanics at the first trailing-slash case: "mod.json/must be refused by write_file". So on mainwrite_filereturnsOkformod.json/(the name check runs on the raw string, before normalization); I did not check what it then wrote.merge --no-ff): 36/36 passed.git merge-tree).Not covered: Windows path forms (backslashes, drive letters, alternate data streams); this ran on macOS, where only
/separates.AI-assisted: Claude Code
@MoonEyes on GitHub · 2026-11-30 10:17 UTC · original
@bobcatchris could you merge current
maininto this branch (a merge, no rebase or force-push) so CI runs again?OreoFR's red/green (macOS) is on the current head
8f7f04d2f. What is in the way is CI on that head, which is red on semantic-tests and ran on an older base. Onmainat4014af7f, CI was green exceptmacos. I have not checked whether each red here comes frommainor from this PR, so the new run should tell.The merge changes the head, so the red/green will need to be run again on the new one.
AI-assisted: yes
@bobcatchris on GitHub · 2026-11-30 11:09 UTC · original
@MoonEyes merged current
main(d367675c7) into this branch (a merge, no rebase or force-push). New head910468f42; the merge was clean, and the diff againstmainis still onlyd3d12/crates/leonida-lua/src/api.rs.Checked on the new head (Windows 11, Ryzen 7 7800X3D, Rust 1.98.1,
cargo test --locked --offline -p leonida-lua): 36 passed, 0 failed.python -I scripts/check_no_game_data.pyonapi.rsfound nothing.cargo clippy --no-deps -p leonida-lua --all-targets -- -D warningsstill reports 3 warnings in the library (input.rsKeys/PadsDefault,memory.rs:94is_multiple_of) and 2 in the tests (tests.rs:356,:370byte string). They are all in files this PR does not touch, so they are not from this change.OreoFR's red/green is on the old head
8f7f04d2fand will need to be run again on910468f42.AI-assisted: Claude Sonnet 5.5
@MoonEyes on GitHub · 2026-11-30 11:33 UTC · original
@OreoFR could you run your red/green again on the new head
910468f42? @bobcatchris mergedmain(d367675c7) into the branch, CI is green on all 5 checks there, and your run was on the previous head8f7f04d2f. A check of the Windows path forms (backslashes, drive letters), which your comment lists as not covered, would help too if someone has a Windows machine.AI-assisted: yes
@Kal0s-design on GitHub · 2026-11-30 13:59 UTC · original
Native Windows red/green on the new head
910468f42, plus the Windows path forms MoonEyes asked about. Merged onto currentmainf44904d21(56547254f). Windows 11, NTFS, MSVC x64, Rust 1.98.1,cargo test -p leonida-lua --lib.main+ only this PR's test module: 35 passed, 1 failed,`mod.json/` must be refused by write_file. On Windows that call returnsOkand does overwritemod.json(the probe below reads it back as the new bytes).main+ this PR: 36 passed, 0 failed.A local probe (not part of the PR) calls
write_fileon a fresh temp folder holdingmod.json, then readsmod.jsonback and lists what was created:mainmod.json/,evil.exe/./Ok,mod.jsonoverwritten /evil.exewrittenmod.json\,C:mod.json,C:\x\mod.json,\?\C:\x,mod.json:x,evil.exe::$DATAsafe_relative:\and:)evil.exe.,evil.exe,evil.exe. .,nul.txt,sub/../mod.json,./mod.json,evil.EXE,EVIL~1.EXEMOD~1.JSO,mod~1.jsoOk,mod.jsonoverwrittenOk,mod.jsonoverwrittenmod.jſon(U+017F),COM¹.txt,LPT²,CONIN$,CONOUT$Ok, a separate ordinary file of that nameSo 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
mod.jsonthe aliasMOD~1.JSOwhen short names are on for the volume (they are for the temp folder here). The name passessafe_relativeand the checks this PR adds (its own name isn'tmod.json, andjsoisn't on the list), and Windows resolves it tomod.json. That's outside this PR's trailing-slash scope. One way to close it would be to check the name of the file the path resolves to when it exists, e.g.canonicalizeit and run the manifest/extension checks on thatfile_name, or to refuse a component containing~followed by a digit. I'd leave that choice to you, as a follow-up item or here.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.
@Kal0s-design on GitHub · 2026-11-30 14:05 UTC · original
@bobcatchris on the 8.3 short-name case from my check above (
MOD~1.JSO→mod.json): I put a fix on top of this branch,github.com/Kal0s-design/leonida-continued@1772676d1(branchfix/lua-write-file-short-names, claimed in #2570 as D3D12-LUA-WRITE-FILE-SHORT-NAMES). When the path leads to an existing file,write_filechecks it again by the name it has (canonicalized, relative to the mod's folder), with your manifest/extension rules moved into onenot_writablefunction. A test fails on this PR's code and passes with it; it skips on volumes without 8.3 names.leonida-lualib: 37 passed. Feel free to cherry-pick it here if you'd rather have it in one PR; otherwise I'll open it withDepends on: #2683when I have a slot.AI-assisted: yes
@bobcatchris on GitHub · 2026-11-30 15:28 UTC · original
@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
@Kal0s-design on GitHub · 2026-11-30 15:42 UTC · original
@bobcatchris understood, thanks. I'll open D3D12-LUA-WRITE-FILE-SHORT-NAMES as its own PR with
Depends on: #2683once this account has a free PR slot, with its own red/green.AI-assisted: yes
@KelboLive on GitHub · 2026-12-01 15:09 UTC · original · reviewed
Reviewed at
910468f42on Windows 11 in an own worktree. The claim holds: both gates now run onsafe_relative(name)(api.rs:512-530), somod.json/andevil.exe/are caught after normalization, and restoring the raw-string deny-list makes the new test fail onevil.exe/— the mutant is killed.cargo test -p leonida-luais 36/36,check_no_game_datapasses, andmerge-treeis clean (590 behind main, butapi.rshas not changed since the merge base).One regression introduced by the rewrite:
Path::extension()returnsNonewhen the name is only a dot plus the extension, so.exe,sub/.batand.ps1are writable again. I verified it by adding.exeto the test's bad list — it fails — while the oldrsplit_once('.')refused them, and Windows itself treats.exeas extensionexe. Fix: derive the suffix from the normalized file name's last.-separated segment (or reject a leading-dot component outright) and add.exe/sub/.execases 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.jsoncheck, andinside()still doing the escape/link check afterwards.@imShangLi on GitHub · 2026-12-01 15:43 UTC · original
VERIFY-2683 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files
Verdict: PASS, and this one closes a hole that lets a mod do two things it is not allowed to do. On
main, a mod can overwrite its ownmod.jsonand create.exe/.dllfiles inside its folder; after this pull request both are refused. I demonstrated the before and after.Head
910468f4, base the currentmain88a9f133, merge based367675c, 1 commit, 1 file, +55/−9:d3d12/crates/leonida-lua/src/api.rs.1. What was wrong
write_filechecked the blocklist against the name as given:rsplit_once('.')on"evil.exe/"gives the extension"exe/"— with the trailing slash still on it — and"exe/"is not in the list. The path itself was normalised later, byinside()→safe_relative(), which drops a trailing slash and a trailing/.:So the check looked at one string and the write went to another.
2. What that let a mod do — measured on
mainI put
main's production code back (only the blocked-check reverted, the pull request's test kept) and calledwrite_filedirectly:The mod's own manifest was overwritten with the bytes the mod chose, and an
.exeand a.dllwere created in its folder — the two things the blocklist exists to prevent.With the pull request's code, the same calls:
3. The fix
The check now runs on the normalised path:
Two details worth naming:
safe_relative(name)?before the check means a name that is not a plain relative path is refused there and then, rather than slipping past the blocklist and being rejected later byinside(). That is the same functioninside()uses, so the check and the write now agree on what the path is.is_manifestrequires the manifest name to be the last component with no parent, sosub/mod.jsonis not treated as the manifest (only the root one is), andmod.jsonis matched case-insensitively —MOD.JSONis caught, which the oldlower == "mod.json"also caught, but the new one keeps that for the normalised name.4. Red and green, and the discrimination
python -I scripts/red_green.py pr2683 --crate leonida-lua(the repository's own red/green tool):and by hand, with only the production change reverted:
With the pull request's code the whole crate is 36 passed, 0 failed.
5. What I did not check
rustc 1.98.1). The behaviour is path handling, which is the same on both, but the reserved-device names and the\\rejection insafe_relativeare Windows-specific and I did not exercise them.write_fileonly. The pull request's own test also asserts that the files were not created, which covers the write path; I did not look for a second way in (the manifest's other fields, thescriptpath, the platform interface).mod.jsonis meant to be writable at all. I took the blocklist at face value: the manifest is the file that decides what the mod may do, so a mod rewriting it is a privilege problem whichever side of the line the maintainer draws it.leonida-gpu,leonida-hleandleonida-loaderdo not build on Linux for reasons that predate this pull request (upstream: "The crates are Windows-only today … Linux follows #2577"), so I ranleonida-luaon its own.cargo clippy(already failing onmain, run as a report by the workflow) andcargo fmt(left out of the d3d12 workflow).AI-assisted: MiniMax M3.1 Flash.
@bobcatchris on GitHub · 2026-12-01 18:25 UTC · original
@KelboLive Fixed in
b24edaa99(after mergingmain, no rebase/force-push):rel.extension()withfile_name.and_then(|f| f.rsplit_once('.'))on thesafe_relative-normalized path so leading-dot executable names (.exe,.exe/,sub/.bat,sub/.ps1/.) are refused again..exe,.exe/,sub/.bat, andsub/.ps1/.towrite_file_blocks_manifest_and_executables_after_path_normalization.cargo test --locked -p leonida-lua(41 passed, 0 failed) andpython -I scripts/check_no_game_data.py(clean).AI-assisted: Gemini 4 Neon (including an independent read-only reviewer pass).
@MoonEyes on GitHub · 2026-12-02 12:24 UTC · original
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
@MoonEyes on GitHub · 2026-12-02 15:43 UTC · original
Closing: on current
mainthis pull request no longer builds. #3051 (merged today) changedd3d12/crates/leonida-lua/src/api.rsto importcrate::manifestinstead ofcrate::manifest::safe_relative; git merges the two without a textual conflict, but the merge fails with E0425 (safe_relativenot found inapi.rs, used at the calls this pull request adds). Open pull requests that have fallen out of step withmainare being closed so the list stays workable. If you still want this change, rebase it on currentmain(callingmanifest::safe_relativethere) and reopen it.AI-assisted (Claude Code).
Pull request closed