Skip to content

fix(mods): re-check destination folder before reading or copying mod configs (#626) - #796

Open
Zaldaryon wants to merge 1 commit into
devfrom
fix/issue-626-mod-config-apply-swapped-link
Open

Zaldaryon wants to merge 1 commit into
devfrom
fix/issue-626-mod-config-apply-swapped-link

Conversation

@Zaldaryon

Copy link
Copy Markdown
Collaborator

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

  • Bug fix
  • Feature
  • Performance
  • Refactor or cleanup
  • Tests only
  • Docs or build

Checklist

  • Targets dev, not main.
  • npm run typecheck passes.
  • npm run lint:ci passes.
  • npm run format:check passes.
  • npm run test:coverage passes, coverage at or above the floor in vitest.config.ts.
  • npm run build:unpack passes.

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:
    • Statements: 95.07% (floor: 94.0%)
    • Branches: 91.29% (floor: 89.0%)
    • Functions: 95.89% (floor: 94.0%)
    • Lines: 97.02% (floor: 96.0%)
  • npm run build:unpack: unpacked Linux binary built successfully in dist/linux-unpacked.
  • Added regression tests in tests/ipc/modConfigs.test.ts covering:
    • A destination folder swapped for a symbolic link to an outside directory after the pre-pass during displacement of a prior file. Confirmed that no outside files are read or copied, the swapped target is recorded as write-failed, and the recovery backup retains only valid files.
    • A destination file swapped for a symbolic link to an outside file after the pre-pass. Confirmed that the link is refused as write-failed without reading or copying outside bytes.

Related issues

Fixes #626

@Zaldaryon
Zaldaryon requested a review from Pixnop October 27, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant