-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Simple Detections for some common saas (#554)
* Add detections for some SAAS services * Improve comment detection for urls with protocol specification in languages with // as the comment format * Update font awesome reference * Update tagreportgroups.json * Update test cases for multiline strings * Remove unused imports
- Loading branch information
Showing
12 changed files
with
208 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.ApplicationInspector.Logging; | ||
using Microsoft.ApplicationInspector.RulesEngine; | ||
using Microsoft.CST.RecursiveExtractor; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Serilog.Events; | ||
|
||
namespace AppInspector.Tests.RuleProcessor; | ||
|
||
[TestClass] | ||
public class QuotedStringsTests | ||
{ | ||
|
||
private const string testDoubleQuotesAreCode = "var url = \"https://contoso.com\"; // contoso.com"; | ||
private const string testSingleQuotesAreCode = "var url = 'https://contoso.com'; // contoso.com"; | ||
private const string testSingleLineWithQuotesInComment = "// var url = 'https://contoso.com';"; | ||
private const string testSingleLineWithDoubleQuotesInComment = "// var url = 'https://contoso.com';"; | ||
private const string testMultiLine = @"/* | ||
https://contoso.com | ||
*/"; | ||
private const string testMultiLineWithoutProto = @" | ||
/* | ||
contoso.com | ||
*/"; | ||
private const string testMultiLineWithResultFollowingCommentEnd = @" | ||
/* | ||
contoso.com | ||
*/ var url = ""https://contoso.com"""; | ||
|
||
private static string detectContosoRule = @" | ||
[ | ||
{ | ||
""id"": ""RE000001"", | ||
""name"": ""Testing.Rules.Quotes"", | ||
""tags"": [ | ||
""Testing.Rules.Quotes"" | ||
], | ||
""severity"": ""Critical"", | ||
""description"": ""Find contoso.com"", | ||
""patterns"": [ | ||
{ | ||
""pattern"": ""contoso.com"", | ||
""type"": ""regex"", | ||
""confidence"": ""High"", | ||
""scopes"": [ | ||
""code"" | ||
] | ||
} | ||
], | ||
""_comment"": """" | ||
} | ||
] | ||
"; | ||
|
||
private readonly ILoggerFactory _loggerFactory = | ||
new LogOptions { ConsoleVerbosityLevel = LogEventLevel.Verbose }.GetLoggerFactory(); | ||
|
||
private readonly Microsoft.ApplicationInspector.RulesEngine.Languages _languages = new(); | ||
|
||
[DataRow(testDoubleQuotesAreCode,1)] | ||
[DataRow(testSingleQuotesAreCode,1)] | ||
[DataRow(testMultiLine,0)] | ||
[DataRow(testMultiLineWithoutProto,0)] | ||
[DataRow(testMultiLineWithResultFollowingCommentEnd,1)] | ||
[DataRow(testSingleLineWithQuotesInComment,0)] | ||
[DataRow(testSingleLineWithDoubleQuotesInComment,0)] | ||
[DataTestMethod] | ||
public void QuotedStrings(string content, int numIssues) | ||
{ | ||
RuleSet rules = new(_loggerFactory); | ||
rules.AddString(detectContosoRule, "contosorule"); | ||
Microsoft.ApplicationInspector.RulesEngine.RuleProcessor ruleProcessor = | ||
new Microsoft.ApplicationInspector.RulesEngine.RuleProcessor(rules, new RuleProcessorOptions()); | ||
_languages.FromFileNameOut("testfile.cs", out LanguageInfo info); | ||
Assert.AreEqual(numIssues, | ||
ruleProcessor.AnalyzeFile(content, new FileEntry("testfile.cs", new MemoryStream()), info).Count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
[ | ||
{ | ||
"name": "SaaS: Salesforce", | ||
"id": "AI060001", | ||
"description": "SaaS: Salesforce Rest API", | ||
"tags": [ | ||
"CloudServices.Salesforce" | ||
], | ||
"severity": "moderate", | ||
"patterns": [ | ||
{ | ||
"confidence": "high", | ||
"pattern": "my\\.salesforce\\.com", | ||
"type": "regex", | ||
"scopes": [ | ||
"code" | ||
], | ||
"modifiers": [ | ||
"i" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "SaaS: ServiceNow", | ||
"id": "AI060002", | ||
"description": "SaaS: ServiceNow Rest API", | ||
"tags": [ | ||
"CloudServices.ServiceNow" | ||
], | ||
"severity": "moderate", | ||
"patterns": [ | ||
{ | ||
"confidence": "high", | ||
"pattern": "service-now\\.com/api", | ||
"type": "regex", | ||
"scopes": [ | ||
"code" | ||
], | ||
"modifiers": [ | ||
"i" | ||
] | ||
} | ||
] | ||
} | ||
, | ||
{ | ||
"name": "SaaS: WorkDay", | ||
"id": "AI060000", | ||
"description": "SaaS: WorkDay Rest API", | ||
"tags": [ | ||
"CloudServices.WorkDay" | ||
], | ||
"severity": "moderate", | ||
"patterns": [ | ||
{ | ||
"confidence": "high", | ||
"pattern": "workday.com", | ||
"type": "regex", | ||
"scopes": [ | ||
"code" | ||
], | ||
"modifiers": [ | ||
"i" | ||
] | ||
} | ||
] | ||
} | ||
] |