dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
487 stars 190 forks source link

directory traversal .. in ArtifactsPath Breaks Resolving Document Contexts #10611

Closed Applesauce314 closed 1 month ago

Applesauce314 commented 1 month ago

If <ArtifactsPath> contains a directory traversal segment, (i.e.. .. or . e.g.<ArtifactsPath>$(MSBuildThisFileDirectory)..\artifacts</ArtifactsPath> then the Razor LSP will be unable to create document contexts and all LSP features will not function.

it appears the ProjectKey stored in the DefaultProjectSnapshotManager._projects_needsLock Dictionary has been normalized to remove the directory traversal segment, but the ProjectKey used to lookup the project in DocumentContextFactory.TryResolveDocument still has the \..\ in it.

the assembly version number from my Visual studio 2022 install 17.9.2

[assembly: AssemblyTitle("Microsoft.AspNetCore.Razor.LanguageServer")]
[assembly: AssemblyFileVersion("7.0.24.12004")]
[assembly: AssemblyInformationalVersion("7.0.0-preview.24120.4+684740676513b3b208d5bd5b7f8786dab8d287b7")]

basic reproduction is at https://github.com/Applesauce314/ArtifactsPathReproIssue10611

Applesauce314 commented 1 month ago

im working on creating a minimal reproduction will link shortly (update: description updated with link)

Applesauce314 commented 1 month ago

you can switch between working and not working by modifying the line in Directory.Build.Props

Applesauce314 commented 1 month ago

IT appears this is a similar problem to #5965 but coming in from a different side.

phil-allen-msft commented 1 month ago

@Applesauce314 , I believe that PR https://github.com/dotnet/razor/pull/9907 should address this issue and it should be available in 17.10.x builds. Please try it out and let us know what you find.

Applesauce314 commented 1 month ago

@Applesauce314 , I believe that PR #9907 should address this issue and it should be available in 17.10.x builds. Please try it out and let us know what you find.

i don't have the ability to update my version at this time, but given that the problem listed is exactly the problem I am having you can close. My apologizes, I thought i did a good job searching before I created this issue but apparently I did not.