Skip to content

Commit

Permalink
(chocolatey#770) Disable showing of sensitive arguments
Browse files Browse the repository at this point in the history
This commit replaces the values in sensitive arguments to instead show
the translatable string `[REDACTED ARGUMENT]` to ensure that sensitive
arguments are not displayed to the user.

This relies on the ArgumentUtility helper to detect whether the sensitive
argument should be shown or not.
  • Loading branch information
AdmiringWorm committed Jan 24, 2022
1 parent e704b2d commit 0baa8f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,28 @@ public IEnumerable<string> DecryptPackageArgumentsFile(string id, string version
? arguments
: _encryptionUtility.decrypt_string(arguments);

// Lets do a global check first to see if there are any sensitive arguments
// before we filter out the values used later.
var sensitiveArgs = ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted);

var packageArgumentsSplit =
packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries);

foreach (var packageArgument in packageArgumentsSplit.or_empty_list_if_null())
{
var isSensitiveArgument = sensitiveArgs && ArgumentsUtility.arguments_contain_sensitive_information(packageArgument);

var packageArgumentSplit =
packageArgument.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);

var optionName = packageArgumentSplit[0].to_string();
var optionValue = string.Empty;

if (packageArgumentSplit.Length == 2)
if (packageArgumentSplit.Length == 2 && isSensitiveArgument)
{
optionValue = Resources.PackageArgumentService_RedactedArgument;
}
else if (packageArgumentSplit.Length == 2)
{
optionValue = packageArgumentSplit[1].to_string().remove_surrounding_quotes();
if (optionValue.StartsWith("'"))
Expand Down
29 changes: 19 additions & 10 deletions Source/ChocolateyGui.Common/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/ChocolateyGui.Common/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1260,4 +1260,7 @@ Please contact your System Administrator to enable this operation.</value>
<value>Arguments for the Package {0}</value>
<comment>{0} = The Title of the package</comment>
</data>
<data name="PackageArgumentService_RedactedArgument" xml:space="preserve">
<value>[REDACTED ARGUMENT]</value>
</data>
</root>

0 comments on commit 0baa8f4

Please sign in to comment.