fix(mcp): make session-marker symlink resistance work on Windows#337
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
markSessionConsulted(the/tmpsession-consulted marker write) relied onO_NOFOLLOWto refuse a pre-planted symlink at the marker path — the CWE-59 protection added in #280. Butfs.constants.O_NOFOLLOWisundefinedon Windows (libuv ignores it), soO_WRONLY | O_CREAT | O_TRUNC | undefinedsilently drops the flag andopenSyncfollows the symlink, overwriting the target.Fix
Add a cross-platform
lstatSync(markerPath).isSymbolicLink()refuse-check beforeopenSync.O_NOFOLLOWstays as the atomic, TOCTOU-free guard on POSIX; the lstat check covers Windows (small lstat→open TOCTOU window, acceptable for a benign marker).Validation
security.test.tsnow fully green (37 passed, 2 skipped). TheSession marker symlink resistance > does not follow a pre-planted symlinktest — which failed on Windows before this change — now passes.Found while validating #327/#230 on a Windows VM. Refs #280.
🤖 Generated with Claude Code