fix: SSMS extension uses a random temp filename#251
Merged
Conversation
Swap the predictable `ssms_plan_{yyyyMMdd_HHmmss}.sqlplan` name for a random
suffix produced by Path.GetRandomFileName, and open with FileMode.CreateNew
so we refuse to overwrite a pre-existing file. Closes the race where another
local process could predict the filename and plant a symlink at that path
before the extension's File.WriteAllText landed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
|
Post-merge review (PR was merged ~7s after open, so inline comments would be noise — summary only). What it does Good
Needs attention
No Avalonia / brush / PlanAnalyzer-sync concerns — this PR doesn't touch UI, theming, or analysis rules. Generated by Claude Code |
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.
Summary
PlanViewer.Ssms/AppLauncher.cs:SavePlanToTempwas naming its temp filessms_plan_{yyyyMMdd_HHmmss}.sqlplan, which is trivially predictable by any other process on the machine. Combined withFile.WriteAllText(which follows symlinks), a same-privilege attacker could plant a symlink at the expected path and have the extension's write redirect into an arbitrary file.Fix
ssms_plan_<random>.sqlplanusingPath.GetRandomFileNamefor the suffix.FileMode.CreateNew + FileShare.Noneso the write refuses to land if a file already exists at that path..sqlplanso the app still recognizes the file type.Test plan
System.IOcalls, which behave identically on net472/net8.0) confirms:yyyyMMdd_HHmmsspattern.FileMode.CreateNewthrowsIOExceptionon a pre-existing file and the pre-existing content is preserved (the symlink-plant defense).dotnet buildcan't — net472 targeting pack isn't installed on this machine).🤖 Generated with Claude Code