Bring back logic to remove unwanted env variables (#20326)

This commit is contained in:
Safia Abdalla 2020-03-30 12:34:19 -07:00 committed by GitHub
parent df1252a3f8
commit cba5387f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Builder
UseShellExecute = false,
RedirectStandardOutput = true,
};
RemoveUnwantedEnvironmentVariables(processStartInfo.Environment);
var debugProxyProcess = Process.Start(processStartInfo);
CompleteTaskWhenServerIsReady(debugProxyProcess, tcs);
@ -64,6 +65,21 @@ namespace Microsoft.AspNetCore.Builder
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);