Skip to content

Bring back logic to remove unwanted env variables #20326

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

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvid
UseShellExecute = false,
RedirectStandardOutput = true,
};
RemoveUnwantedEnvironmentVariables(processStartInfo.Environment);

var debugProxyProcess = Process.Start(processStartInfo);
CompleteTaskWhenServerIsReady(debugProxyProcess, tcs);
Expand All @@ -64,6 +65,21 @@ private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvid
return await tcs.Task;
}

private static void RemoveUnwantedEnvironmentVariables(IDictionary<string, string> environment)
{
// Generally we expect to pass through most environment variables, since dotnet might
// need them for arbitrary reasons to function correctly. However, we specifically don't
// want to pass through any ASP.NET Core hosting related ones, since the child process
// shouldn't be trying to use the same port numbers, etc. In particular we need to break
// the association with IISExpress and the MS-ASPNETCORE-TOKEN check.
// For more context on this, see https://github.com/dotnet/aspnetcore/issues/20308.
var keysToRemove = environment.Keys.Where(key => key.StartsWith("ASPNETCORE_")).ToList();
foreach (var key in keysToRemove)
{
environment.Remove(key);
}
}

private static string LocateDebugProxyExecutable(IWebHostEnvironment environment)
{
var assembly = Assembly.Load(environment.ApplicationName);
Expand Down