Skip to content

fix(mcp): make session-marker symlink resistance work on Windows#337

Merged
colbymchenry merged 1 commit into
mainfrom
fix/session-marker-symlink-nofollow
May 22, 2026
Merged

fix(mcp): make session-marker symlink resistance work on Windows#337
colbymchenry merged 1 commit into
mainfrom
fix/session-marker-symlink-nofollow

Conversation

@colbymchenry
Copy link
Copy Markdown
Owner

What

markSessionConsulted (the /tmp session-consulted marker write) relied on O_NOFOLLOW to refuse a pre-planted symlink at the marker path — the CWE-59 protection added in #280. But fs.constants.O_NOFOLLOW is undefined on Windows (libuv ignores it), so O_WRONLY | O_CREAT | O_TRUNC | undefined silently drops the flag and openSync follows the symlink, overwriting the target.

Fix

Add a cross-platform lstatSync(markerPath).isSymbolicLink() refuse-check before openSync. O_NOFOLLOW stays as the atomic, TOCTOU-free guard on POSIX; the lstat check covers Windows (small lstat→open TOCTOU window, acceptable for a benign marker).

Validation

  • macOS: full suite green (775 passed, 2 win-gated skips).
  • Real Windows 11 (ARM) VM: security.test.ts now fully green (37 passed, 2 skipped). The Session marker symlink resistance > does not follow a pre-planted symlink test — which failed on Windows before this change — now passes.

Found while validating #327/#230 on a Windows VM. Refs #280.

🤖 Generated with Claude Code

O_NOFOLLOW is undefined on Windows (libuv ignores it), so the bitwise-OR
silently dropped it and markSessionConsulted would follow a pre-planted symlink
at the tmp marker path — the CWE-59 gap #280 closed on POSIX but not Windows.
Add a cross-platform lstatSync isSymbolicLink() refuse-check before openSync
(O_NOFOLLOW stays as the atomic, TOCTOU-free guard on POSIX). The existing
Session-marker-symlink-resistance test now passes on Windows.

Refs #280

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@colbymchenry colbymchenry merged commit 6f4b521 into main May 22, 2026
@colbymchenry colbymchenry deleted the fix/session-marker-symlink-nofollow branch May 22, 2026 19: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