FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Simplify Logic in RedactIfPowerShellCode internal method · PowerShell/PowerShell@afa9957 · GitHub

Repository navigation

Commit afa9957

Browse files
committed
Simplify Logic in RedactIfPowerShellCode internal method
1 parent 88d325f commit afa9957

1 file changed

Lines changed: 4 additions & 35 deletions

File tree

‎src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs‎

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,47 +1404,16 @@ internal static string RedactIfPowerShellCode(string input)
14041404
return input;
14051405
}
14061406

1407-
bool startsWithDangerousToken =
1407+
bool startsWithOrContainsDangerousToken =
14081408
input.StartsWith('$') ||
14091409
input.StartsWith("@{") ||
14101410
input.StartsWith('(') ||
14111411
input.StartsWith('"') ||
1412-
input.StartsWith("'") ||
14131412
input.StartsWith('@') ||
1414-
input.StartsWith('\'');
1413+
input.StartsWith('\'') ||
1414+
input.Contains('$');
14151415

1416-
if (startsWithDangerousToken)
1417-
{
1418-
// TODO add a debug message
1419-
return "REDACTED";
1420-
}
1421-
1422-
var ast = Parser.ParseInput(
1423-
input.ToString(),
1424-
out Token[] _,
1425-
out ParseError[] errors);
1426-
1427-
if (errors.Length > 0)
1428-
{
1429-
return input;
1430-
}
1431-
1432-
bool containsCode = false;
1433-
// we leave out n is CommandAst from here as to allow VMNames like svr19 to pass through without being redacted.
1434-
// Also could have used .Any() from Linq but I couldn't get that working.
1435-
foreach (var node in ast.FindAll(
1436-
n =>
1437-
n is VariableExpressionAst ||
1438-
n is ExpandableStringExpressionAst ||
1439-
n is SubExpressionAst,
1440-
true))
1441-
{
1442-
containsCode = true;
1443-
// TODO add a debug message
1444-
break;
1445-
}
1446-
1447-
return containsCode
1416+
return startsWithOrContainsDangerousToken
14481417
? "REDACTED"
14491418
: input;
14501419
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL