Skip to content
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
39 changes: 31 additions & 8 deletions src/Runner.Worker/ActionCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void ProcessCommand(IExecutionContext context, string line, ActionCommand
{
var configurationStore = HostContext.GetService<IConfigurationStore>();
var isHostedServer = configurationStore.GetSettings().IsHostedServer;

var allowUnsecureCommands = false;
bool.TryParse(Environment.GetEnvironmentVariable(Constants.Variables.Actions.AllowUnsupportedCommands), out allowUnsecureCommands);

Expand All @@ -209,9 +209,9 @@ public void ProcessCommand(IExecutionContext context, string line, ActionCommand
else if (!allowUnsecureCommands)
{
// Log Telemetry and let user know they shouldn't do this
var issue = new Issue()
{
Type = IssueType.Warning,
var issue = new Issue()
{
Type = IssueType.Error,
Message = String.Format(Constants.Runner.UnsupportedCommandMessage, this.Command)
};
issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = Constants.Runner.UnsupportedCommand;
Expand All @@ -223,6 +223,24 @@ public void ProcessCommand(IExecutionContext context, string line, ActionCommand
throw new Exception("Required field 'name' is missing in ##[set-env] command.");
}


foreach (var blocked in _setEnvBlockList)
{
if (string.Equals(blocked, envName, StringComparison.OrdinalIgnoreCase))
{
// Log Telemetry and let user know they shouldn't do this
var issue = new Issue()
{
Type = IssueType.Error,
Message = $"Can't update {blocked} environment variable using ::set-env:: command."
};
issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = $"{Constants.Runner.UnsupportedCommand}_{envName}";
context.AddIssue(issue);

return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this return; statement was surprising to me to read at first.

I'm guessing that if we ever add more items to _setEnvBlockList, we want the runner to report an error on the first offending env var, instead of all of them, @TingluoHuang?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just want to make sure we don't run

context.Global.EnvironmentVariables[envName] = command.Data;
context.SetEnvContext(envName, command.Data);
context.Debug($"{envName}='{command.Data}'");

}
}

context.Global.EnvironmentVariables[envName] = command.Data;
context.SetEnvContext(envName, command.Data);
context.Debug($"{envName}='{command.Data}'");
Expand All @@ -232,6 +250,11 @@ private static class SetEnvCommandProperties
{
public const String Name = "name";
}

private string[] _setEnvBlockList =
{
"NODE_OPTIONS"
};
}

public sealed class SetOutputCommandExtension : RunnerService, IActionCommandExtension
Expand Down Expand Up @@ -319,7 +342,7 @@ public void ProcessCommand(IExecutionContext context, string line, ActionCommand
{
var configurationStore = HostContext.GetService<IConfigurationStore>();
var isHostedServer = configurationStore.GetSettings().IsHostedServer;

var allowUnsecureCommands = false;
bool.TryParse(Environment.GetEnvironmentVariable(Constants.Variables.Actions.AllowUnsupportedCommands), out allowUnsecureCommands);

Expand All @@ -342,9 +365,9 @@ public void ProcessCommand(IExecutionContext context, string line, ActionCommand
else if (!allowUnsecureCommands)
{
// Log Telemetry and let user know they shouldn't do this
var issue = new Issue()
{
Type = IssueType.Warning,
var issue = new Issue()
{
Type = IssueType.Error,
Message = String.Format(Constants.Runner.UnsupportedCommandMessage, this.Command)
};
issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = Constants.Runner.UnsupportedCommand;
Expand Down