Re-check the game folder right before git deletes or overwrites files, so a swapped-in junction is refused #162

Closed
opened 2026-10-25 23:28:10 -05:00 by ethan-hann · 1 comment
Owner

A security review found a check-then-use race in the git operations that delete or overwrite files. DiscardChangesAsync (src/Savepoint.Core/Git/GitEngine.Checkout.cs:124-144) runs CheckWorkTree and RepoMarker.Verify once, then several git processes later runs git clean -f -d -x (254-263); CleanAsync (215-227) and the checkout at 293 are the same. GitRunner.cs:182 passes GIT_WORK_TREE as Path.GetFullPath of the original path, not the link-resolved path PathSafety approved, and each git process reopens the folder by name. On a shared PC where another local account can modify the folder above a game folder (a secondary NTFS drive, a folder made under C:), that account can swap the game folder for a junction to the victim's Documents between the check and git clean, and SavePoint deletes untracked files there. Fix: pass PathSafety.ResolveRealPath as GIT_WORK_TREE and record the folder identity; re-check identity and the consent marker right before each reset --hard, checkout --force and clean; on Windows hold a handle on the folder without FILE_SHARE_DELETE for the whole operation so it cannot be renamed. Severity medium: needs a second local account with write access to the parent folder.

A security review found a check-then-use race in the git operations that delete or overwrite files. DiscardChangesAsync (src/Savepoint.Core/Git/GitEngine.Checkout.cs:124-144) runs CheckWorkTree and RepoMarker.Verify once, then several git processes later runs git clean -f -d -x (254-263); CleanAsync (215-227) and the checkout at 293 are the same. GitRunner.cs:182 passes GIT_WORK_TREE as Path.GetFullPath of the original path, not the link-resolved path PathSafety approved, and each git process reopens the folder by name. On a shared PC where another local account can modify the folder above a game folder (a secondary NTFS drive, a folder made under C:\), that account can swap the game folder for a junction to the victim's Documents between the check and git clean, and SavePoint deletes untracked files there. Fix: pass PathSafety.ResolveRealPath as GIT_WORK_TREE and record the folder identity; re-check identity and the consent marker right before each reset --hard, checkout --force and clean; on Windows hold a handle on the folder without FILE_SHARE_DELETE for the whole operation so it cannot be renamed. Severity medium: needs a second local account with write access to the parent folder.
ethan-hann added this to the 1.0 milestone 2026-10-25 23:28:10 -05:00
Author
Owner

Shipped in 0.9.15 (pull request 174).

Shipped in 0.9.15 (pull request 174).
Sign in to join this conversation.
No milestone
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
ethan-hann/SavePoint#162
No description provided.