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.
This commit is contained in:
Lord Hepipud 2021-07-23 15:43:32 +02:00 committed by GitHub
commit afb004af03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
} }
} }