From 178f48403e13f53465cce4659eca52395ef9a595 Mon Sep 17 00:00:00 2001 From: "Yuting Chen[MSFT]" Date: Thu, 16 Apr 2015 17:17:25 -0700 Subject: [PATCH 1/5] Update UseShouldProcessForStateChangingFunctions.cs Remove check for "Get-'" Get does not modify system Status --- Rules/UseShouldProcessForStateChangingFunctions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Rules/UseShouldProcessForStateChangingFunctions.cs b/Rules/UseShouldProcessForStateChangingFunctions.cs index 1c5a204b2..d8bf60c96 100644 --- a/Rules/UseShouldProcessForStateChangingFunctions.cs +++ b/Rules/UseShouldProcessForStateChangingFunctions.cs @@ -44,8 +44,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) string funcName = funcDefAst.Name; bool hasShouldProcessAttribute = false; - if (funcName.StartsWith("Get-", StringComparison.OrdinalIgnoreCase) || - funcName.StartsWith("Stop-", StringComparison.OrdinalIgnoreCase)|| + if (funcName.StartsWith("Stop-", StringComparison.OrdinalIgnoreCase)|| funcName.StartsWith("New-", StringComparison.OrdinalIgnoreCase) || funcName.StartsWith("Set-", StringComparison.OrdinalIgnoreCase) || funcName.StartsWith("Update-", StringComparison.OrdinalIgnoreCase) || From 22af2e87b310973db37642f9c845e652f537226c Mon Sep 17 00:00:00 2001 From: "Yuting Chen[MSFT]" Date: Fri, 17 Apr 2015 10:13:11 -0700 Subject: [PATCH 2/5] Update UseShouldProcessForStateChangingFunctions.md --- RuleDocumentation/UseShouldProcessForStateChangingFunctions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RuleDocumentation/UseShouldProcessForStateChangingFunctions.md b/RuleDocumentation/UseShouldProcessForStateChangingFunctions.md index d500091d0..4ac36a36b 100644 --- a/RuleDocumentation/UseShouldProcessForStateChangingFunctions.md +++ b/RuleDocumentation/UseShouldProcessForStateChangingFunctions.md @@ -3,7 +3,7 @@ ##Description -Functions that have verbs like New, Start, Stop, Set, Reset that change system state should support 'ShouldProcess' +Functions that have verbs like New, Start, Stop, Set, Reset and Restart that change system state should support 'ShouldProcess' ##How to Fix From 1eee6c52ede53d131fe7170ddfe8420b33e52df0 Mon Sep 17 00:00:00 2001 From: Yuting Chen Date: Mon, 20 Apr 2015 14:21:18 -0700 Subject: [PATCH 3/5] Fix AvoidUsingInternalURLs throw warnings at SDDL --- Rules/AvoidUsingInternalURLs.cs | 12 ++++++------ Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1 | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Rules/AvoidUsingInternalURLs.cs b/Rules/AvoidUsingInternalURLs.cs index c165d7672..1ffe1716e 100644 --- a/Rules/AvoidUsingInternalURLs.cs +++ b/Rules/AvoidUsingInternalURLs.cs @@ -13,15 +13,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Management.Automation.Language; using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic; using System.ComponentModel.Composition; -using System.Resources; using System.Globalization; -using System.Threading; -using System.Reflection; using System.IO; namespace Microsoft.Windows.Powershell.ScriptAnalyzer.BuiltinRules @@ -118,7 +113,12 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) } if (!firstPartURL.Contains(".")) { - isInternalURL = true; + //Add a check to exclude potential SDDL format. Check if a string have four components separated by ":" + var count = firstPartURL.Count(x => x == ':'); + if (count !=3 ) + { + isInternalURL = true; + } } } if (isInternalURL) diff --git a/Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1 b/Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1 index 73825de70..cdd8b7cc5 100644 --- a/Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1 +++ b/Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1 @@ -1,3 +1,4 @@ $correctPath = "www.bing.com" $externalSite = "//outside.co/test" -rmdir /s /q ".\Directory" \ No newline at end of file +rmdir /s /q ".\Directory" +$sd = "O:BAG:BAD:(A;;0x800;;;WD)(A;;0x120fff;;;SY)(A;;0x120fff;;;LS)(A;;0x120fff;;;NS)(A;;0x120fff;;;BA)(A;;0xee5;;;LU)(A;;LC;;;MU)(A;;0x800;;;AG)" \ No newline at end of file From 52f882c8eb12ddc930a6bfe7c8cc47bf208e0a81 Mon Sep 17 00:00:00 2001 From: Yuting Chen Date: Mon, 20 Apr 2015 14:57:36 -0700 Subject: [PATCH 4/5] Change count of ":" to more than 3 --- Rules/AvoidUsingInternalURLs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rules/AvoidUsingInternalURLs.cs b/Rules/AvoidUsingInternalURLs.cs index 1ffe1716e..075226b4a 100644 --- a/Rules/AvoidUsingInternalURLs.cs +++ b/Rules/AvoidUsingInternalURLs.cs @@ -115,7 +115,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) { //Add a check to exclude potential SDDL format. Check if a string have four components separated by ":" var count = firstPartURL.Count(x => x == ':'); - if (count !=3 ) + if (count > 3 ) { isInternalURL = true; } From eb7c565c03a782d0629d3f31de071e48db946171 Mon Sep 17 00:00:00 2001 From: Yuting Chen Date: Mon, 20 Apr 2015 14:59:25 -0700 Subject: [PATCH 5/5] Change column count to 3 and 4. --- Rules/AvoidUsingInternalURLs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rules/AvoidUsingInternalURLs.cs b/Rules/AvoidUsingInternalURLs.cs index 075226b4a..1a5db9ef3 100644 --- a/Rules/AvoidUsingInternalURLs.cs +++ b/Rules/AvoidUsingInternalURLs.cs @@ -115,7 +115,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) { //Add a check to exclude potential SDDL format. Check if a string have four components separated by ":" var count = firstPartURL.Count(x => x == ':'); - if (count > 3 ) + if (count == 3 || count == 4 ) { isInternalURL = true; }