Repository navigation
fix(mods): re-check destination folder before reading or copying mod configs (#626) - #796
Conversation
Pixnop
left a comment
There was a problem hiding this comment.
I reviewed 0e3d026b against dev adab6b96: ran your new tests against dev's code, then swapped a ModConfig folder for a link at three later points: between the lstat and the readFile, while the recovery folder is prepared, and during an export.
The check sits where #626 asks for it, right before the lstat (modConfigs.ts:729). A throw there lands in the per-entry catch, so the entry is refused as write-failed, the other entries still apply, and the lease is released as before. In the scenario the issue describes, a swap while an earlier entry is being displaced, the outside file is no longer read or copied. On dev's code the folder-swap test fails (1 failed, 75 passed in modConfigs.test.ts): the outside file ends up in the recovery folder. On this head all 76 pass. It merges cleanly with #793, which also edits modConfigs.ts, and it touches no locale file.
Approving. Note 1 (at least the comment) and note 3 are worth taking here. Note 2 fits a follow-up issue.
Not blocking
-
A swap that lands after the new check still leaves the outside file in a kept recovery folder. The check runs once, then
lstat(:731),readFile(:745),recoveryFolderFor()(:753),ensureDir(:765) andfse.copy(:769) each await. I swappedswapped/for a link right after thelstat, withlegit.jsonin the same pack: the result wasapplied: [legit.json replace],failed: [swapped/target.json write-failed], and the kept recovery folder heldswapped/target.jsonwith the outside file's bytes. Both the read and the copy see the same outside bytes, so the digest check passes. A swap during theensureDirinstead makesfse.copyread the outside file, then the digest check removes it and reportsnot-landed, which is misleading but keeps none of the outside bytes. Path checks can't close this completely in Node, so I'd keep it proportional: runassertManagedPath(dirname(entry.destination), ...)once more after the copy is verified, and on failure removebackupPathand refuse withwrite-failed. Either way, the comment at :727-728 should not claim the copy is covered. -
The export has the same gap.
walkModConfigslstats every file, butcollectModConfigsreads each one later (:346) with no new check, andreadFilefollows links. I puta.jsonandsub/b.jsoninModConfig, then swappedsub/for a link to an outside folder during the read ofa.json. The export returnedok: truewith the outsideb.jsonundersub/b.json. A pack is meant to be shared, so this goes further than the apply case, where the bytes stay in the player's own backups. Re-assertingdirname(file.entryPath)and checking that anlstatstill reports a regular file right before the read would match this PR. Since #793 also changeswalkModConfigs, a separate issue after it lands is probably simpler. -
The file-swap test passes on dev, and some of the read and copy checks can't fail. The swap in the test at :1295 is refused on dev too, by the existing
isSymbolicLink()check at :739. That makes it a fine guard for :739, but not a test of this fix, so a title saying so would help. The handler only ever reads and copies the in-folder path, sostartsWith(outside)at :1281, :1284, :1335 and :1338 never matches. On Windows,includes("swapped/target.json")at :1281 and :1284 doesn't match a path built withpath.joineither, which leaves only thebackupFolderchecks guarding the regression there. Matching onjoin("swapped", "target.json")and dropping thestartsWith(outside)branches fixes both. -
The comment at :714 lost its reason. The old four lines said why a refused key must not be re-examined: the
lstat,readFileandcopyon such a path read someone else's file and put a copy in the recovery folder. The new line says what the code does, not why. I'd keep the old comment. The new #626 comment below it covers the extra check.
|
I reviewed Round oneA swap after the first check no longer leaves the outside file in the recovery folder. The check after the The swap tests now fail where they should. The read and copy checks at The comment at Still approved. It is merged already, so the point below can go in a small follow-up. Not blocking
|
Summary
Revalidates the destination directory with assertManagedPath in applyOneConfigEntry before running lstat, readFile, or fse.copy.
Previously, assertManagedPath was called only during the initial pre-pass over all pending configs and immediately before the atomic write in the write loop. If a folder under ModConfig was replaced with a symbolic link after the pre-pass, lstat on the destination resolved through the directory link to an outside target file, which was read and copied into the recovery backup folder before the subsequent write was refused. Re-checking the destination directory immediately before lstat and read operations halts processing on the swapped path, refusing it as write-failed without reading outside files or copying them into backups.
Type
Checklist
dev, notmain.npm run typecheckpasses.npm run lint:cipasses.npm run format:checkpasses.npm run test:coveragepasses, coverage at or above the floor invitest.config.ts.npm run build:unpackpasses.Testing
Executed the full test suite and build verification:
npm run typecheck: 0 errors.npm run lint:ci: 0 errors.npm run format:check: all files formatted.npm run test:coverage: 304 test files passed (1919 tests passed, 2 skipped). Coverage floors exceeded across all metrics:npm run build:unpack: unpacked Linux binary built successfully indist/linux-unpacked.tests/ipc/modConfigs.test.tscovering:Related issues
Fixes #626