You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rules that return a long extent property (as e.g. a [ScriptBlock] expression) often have no RuleSuppressionID
Which means that one isn't able to suppress that specific warning (by RuleSuppressionID) and still validate similar occurences with a differed RuleSuppressionID.
Purposed solution
When a (custom) rule doesn't return a RuleSuppressionID the engine could technically always add a unique RuleSuppressionID by fabricating (and validating) one using the hashcode of the returned Extent.Text.
Basically:
(Invoke-ScriptAnalyzer .\MyScript.ps1).foreach{
if (-not$_.RuleSuppressionID) { $_.RuleSuppressionID=$_.Extent.Text.GetHashCode() }; $_
} |Select-Object*
Line : 64
Column : 71
Message : Possible script injection risk via the a dangerous method. Untrusted input can cause arbitrary PowerShell expressions to be run. The PowerShell.AddCommand().AddParameter() APIs should be used instead.
Extent : [ScriptBlock]::Create($Expression)
RuleName : InjectionRisk.Create
Severity : Warning
ScriptName : Update-Accessor.ps1
ScriptPath : C:\Users\Gebruiker\My Drive\Scripts\PowerShell\Update-Accessor\Update-Accessor.ps1
RuleSuppressionID : 227051976
SuggestedCorrections :
IsSuppressed : False
The text was updated successfully, but these errors were encountered:
I disagree, the custom rule needs to return the id. PSSA should not auto-generate them because if that ever has to change, one cannot change it because people already rely on that.
Good point.
Aside from this, I don't thick that using the GetHashCode() method for this is a good idea as it might return different values for the same string content #46406.
For something like this it is probably better to create a MD5 hash and also consider the case (.toUpper()) and diacritics.
I have closed this issue and create a new request for a rule to check for a dynamic RuleSuppressionID (#1964)
Uh oh!
There was an error while loading. Please reload this page.
Rules that return a long
extent
property (as e.g. a[ScriptBlock]
expression) often have noRuleSuppressionID
Which means that one isn't able to suppress that specific warning (by
RuleSuppressionID
) and still validate similar occurences with a differedRuleSuppressionID
.Purposed solution
When a (custom) rule doesn't return a
RuleSuppressionID
the engine could technically always add a uniqueRuleSuppressionID
by fabricating (and validating) one using the hashcode of the returnedExtent.Text
.Basically:
The text was updated successfully, but these errors were encountered: