Skip to content

Commit

Permalink
Asset fingerprint (#276)
Browse files Browse the repository at this point in the history
* Provide an asset fingerprint.

* Updating tests and adding platform to sql and mysql

* updating tests

* Improving asset platform and updating tests

Co-authored-by: Michael Fanning <[email protected]>
  • Loading branch information
eddynaka and michaelcfanning authored Mar 9, 2021
1 parent ec93a4f commit 9780de1
Show file tree
Hide file tree
Showing 63 changed files with 417 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
{
Id = id,
Key = key,
Platform = nameof(AssetPlatform.Google),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_003.GoogleApiKeyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
Key = matchedPattern,
Platform = nameof(AssetPlatform.Google),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
{
Id = id,
Key = key,
Platform = nameof(AssetPlatform.Facebook),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_005.SlackTokenValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
Key = matchedPattern,
Platform = nameof(AssetPlatform.Slack),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_006.GitHubPatValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
PersonalAccessToken = pat,
Platform = nameof(AssetPlatform.GitHub),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
{
Id = id,
Key = key,
Platform = nameof(AssetPlatform.GitHub),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_008.AwsCredentialsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
{
Id = id,
Key = key,
Platform = nameof(AssetPlatform.Aws),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
{
Id = id,
Key = key,
Platform = nameof(AssetPlatform.LinkedIn),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_010.SquarePatValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
PersonalAccessToken = key,
Platform = nameof(AssetPlatform.Square),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
{
Id = id,
Key = key,
Platform = nameof(AssetPlatform.Square),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_012.SlackWebhookValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
Uri = matchedPattern,
Platform = nameof(AssetPlatform.Slack),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint()
{
Key = key,
Platform = nameof(AssetPlatform.Facebook),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint()
{
Resource = matchedPattern,
Platform = nameof(AssetPlatform.Google),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_016.StripeApiKeyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
Key = key,
Platform = nameof(AssetPlatform.Stripe),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_017.NpmAuthorTokenValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
Key = key,
Platform = nameof(AssetPlatform.Npm),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprintText = new Fingerprint
{
Key = key,
Platform = nameof(AssetPlatform.Aws),
}.ToString();

return nameof(ValidationState.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
if (groups.ContainsKey("host") && groups.ContainsKey("database") && groups.ContainsKey("account") && groups.ContainsKey("password"))
{
host = groups["host"];
database = groups["database"];
account = groups["account"];
database = groups["database"];
password = groups["password"];
}
else
{
host = ParseExpression(RegexEngine, matchedPattern, HostExpression);
database = ParseExpression(RegexEngine, matchedPattern, DatabaseExpression);
account = ParseExpression(RegexEngine, matchedPattern, AccountExpression);
database = ParseExpression(RegexEngine, matchedPattern, DatabaseExpression);
password = ParseExpression(RegexEngine, matchedPattern, PasswordExpression);
}

Expand Down Expand Up @@ -119,6 +119,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
Resource = database,
Account = account,
Password = password,
Platform = SharedUtilities.GetDatabasePlatformFromHost(host, out _),
}.ToString();

return nameof(ValidationState.Unknown);
Expand All @@ -141,7 +142,7 @@ protected override string IsValidDynamicHelper(ref string fingerprintText,

string connString =
$"Server={host};Initial Catalog={database};User ID={account};Password={password};" +
"Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
"Trusted_Connection=False;Encrypt=True;Connection Timeout=3;";
message = $"the '{account}' account was authenticated against database '{database}' hosted on '{host}'";

// Validating ConnectionString with database.
Expand All @@ -153,7 +154,7 @@ protected override string IsValidDynamicHelper(ref string fingerprintText,

connString =
$"Server={host};User ID={account};Password={password};" +
"Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
"Trusted_Connection=False;Encrypt=True;Connection Timeout=3;";
message = $"the '{account}' account is compromised for server '{host}'";

// Validating ConnectionString without database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected override string IsValidStaticHelper(ref string matchedPattern,
fingerprint.Host = host.Replace("\"", string.Empty).Replace(",", ";");
fingerprint.Resource = database;
fingerprint.Port = port;
fingerprint.Platform = SharedUtilities.GetDatabasePlatformFromHost(fingerprint.Host, out _);

fingerprintText = fingerprint.ToString();

Expand Down
1 change: 1 addition & 0 deletions Src/Plugins/Security/SEC101_102.AdoPatValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static string IsValidStatic(ref string matchedPattern,
fingerprintText = new Fingerprint()
{
PersonalAccessToken = pat,
Platform = nameof(AssetPlatform.AzureDevOps),
}.ToString();
}

Expand Down
Loading

0 comments on commit 9780de1

Please sign in to comment.