Skip to content

Close remaining path-validation gaps in install flow#409

Merged
Shivansps merged 1 commit into
KnossosNET:mainfrom
Goober5000:fix/various_path_issues
May 11, 2026
Merged

Close remaining path-validation gaps in install flow#409
Shivansps merged 1 commit into
KnossosNET:mainfrom
Goober5000:fix/various_path_issues

Conversation

@Goober5000
Copy link
Copy Markdown
Contributor

Three gaps in install-time path handling that survived e20a3ed:

  • mod.id, mod.version, mod.parent, and pkg.folder were concatenated into modPath without validation, BEFORE the existing IsSubPath check. A poisoned id like "....\Windows\System32" let every subsequent file.dest pass against the poisoned base. New KnUtils.IsSafePathComponent (rejects separators, "..", null bytes, drive letters, NTFS-stripped trailing dots/spaces); InstallMod and InstallBuild now validate before building modPath.

  • TryToCopyFilesFromOldVersions called File.Exists, GetFileHash, File.Copy, and HardLink.CreateFileLink on paths built from JSON- supplied oldPkg.folder / package.folder / f.filename with no IsSubPath check. Now guarded on both the read and write sides, with the existing clear-lists-and-break failure pattern.

  • IsSubPath used OrdinalIgnoreCase unconditionally; on Linux/macOS that let same-name-different-case siblings pass as in-base. Now Ordinal on non-Windows.

Three gaps in install-time path handling that survived e20a3ed:

- mod.id, mod.version, mod.parent, and pkg.folder were concatenated
  into modPath without validation, BEFORE the existing IsSubPath check.
  A poisoned id like "..\..\Windows\System32" let every subsequent
  file.dest pass against the poisoned base. New
  KnUtils.IsSafePathComponent (rejects separators, "..", null bytes,
  drive letters, NTFS-stripped trailing dots/spaces); InstallMod and
  InstallBuild now validate before building modPath.

- TryToCopyFilesFromOldVersions called File.Exists, GetFileHash,
  File.Copy, and HardLink.CreateFileLink on paths built from JSON-
  supplied oldPkg.folder / package.folder / f.filename with no
  IsSubPath check. Now guarded on both the read and write sides, with
  the existing clear-lists-and-break failure pattern.

- IsSubPath used OrdinalIgnoreCase unconditionally; on Linux/macOS
  that let same-name-different-case siblings pass as in-base. Now
  Ordinal on non-Windows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@wookieejedi wookieejedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things still seem to work as expected

@Shivansps Shivansps merged commit cc3c167 into KnossosNET:main May 11, 2026
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.

3 participants