Skip to content

Commit 07778e4

Browse files
Revert "Deactivate Base64 Encoded Vso Commands AB#2008236 (#5158)" (#5232)
This reverts commit bc979be.
1 parent 9c887e9 commit 07778e4

File tree

3 files changed

+3
-118
lines changed

3 files changed

+3
-118
lines changed

src/Agent.Sdk/Util/StringUtil.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ public static bool AreHashesEqual(string leftValue, string rightValue)
282282

283283
/// <summary>
284284
/// Finds all vso commands in the line and deactivates them
285-
/// Also, assuming line to be base64 encoded, finds all vso commands in the decoded string and deactivates them and re-encode
286285
/// </summary>
287286
/// <returns>String without vso commands that can be executed</returns>
288287
public static string DeactivateVsoCommands(string input)
@@ -292,41 +291,6 @@ public static string DeactivateVsoCommands(string input)
292291
return string.Empty;
293292
}
294293

295-
try
296-
{
297-
input = DeactivateVsoCommandsIfBase64Encoded(input);
298-
}
299-
catch (FormatException)
300-
{
301-
// Ignore exception and continue to deactivate vso commands in the input string.
302-
}
303-
return ScrapVsoCommands(input);
304-
}
305-
306-
/// <summary>
307-
/// Tries to decode the input string assuming it to be base64 encoded and
308-
/// scraps vso command if any and re-encodes the updated string.
309-
/// An exception is thrown for the case when the input is not base64 encoded.
310-
/// </summary>
311-
/// <returns>String without vso commands that can be executed</returns>
312-
public static string DeactivateVsoCommandsIfBase64Encoded(string input)
313-
{
314-
if (input == null)
315-
{
316-
throw new ArgumentNullException(nameof(input), "Input string cannot be null.");
317-
}
318-
if (input.Length == 0)
319-
{
320-
return string.Empty;
321-
}
322-
byte[] decodedBytes = Convert.FromBase64String(input);
323-
string decodedString = Encoding.UTF8.GetString(decodedBytes);
324-
decodedString = ScrapVsoCommands(decodedString);
325-
return Convert.ToBase64String(Encoding.UTF8.GetBytes(decodedString));
326-
}
327-
328-
private static string ScrapVsoCommands(string input)
329-
{
330294
return Regex.Replace(input, "##vso", "**vso", RegexOptions.IgnoreCase);
331295
}
332296
}

src/Test/L0/Util/StringUtilL0.cs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.VisualStudio.Services.Agent.Util;
5-
using System;
6-
using System.Text;
75
using System.Globalization;
86
using Xunit;
97

@@ -24,66 +22,14 @@ public class StringUtilL0
2422
[InlineData("##VsO", "**vso")]
2523
[InlineData("", "")]
2624
[InlineData(null, "")]
27-
[InlineData(" ", "")]
25+
[InlineData(" ", " ")]
2826
public void DeactivateVsoCommandsFromStringTest(string input, string expected)
2927
{
3028
var result = StringUtil.DeactivateVsoCommands(input);
3129

3230
Assert.Equal(expected, result);
3331
}
3432

35-
/// <summary>
36-
/// In this test, a vso command is encoded as a bse64 string and being passed as input to the DeactivateBase64EncodedVsoCommands
37-
/// The returned string when decoded will have ## replaced with **, deactivating the vso command.
38-
/// </summary>
39-
[Fact]
40-
[Trait("Level", "L0")]
41-
[Trait("Category", "Common")]
42-
public void DeactivateVsoCommandsIfBase64Encoded_EncodedVsoCommands_Returns_DeactivatedVsoCommands()
43-
{
44-
string vsoCommand = "##vso[task.setvariable variable=downloadUrl]https://www.evil.com";
45-
string encodedVsoCommand = Convert.ToBase64String(Encoding.UTF8.GetBytes(vsoCommand));
46-
47-
string result = StringUtil.DeactivateVsoCommandsIfBase64Encoded(encodedVsoCommand);
48-
49-
string deactivatedVsoCommand = "**vso[task.setvariable variable=downloadUrl]https://www.evil.com";
50-
var expected = Convert.ToBase64String(Encoding.UTF8.GetBytes(deactivatedVsoCommand));
51-
52-
Assert.Equal(expected, result);
53-
}
54-
55-
/// <summary>
56-
/// In this test, a vso command is being passed as input to the DeactivateBase64EncodedVsoCommands
57-
/// The unmodified string would be returned.
58-
/// </summary>
59-
[Fact]
60-
[Trait("Level", "L0")]
61-
[Trait("Category", "Common")]
62-
public void DeactivateVsoCommandsIfBase64Encoded_NotEncodedVsoCommands_Throws_FormatException()
63-
{
64-
string vsoCommand = "##vso[task.setvariable variable=downloadUrl]https://www.evil.com";
65-
Assert.Throws<FormatException>(() => StringUtil.DeactivateVsoCommandsIfBase64Encoded(vsoCommand));
66-
}
67-
68-
[Fact]
69-
[Trait("Level", "L0")]
70-
[Trait("Category", "Common")]
71-
public void DeactivateVsoCommandsIfBase64Encoded_InputEmpty_Returns_UnmodifiedString()
72-
{
73-
string vsoCommand = "";
74-
string result = StringUtil.DeactivateVsoCommandsIfBase64Encoded(vsoCommand);
75-
Assert.Equal(vsoCommand, result);
76-
}
77-
78-
[Fact]
79-
[Trait("Level", "L0")]
80-
[Trait("Category", "Common")]
81-
public void DeactivateVsoCommandsIfBase64Encoded_InputNull_Throws_Exception()
82-
{
83-
string vsoCommand = null;
84-
Assert.Throws<ArgumentNullException>(() => StringUtil.DeactivateVsoCommandsIfBase64Encoded(vsoCommand));
85-
}
86-
8733
[Fact]
8834
[Trait("Level", "L0")]
8935
[Trait("Category", "Common")]

