Skip to content

Commit afb004a

Browse files
authored
Merge pull request #307 from Icinga:feature/remove_pass_on_string_secure_string_exception
Feature: Removes password on Secure.String exceptions Improves error handling in case of exceptions, which will now remove the arguments and content for passwords, in case `String` is tried to be used for `SecureString` arguments.
2 parents 5012bb2 + 77de548 commit afb004a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

doc/31-Changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1111

1212
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/15?closed=1)
1313

14+
## Enhancements
15+
16+
* [#301](https://github.com/Icinga/icinga-powershell-framework/pull/301) Improves error handling to no longer print passwords in case `String` is used for `SecureString` arguments
1417
* [#305](https://github.com/Icinga/icinga-powershell-framework/pull/305) Adds a new Cmdlet to test if functions with `Add-Type` are already present inside the current scope of the shell
1518
* [#306](https://github.com/Icinga/icinga-powershell-framework/pull/306) Adds new Cmdlet `Exit-IcingaThrowCritical` to throw critical exit with a custom message, either by force or by using string filtering and adds storing of plugin exit codes internally
1619

lib/icinga/plugin/Exit-IcingaExecutePlugin.psm1

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@ function Exit-IcingaExecutePlugin()
1818
} catch {
1919
$ExMsg = $_.Exception.Message;
2020
$StackTrace = $_.ScriptStackTrace;
21+
$ExErrorId = $_.FullyQualifiedErrorId;
22+
$ArgName = $_.Exception.ParameterName;
23+
$ListArgs = $args;
2124

22-
Write-IcingaConsolePlain '[UNKNOWN] Icinga Exception: {0}{1}{1}CheckCommand: {2}{1}Arguments: {3}{1}{1}StackTrace:{1}{4}' -Objects $ExMsg, (New-IcingaNewLine), $Command, $args, $StackTrace;
25+
if ($ExErrorId -Like "*ParameterArgumentTransformationError*" -And $ExMsg.Contains('System.Security.SecureString')) {
26+
$ExMsg = [string]::Format(
27+
'Cannot bind parameter {0}. Cannot convert the provided value for argument "{0}" of type "System.String" to type "System.Security.SecureString".',
28+
$ArgName
29+
);
30+
31+
$args.Clear();
32+
$ListArgs = 'Hidden for security reasons';
33+
}
34+
35+
Write-IcingaConsolePlain '[UNKNOWN] Icinga Exception: {0}{1}{1}CheckCommand: {2}{1}Arguments: {3}{1}{1}StackTrace:{1}{4}' -Objects $ExMsg, (New-IcingaNewLine), $Command, $ListArgs, $StackTrace;
2336
exit 3;
2437
}
2538
}

0 commit comments

Comments
 (0)