Skip to content

Commit 165b28e

Browse files
committed
add security reports
1 parent 271a72a commit 165b28e

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

sql/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SQL Queries for GitHub Enterprise Server
22

3-
:warning: Run these directly against your GitHub Enterprise Server database at your own risk. A safer method to run these is outlined [here](USAGE.md).
3+
:warning: While these are all read-only queries and do not write to the database, run these directly against your GitHub Enterprise Server database at your own risk. A safer method to run these is outlined [here](USAGE.md).
4+
5+
Each query has a comment at the top of the file elaborating what it does, etc.
46

57
## Audit queries
68

@@ -20,6 +22,10 @@ The `audit` folder has queries that are all around auditing credentials, webhook
2022

2123
The `security` folder has queries that are all around dependency alerts and any other security features.
2224

25+
- `active-repo-report.sql` - A list of all detected HIGH and CRITICAL vulnerabilities from repos pushed to in the past 90 days. It also returns who owns it and further details on the exact vulnerability. The threshold of time and severity to return is adjustable.
26+
- `vuln-critical-count.sql` - A count of repositories affected by each CRITICAL vulnerability.
27+
- `vuln-report.sql` - A report of all detected vulnerabilities in every single repo in GHES, who owns it, when it was last pushed to, the platform of the vulnerability, and the GHSA/MITRE/WhiteSource info on it. This can be a very large report.
28+
2329
## Usage queries
2430

2531
The `usage` folder has queries that are all around usage of various features in GitHub Enterprise Server.

sql/security/active-repo-report.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This pulls a list of all detected HIGH and CRITICAL vulnerabilities from
3+
* repositories pushed to in the past 90 days. It also returns who owns it and
4+
* further details on the exact vulnerability.
5+
*
6+
* If you comment line 34, it will both root and fork repositories. As is,
7+
* it will only report root repos.
8+
*/
9+
SELECT
10+
r.name AS repo_name,
11+
u.login AS repo_owner,
12+
u.type AS owner_type,
13+
pushed_at AS last_update,
14+
platform,
15+
severity,
16+
cve_id,
17+
ghsa_id,
18+
white_source_id,
19+
external_reference
20+
FROM
21+
github_enterprise.repository_vulnerability_alerts z
22+
JOIN github_enterprise.vulnerabilities v ON
23+
z.vulnerability_id = v.id
24+
JOIN github_enterprise.repositories r ON
25+
z.repository_id = r.id
26+
JOIN github_enterprise.users u ON
27+
r.owner_id = u.id
28+
WHERE
29+
(v.severity = "critical"
30+
OR v.severity = "high")
31+
AND DATEDIFF(NOW(), r.pushed_at) < 91
32+
AND r.parent_id IS NULL
33+
ORDER BY
34+
last_update DESC;

sql/security/vuln-critical-count.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* This pulls a count of repos affected by each _critical_ vulnerability.
3+
*/
4+
SELECT
5+
v.id,
6+
v.cve_id,
7+
v.ghsa_id,
8+
v.white_source_id,
9+
v.published_at as published,
10+
v.external_reference,
11+
v.platform as ecosystem,
12+
COUNT(z.vulnerability_id) as repo_count
13+
FROM
14+
github_enterprise.repository_vulnerability_alerts z
15+
JOIN github_enterprise.vulnerabilities v ON
16+
z.vulnerability_id = v.id
17+
WHERE
18+
v.severity = 'critical'
19+
GROUP BY
20+
v.id
21+
ORDER BY
22+
COUNT(z.vulnerability_id) DESC;

sql/security/vuln-report.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This pulls a list of all detected vulnerabilities, what it is, who owns the
3+
* associated repo, and when the repo was last updated. This can be a very
4+
* large report!
5+
*/
6+
SELECT
7+
r.name as repo_name,
8+
u.login as repo_owner,
9+
u.type as owner_type,
10+
pushed_at as last_update,
11+
platform,
12+
severity,
13+
cve_id,
14+
ghsa_id,
15+
white_source_id,
16+
external_reference
17+
FROM
18+
github_enterprise.repository_vulnerability_alerts z
19+
JOIN github_enterprise.vulnerabilities v ON
20+
z.vulnerability_id = v.id
21+
JOIN github_enterprise.repositories r ON
22+
z.repository_id = r.id
23+
JOIN github_enterprise.users u ON
24+
r.owner_id = u.id
25+
ORDER BY
26+
last_update DESC;

0 commit comments

Comments
 (0)