src/Test/L0/Worker/WorkerL0.cs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Xunit;
1212
using Microsoft.VisualStudio.Services.WebApi;
1313
using Pipelines = Microsoft.TeamFoundation.DistributedTask.Pipelines;
14-
using System.Text;
1514

1615
namespace Microsoft.VisualStudio.Services.Agent.Tests.Worker
1716
{
@@ -296,37 +295,13 @@ public void VerifyJobRequestMessageVsoCommandsDeactivatedIfVariableCasesHandlesN
296295

297296
message.Variables[Constants.Variables.Build.SourceVersionMessage] = "";
298297
message.Variables[Constants.Variables.System.SourceVersionMessage] = null;
299-
message.Variables[Constants.Variables.Build.DefinitionName] = "";
298+
message.Variables[Constants.Variables.Build.DefinitionName] = " ";
300299

301300
var scrubbedMessage = WorkerUtilities.DeactivateVsoCommandsFromJobMessageVariables(message);
302301

303302
Assert.Equal("", scrubbedMessage.Variables[Constants.Variables.Build.SourceVersionMessage]);
304303
Assert.Equal("", scrubbedMessage.Variables[Constants.Variables.System.SourceVersionMessage]);
305-
Assert.Equal("", scrubbedMessage.Variables[Constants.Variables.Build.DefinitionName]);
306-
}
307-
308-
309-
[Fact]
310-
[Trait("Level", "L0")]
311-
[Trait("Category", "Worker")]
312-
public void VerifyJobRequestMessageVsoCommandsDeactivatedIfVariableCasesHandlesBase64EncodedVsoCommands()
313-
{
314-
Pipelines.AgentJobRequestMessage message = CreateJobRequestMessage("jobWithVsoCommands");
315-
// Set up
316-
// A build variable is assigned a VSO command encoded as base 64 string
317-
string vsoCommand = "##vso[task.setvariable variable=downloadUrl]https://www.evil.com";
318-
string encodedVsoCommand = Convert.ToBase64String(Encoding.UTF8.GetBytes(vsoCommand));
319-
message.Variables[Constants.Variables.Build.SourceVersionMessage] = encodedVsoCommand;
320-
321-
// Act
322-
var scrubbedMessage = WorkerUtilities.DeactivateVsoCommandsFromJobMessageVariables(message);
323-
324-
// Expected
325-
// Returned string in it's decode form would have ## replaced with ** to deactivate vso command
326-
string deactivatedVsoCommand = "**vso[task.setvariable variable=downloadUrl]https://www.evil.com";
327-
string expected = Convert.ToBase64String(Encoding.UTF8.GetBytes(deactivatedVsoCommand));
328-
329-
Assert.Equal(expected, scrubbedMessage.Variables[Constants.Variables.Build.SourceVersionMessage]);
304+
Assert.Equal(" ", scrubbedMessage.Variables[Constants.Variables.Build.DefinitionName]);
330305
}
331306

332307
private bool IsMessageIdentical(Pipelines.AgentJobRequestMessage source, Pipelines.AgentJobRequestMessage target)

0 commit comments

Comments
 (0)