-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixed a bug where a misplaced = character could bypass heredoc-style processing.
#2627
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
Changes from all commits
d8a5087
bad293e
a5f4798
a57a564
a9c11f3
ada17f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,7 +281,7 @@ public void ProcessCommand(IExecutionContext context, string filePath, Container | |
| } | ||
| } | ||
|
|
||
| public sealed class EnvFileKeyValuePairs: IEnumerable<KeyValuePair<string, string>> | ||
| public sealed class EnvFileKeyValuePairs : IEnumerable<KeyValuePair<string, string>> | ||
| { | ||
| private IExecutionContext _context; | ||
| private string _filePath; | ||
|
|
@@ -322,21 +322,9 @@ public IEnumerator<KeyValuePair<string, string>> GetEnumerator() | |
| var equalsIndex = line.IndexOf("=", StringComparison.Ordinal); | ||
| var heredocIndex = line.IndexOf("<<", StringComparison.Ordinal); | ||
|
|
||
| // Normal style NAME=VALUE | ||
| if (equalsIndex >= 0 && (heredocIndex < 0 || equalsIndex < heredocIndex)) | ||
| { | ||
| var split = line.Split(new[] { '=' }, 2, StringSplitOptions.None); | ||
| if (string.IsNullOrEmpty(line)) | ||
| { | ||
| throw new Exception($"Invalid format '{line}'. Name must not be empty"); | ||
| } | ||
|
|
||
| key = split[0]; | ||
| output = split[1]; | ||
| } | ||
|
|
||
| // Heredoc style NAME<<EOF | ||
| else if (heredocIndex >= 0 && (equalsIndex < 0 || heredocIndex < equalsIndex)) | ||
| // Heredoc style NAME<<EOF (where EOF is typically randomly-generated Base64 and may include an '=' character) | ||
| // see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings | ||
| if (heredocIndex >= 0 && (equalsIndex < 0 || heredocIndex < equalsIndex)) | ||
| { | ||
| var split = line.Split(new[] { "<<" }, 2, StringSplitOptions.None); | ||
| if (string.IsNullOrEmpty(split[0]) || string.IsNullOrEmpty(split[1])) | ||
|
|
@@ -364,6 +352,18 @@ public IEnumerator<KeyValuePair<string, string>> GetEnumerator() | |
|
|
||
| output = endIndex > startIndex ? text.Substring(startIndex, endIndex - startIndex) : string.Empty; | ||
| } | ||
| // Normal style NAME=VALUE | ||
| else if (equalsIndex >= 0 && heredocIndex < 0) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we can be stricter here: Note that we're now checking: whereas before it was: |
||
| { | ||
| var split = line.Split(new[] { '=' }, 2, StringSplitOptions.None); | ||
| if (string.IsNullOrEmpty(line)) | ||
| { | ||
| throw new Exception($"Invalid format '{line}'. Name must not be empty"); | ||
| } | ||
|
|
||
| key = split[0]; | ||
| output = split[1]; | ||
| } | ||
| else | ||
| { | ||
| throw new Exception($"Invalid format '{line}'"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ public void CreateStepSummaryCommand_Simple() | |
| "", | ||
| "## This is more markdown content", | ||
| }; | ||
| WriteContent(stepSummaryFile, content); | ||
| TestUtil.WriteContent(stepSummaryFile, content); | ||
|
|
||
| _createStepCommand.ProcessCommand(_executionContext.Object, stepSummaryFile, null); | ||
| _jobExecutionContext.Complete(); | ||
|
|
@@ -153,7 +153,7 @@ public void CreateStepSummaryCommand_ScrubSecrets() | |
| "", | ||
| "# GITHUB_TOKEN ghs_verysecuretoken", | ||
| }; | ||
| WriteContent(stepSummaryFile, content); | ||
| TestUtil.WriteContent(stepSummaryFile, content); | ||
|
|
||
| _createStepCommand.ProcessCommand(_executionContext.Object, stepSummaryFile, null); | ||
|
|
||
|
|
@@ -167,21 +167,6 @@ public void CreateStepSummaryCommand_ScrubSecrets() | |
| } | ||
| } | ||
|
|
||
| private void WriteContent( | ||
| string path, | ||
| List<string> content, | ||
| string newline = null) | ||
| { | ||
| if (string.IsNullOrEmpty(newline)) | ||
| { | ||
| newline = Environment.NewLine; | ||
| } | ||
|
|
||
| var encoding = new UTF8Encoding(true); // Emit BOM | ||
| var contentStr = string.Join(newline, content); | ||
| File.WriteAllText(path, contentStr, encoding); | ||
| } | ||
|
Comment on lines
-170
to
-183
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were four verbatim copies of this method floating around, so I defined it once-and-only-once in TestUtil.cs. I also dropped the ability to pass an arbitrary string in as a newline. (Several tests were passing a single SPACE which was such a subtle difference that it made it really hard to decipher why two seemingly-identical tests would behave differently.) The new version in |
||
|
|
||
| private TestHostContext Setup([CallerMemberName] string name = "") | ||
| { | ||
| var hostContext = new TestHostContext(this, 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 basically just swapped the order of this conditional and the
else ifthat follows it.