-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update LanguageServerHost to use NamedPipe #69816
Conversation
Do we have any tests for this component? I don't see any... |
We don't for the program component itself, only for the component that we pass the streams to. We likely should but I haven't gotten to it. |
src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs
Outdated
Show resolved
Hide resolved
src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs
Show resolved
Hide resolved
src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs
Outdated
Show resolved
Hide resolved
static string GetDotNetPipeConnectionString(string pipeName) | ||
{ | ||
return "\\\\.\\" + pipeName; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this syntax also work on Mac/Linux pipes? Or should we expect that the host is providing the Win32 name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure! Attempting to test on mac now
var pipeNameOption = new CliOption<string>("--pipe") | ||
{ | ||
Description = "The name of the pipe to use for RPC with the parent process.", | ||
Required = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still allow for stdin/stdout for a bit longer, if only so that way we don't have to merge/flow this simultaneously with the VS Code side of things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
David and I discussed this, and determined it would be fine to merge both PRs close together. The only risk is that someone else updates roslyn version before I get PR in, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we should change, otherwise looks good.
src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs
Outdated
Show resolved
Hide resolved
src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs
Outdated
Show resolved
Hide resolved
@@ -100,7 +100,11 @@ static async Task RunAsync(ServerConfiguration serverConfiguration, Cancellation | |||
// TODO: Remove, the path should match exactly. Workaround for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1830914. | |||
Microsoft.CodeAnalysis.EditAndContinue.EditAndContinueMethodDebugInfoReader.IgnoreCaseWhenComparingDocumentNames = Path.DirectorySeparatorChar == '\\'; | |||
|
|||
var server = new LanguageServerHost(Console.OpenStandardInput(), Console.OpenStandardOutput(), exportProvider, loggerFactory.CreateLogger(nameof(LanguageServerHost))); | |||
// Named pipe server is actually created from the client, so here we create a client stream. | |||
var pipeServer = new NamedPipeClientStream(serverName: ".", serverConfiguration.PipeName, PipeDirection.InOut, PipeOptions.Asynchronous); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dibarbet PipeOptions.CurrentUserOnly isn't working. It connects but doesn't send any messages. I could investigate further (I don't know if the issue is between .net and nodjs?) but I don't know if it's worth the time. I don't think this is less secure than the stdin/out was? Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the client is not creating a pipe that applies to the current user.
Honestly I'm not super familiar with named pipes - but it seems like a lower privileged user could hijack the pipe name and then get access to files from the server that they normally couldn't get. I'm not sure it would be as easy to hijack stdin/out. But maybe it doesn't matter if the pipe is created in the user's tmp dir?
But I don't really know much about named pipes. Not sure @jaredpar might have additional insight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is less secure than the stdin/out was?
You can't get a handle to another processes stdin/out, but depending on how the pipe is created, this could be. This is a pretty common source of security bugs in the Linux world, especially since /tmp is world-accessible. The potential attack here is imagine you have two users on a machine, one launches VS Code. The other malicious user sees the pipe get created, and connects to it prior to our LSP connecting to it. In that case, you're now able to send LSP messages to the other user's client, which could be potentially bad/broken. (Imagine getting didOpen for files you can't otherwise read, or sending LSP messages back which executes stuff on the VS Code side...)
It's entirely possible we're OK here if the pipe creation API is already doing the right thing, but we'd need to validate that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't see a way to configure access on the nodejs side - https://nodejs.org/api/net.html#netcreateserveroptions-connectionlistener
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it here - https://nodejs.org/api/net.html#serverlistenoptions-callback - looks like the default should be current user, so that looks ok (unless vscode is launching as a different user)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you see the default as current user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under server.listen options (from https://nodejs.org/api/net.html#serverlistenoptions-callback ), e.g.
closed in favor of #69918 |
Current communication between client and the Rolsyn language server is writing to STDOUT. This makes the connection vulnerable to any code in the process writing to stdout stream and corrupting the data.
We have seen at least one bug with this problem: microsoft/vscode-dotnettools#333
The fix it to use a named pipe to communicate. Two things to note about this...