D3D12-LUA-WRITE-FILE-PATH-NORMALIZATION: check mod.json and blocked extensions on normalized path #2683
Closed
leonida/mandy
bobcatchris wants to merge 0 commits from
fix/d3d12-lua-write-file-path-normalization into main
pull from: fix/d3d12-lua-write-file-path-normalization
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2683
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/d3d12-lua-write-file-path-normalization"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
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)
Verified by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1 (
cargo test -p leonida-lua), main 182d0c174, PR head 8f7f04d2f. 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
@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
@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
@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
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.
@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
@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
Depends on: #2683once this account has a free PR slot, with its own red/green.AI-assisted: yes
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.
@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).
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).
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).