-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from instriq/develop
Version 0.1.0
- Loading branch information
Showing
16 changed files
with
273 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ name: Linter | |
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
pull_request: | ||
branches: | ||
|
@@ -17,4 +18,4 @@ jobs: | |
- name: Run Perl::Critic | ||
uses: natanlao/[email protected] | ||
with: | ||
files: critic | ||
files: critic |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
severity = 4 | ||
severity = 3 | ||
|
||
[-TestingAndDebugging::RequireUseStrict] | ||
[-TestingAndDebugging::RequireUseWarnings] | ||
[-TestingAndDebugging::RequireUseWarnings] |
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 |
---|---|---|
|
@@ -40,4 +40,4 @@ runs: | |
--critical $MAX_CRITICAL \ | ||
--high $MAX_HIGH \ | ||
--medium $MAX_MEDIUM \ | ||
--low $MAX_LOW | ||
--low $MAX_LOW |
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,59 @@ | ||
package SecurityGate::Engine::Code { | ||
use strict; | ||
use warnings; | ||
use Mojo::UserAgent; | ||
use Mojo::JSON; | ||
|
||
sub new { | ||
my ($class, $token, $repository, $severity_limits) = @_; | ||
my $alerts_endpoint = "https://api.github.com/repos/$repository/code-scanning/alerts"; | ||
|
||
my $userAgent = Mojo::UserAgent -> new(); | ||
my $alerts_request = $userAgent -> get($alerts_endpoint, {Authorization => "Bearer $token"}) -> result(); | ||
|
||
if ($alerts_request -> code() == 200) { | ||
my $alerts_data = $alerts_request -> json(); | ||
my $open_alerts = 0; | ||
my %severity_counts = map {$_ => 0} keys %$severity_limits; | ||
|
||
foreach my $alert (@$alerts_data) { | ||
if ($alert -> {state} eq "open") { | ||
$open_alerts++; | ||
|
||
my $severity = $alert -> {rule} -> {severity}; | ||
$severity_counts{$severity}++ if exists $severity_counts{$severity}; | ||
} | ||
} | ||
|
||
print "[!] Total of open code scanning alerts: $open_alerts\n"; | ||
|
||
foreach my $severity (keys %severity_counts) { | ||
print "[-] $severity: $severity_counts{$severity}\n"; | ||
} | ||
|
||
my $threshold_exceeded = 0; | ||
|
||
foreach my $severity (keys %severity_counts) { | ||
if ($severity_counts{$severity} > $severity_limits -> {$severity}) { | ||
print "[+] More than $severity_limits->{$severity} $severity code scanning alerts found.\n"; | ||
|
||
$threshold_exceeded = 1; | ||
} | ||
} | ||
|
||
if ($threshold_exceeded) { | ||
return 1; | ||
} | ||
} | ||
|
||
else { | ||
print "Error: Unable to fetch code scanning alerts. HTTP status code: " . $alerts_request -> code() . "\n"; | ||
|
||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
1; |
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,57 @@ | ||
package SecurityGate::Engine::Dependencies { | ||
use strict; | ||
use warnings; | ||
use Mojo::UserAgent; | ||
use Mojo::JSON; | ||
use Exporter 'import'; | ||
|
||
our @EXPORT_OK = qw(@SEVERITIES); | ||
our @SEVERITIES = ("critical", "high", "medium", "low"); | ||
|
||
sub new { | ||
my ($class, $token, $repository, $severity_limits) = @_; | ||
|
||
my %severity_counts = map { $_ => 0 } @SEVERITIES; | ||
|
||
my $endpoint = "https://api.github.com/repos/$repository/dependabot/alerts"; | ||
my $userAgent = Mojo::UserAgent -> new(); | ||
my $request = $userAgent -> get($endpoint, {Authorization => "Bearer $token"}) -> result(); | ||
|
||
if ($request -> code() == 200) { | ||
my $data = $request -> json(); | ||
|
||
foreach my $alert (@$data) { | ||
if ($alert -> {state} eq "open") { | ||
my $severity = $alert -> {security_vulnerability} -> {severity}; | ||
$severity_counts{$severity}++; | ||
} | ||
} | ||
|
||
print "[!] Total of security alerts:\n\n"; | ||
|
||
foreach my $severity (@SEVERITIES) { | ||
print "[-] $severity: $severity_counts{$severity}\n"; | ||
} | ||
|
||
print "\n"; | ||
|
||
my $threshold_exceeded = 0; | ||
|
||
foreach my $severity (@SEVERITIES) { | ||
if ($severity_counts{$severity} > $severity_limits -> {$severity}) { | ||
print "[+] More than $severity_limits->{$severity} $severity security alerts found.\n"; | ||
$threshold_exceeded = 1; | ||
} | ||
} | ||
|
||
return $threshold_exceeded; | ||
} | ||
|
||
else { | ||
print "Error: Unable to fetch alerts. HTTP status code: " . $request -> code() . "\n"; | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
1; |
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,65 @@ | ||
package SecurityGate::Engine::Secrets { | ||
use strict; | ||
use warnings; | ||
use Mojo::UserAgent; | ||
use Mojo::JSON; | ||
|
||
sub new { | ||
my ($class, $token, $repository) = @_; | ||
|
||
my $endpoint = "https://api.github.com/repos/$repository/secret-scanning/alerts"; | ||
my $userAgent = Mojo::UserAgent -> new(); | ||
my $request = $userAgent -> get($endpoint, {Authorization => "Bearer $token"}) -> result(); | ||
|
||
if ($request -> code() == 200) { | ||
my $data = $request -> json(); | ||
my $open_alerts = 0; | ||
my @alert_details; | ||
|
||
foreach my $alert (@$data) { | ||
if ($alert -> {state} eq "open") { | ||
$open_alerts++; | ||
|
||
my $locations_endpoint = "https://api.github.com/repos/$repository/secret-scanning/alerts/$alert -> {number}/locations"; | ||
my $locations_request = $userAgent -> get($locations_endpoint, {Authorization => "Bearer $token"}) -> result(); | ||
|
||
if ($locations_request -> code() == 200) { | ||
my $locations = $locations_request -> json(); | ||
|
||
push @alert_details, { | ||
alert_number => $alert -> {number}, | ||
locations => $locations, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
if ($open_alerts > 0) { | ||
print "[!] Total of open secret scanning alerts: $open_alerts\n"; | ||
|
||
foreach my $detail (@alert_details) { | ||
print "[-] Alert $detail -> {alert_number} found in the following locations:\n"; | ||
|
||
foreach my $location (@{$detail -> {locations}}) { | ||
print " File: $location -> {path}, Start line: $location -> {start_line}\n"; | ||
} | ||
} | ||
|
||
print "[+] Secret scanning alert(s) found. Blocking pipeline.\n"; | ||
return 1; | ||
} | ||
|
||
else { | ||
print "[-] No secret scanning alerts found.\n"; | ||
return 0; | ||
} | ||
} | ||
|
||
else { | ||
print "Error: Unable to fetch secret scanning alerts. HTTP status code: " . $request -> code() . "\n"; | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
1; |
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,24 @@ | ||
package SecurityGate::Utils::Helper { | ||
use strict; | ||
use warnings; | ||
|
||
sub new { | ||
return " | ||
\rSecurity Gate v0.1.0 | ||
\rCore Commands | ||
\r==================== | ||
\r\tCommand Description | ||
\r\t------- ----------- | ||
\r\t-t, --token GitHub token | ||
\r\t-r, --repo GitHub repository, organization/repository-name | ||
\r\t-c, --critical Critical severity limit | ||
\r\t-h, --high High severity limit | ||
\r\t-m, --medium Medium severity limit | ||
\r\t-l, --low Low severity limit | ||
\r\t--dependency-alerts Check for dependency alerts | ||
\r\t--secret-alerts Check for secret scanning alerts | ||
\r\t--code-alerts Check for code scanning alerts\n\n"; | ||
} | ||
} | ||
|
||
1; |
Oops, something went wrong.