Removes password on secure.string exceptions

This commit is contained in:
Lord Hepipud 2021-07-16 13:15:21 +02:00
parent 5012bb29b3
commit 77de5485a1
2 changed files with 17 additions and 1 deletions

View file

@ -11,6 +11,9 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/15?closed=1) [Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/15?closed=1)
## Enhancements
* [#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
* [#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 * [#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
* [#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 * [#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

View file

@ -18,8 +18,21 @@ function Exit-IcingaExecutePlugin()
} catch { } catch {
$ExMsg = $_.Exception.Message; $ExMsg = $_.Exception.Message;
$StackTrace = $_.ScriptStackTrace; $StackTrace = $_.ScriptStackTrace;
$ExErrorId = $_.FullyQualifiedErrorId;
$ArgName = $_.Exception.ParameterName;
$ListArgs = $args;
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; if ($ExErrorId -Like "*ParameterArgumentTransformationError*" -And $ExMsg.Contains('System.Security.SecureString')) {
$ExMsg = [string]::Format(
'Cannot bind parameter {0}. Cannot convert the provided value for argument "{0}" of type "System.String" to type "System.Security.SecureString".',
$ArgName
);
$args.Clear();
$ListArgs = 'Hidden for security reasons';
}
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;
exit 3; exit 3;
} }
} }