Skip to content

fix(windows): refuse .part reparse points - #113

Merged
Abdk4Moura merged 6 commits into
mainfrom
fix/win-reparse-pr
Aug 4, 2026
Merged

fix(windows): refuse .part reparse points#113
Abdk4Moura merged 6 commits into
mainfrom
fix/win-reparse-pr

Conversation

@Abdk4Moura

@Abdk4Moura Abdk4Moura commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

Harden Windows .part writes against symlinks and junctions. The helpers open with FILE_FLAG_OPEN_REPARSE_POINT and FILE_FLAG_BACKUP_SEMANTICS, then inspect the opened handle with GetFileInformationByHandle before allowing writes.

The windows-sys = 0.59 feature list includes Win32_Storage_FileSystem, Win32_Foundation, and Win32_Security. Win32_Security is retained for the named-pipe SECURITY_ATTRIBUTES work in PR #63; the lists must be merged, not replaced.

Tests

The Windows tests include a junction smoke check and file-symlink redirect refusal for resume/open. The meaningful tests assert PermissionDenied, the reparse point refusal message, and unchanged outside-target contents.

The throwaway no-hardening control in PR #111 ran on Windows and produced the predicted result: the two symlink tests failed because unhardened OpenOptions returned Ok for the outside target, while the junction CREATE_NEW smoke test passed with EEXIST. This demonstrates that the two symlink assertions are load-bearing.

Scope

Source reading establishes that main's Windows helpers lacked a reparse check while the Unix helpers checked the opened file. The control run now also demonstrates the vulnerable before-state. PR #113's exact head a71098df0dfb8ef3e7b72da1789b0be3e5c7bb42 is green on all 11 checks.

…ctions

Closes the Windows half that 0.7.2/0.7.3 explicitly deferred.

safe_create_part (Windows): opens with FILE_FLAG_OPEN_REPARSE_POINT +
FILE_FLAG_BACKUP_SEMANTICS (allows opening dir junctions), then uses
GetFileInformationByHandle (handle-based, no TOCTOU) to reject reparse
points.

safe_resume_part / safe_open_part (Windows): same approach —
FILE_FLAG_OPEN_REPARSE_POINT + FILE_FLAG_BACKUP_SEMANTICS, then
GetFileInformationByHandle to reject reparse points and non-regular files.

Added windows-sys 0.59 with Win32_Storage_FileSystem + Win32_Foundation.

Three #[cfg(windows)] tests: use  for junction creation
(no privilege needed). Tests accept either outcome (open-fails OR attr-
rejects) since dir junctions may need FILE_FLAG_BACKUP_SEMANTICS to open
for write. Runtime verification needs a Windows runner (#34).

cargo check --target x86_64-pc-windows-gnu --tests: clean.
The 3 win_safe_*_refuses_junction tests + create_junction helper were
at ~main.rs:4755, which is inside the main code (not inside #[cfg(test)]).
They compiled as dead code into the normal binary and the test harness
never collected them, so they'd never actually run even on a Windows runner.

Moved them into the existing #[cfg(test)] mod tests block where the Unix
transfer_part_refuses_symlink / transfer_open_part_refuses_symlink tests
already live. Now the harness collects them on Windows and the 'never used'
warnings disappear.

cargo check --target x86_64-pc-windows-gnu --tests: warning-clean for these
functions (verified in the shared checkout before moving to worktree).
@Abdk4Moura
Abdk4Moura merged commit 56c375a into main Aug 4, 2026
11 checks passed
@Abdk4Moura
Abdk4Moura deleted the fix/win-reparse-pr branch August 4, 2026 08:29
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