diff --git a/src/Runner.Worker/FileCommandManager.cs b/src/Runner.Worker/FileCommandManager.cs index a084a5757..b03c31890 100644 --- a/src/Runner.Worker/FileCommandManager.cs +++ b/src/Runner.Worker/FileCommandManager.cs @@ -141,6 +141,28 @@ namespace GitHub.Runner.Worker var pairs = new EnvFileKeyValuePairs(context, filePath); foreach (var pair in pairs) { + var isBlocked = false; + foreach (var blocked in _setEnvBlockList) + { + if (string.Equals(blocked, pair.Key, StringComparison.OrdinalIgnoreCase)) + { + // Log Telemetry and let user know they shouldn't do this + var issue = new Issue() + { + Type = IssueType.Error, + Message = $"Can't store {blocked} output parameter using '$GITHUB_ENV' command." + }; + issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = $"{Constants.Runner.UnsupportedCommand}_{pair.Key}"; + context.AddIssue(issue, ExecutionContextLogOptions.Default); + + isBlocked = true; + break; + } + } + if (isBlocked) + { + continue; + } SetEnvironmentVariable(context, pair.Key, pair.Value); } } @@ -154,6 +176,11 @@ namespace GitHub.Runner.Worker context.SetEnvContext(name, value); context.Debug($"{name}='{value}'"); } + + private string[] _setEnvBlockList = + { + "NODE_OPTIONS" + }; } public sealed class CreateStepSummaryCommand : RunnerService, IFileCommandExtension diff --git a/src/Test/L0/Worker/SetEnvFileCommandL0.cs b/src/Test/L0/Worker/SetEnvFileCommandL0.cs index 62e8b6b9b..8526c2868 100644 --- a/src/Test/L0/Worker/SetEnvFileCommandL0.cs +++ b/src/Test/L0/Worker/SetEnvFileCommandL0.cs @@ -183,6 +183,47 @@ namespace GitHub.Runner.Common.Tests.Worker } } + + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Worker")] + public void SetEnvFileCommand_BlockListItemsFiltered() + { + using (var hostContext = Setup()) + { + var stateFile = Path.Combine(_rootDirectory, "simple"); + var content = new List + { + "NODE_OPTIONS=asdf", + }; + WriteContent(stateFile, content); + _setEnvFileCommand.ProcessCommand(_executionContext.Object, stateFile, null); + Assert.Equal(1, _issues.Count); + Assert.Equal(0, _executionContext.Object.Global.EnvironmentVariables.Count); + } + } + + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Worker")] + public void SetEnvFileCommand_BlockListItemsFiltered_Heredoc() + { + using (var hostContext = Setup()) + { + var stateFile = Path.Combine(_rootDirectory, "simple"); + var content = new List + { + "NODE_OPTIONS<