Skip to content

Commit b539eec

Browse files
authored
Merge branch 'main' into add/sarif_import_issue_with_ssl_troubleshooting
2 parents 9ba480c + 1ad7098 commit b539eec

10 files changed

Lines changed: 158 additions & 20 deletions

File tree

reporting/advanced-security-reporting.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
- [ ] https://github.com/ThibaudLopez/GHAS
1919
- SIEM integrations
2020
- [ ] https://github.blog/2022-10-13-introducing-github-advanced-security-siem-integrations-for-security-professionals/
21+
- [ ] https://github.blog/2023-03-10-introducing-github-vulnerability-management-integrations-for-security-professionals/
2122
- [ ] https://resources.github.com/security/integrating-github-advanced-security-with-third-party-platforms/

reporting/issues_csv/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A `powershell` script that fetches Code Scanning, Secret Scanning and Dependabot alerts for an organization and outputs them to a CSV file using `jq`.
2+
Includes the repository topics that might be used for filtering and grouping the alerts.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### the csv headers
2+
["repo","severity","created","fixed","dismissed","dismissed reason","state","url","topics"],
3+
(.[]|
4+
### the json path
5+
[.repository.name,.rule.severity,.created_at,.fixed_at,.dismissed_at,.dismissed_reason,.state,.html_url,($topics[][.repository.name]|join(" "))]
6+
) | @csv

reporting/issues_csv/dependabot.jq

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### the csv headers
2+
["repo","package","severity","CVSS","created","fixed","dismissed","dismissed reason","state","url","topics"],
3+
(.[].data.repository.vulnerabilityAlerts.edges[0].node | select(.!=null)|
4+
### the json path
5+
[.repository.name,
6+
.securityVulnerability.package.name,
7+
.securityVulnerability.severity,
8+
.securityVulnerability.advisory.cvss.score,
9+
.createdAt,
10+
.fixedAt,
11+
.dismissedAt,
12+
.dismissReason,
13+
.state,
14+
("https://github.com/beazley/"+.repository.name+"/security/dependabot/"+(.number|tostring)),
15+
($topics[][.repository.name]|join(" "))]
16+
) | @csv

reporting/issues_csv/reporting.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env pwsh
2+
$ORG = "mbaluda-org"
3+
4+
### FETCH TOPICS ###
5+
$topics = gh api --cache 5m orgs/$ORG/repos -q 'map(select(.name)|{(.name):(.topics)})|add' | jq -s 'add'
6+
$topics | Out-File topics_map.json -encoding utf8
7+
8+
### CODE SCANNING ALERTS ###
9+
gh api orgs/$ORG/code-scanning/alerts --method GET --paginate | jq -rf code_scanning.jq --slurpfile topics topics_map.json > code_scanning.csv
10+
11+
### SECRET SCANNING ALERTS ###
12+
gh api orgs/$ORG/secret-scanning/alerts --method GET --paginate | jq -rf secret_scanning.jq --slurpfile topics topics_map.json > secret_scanning.csv
13+
14+
### DEPENDABOT SCANNING ALERTS ###
15+
$repos = $topics | jq 'keys[]'
16+
$(foreach ($repo in $repos) {
17+
gh api graphql -F group=$ORG -F repo=$repo -f query='
18+
query ($endCursor: String, $group: String!, $repo: String!) {
19+
repository(owner: $group, name: $repo) {
20+
vulnerabilityAlerts(first: 100, after: $endCursor) {
21+
edges { node { createdAt fixedAt dismissedAt dismissReason state securityVulnerability { package { name } severity advisory { cvss { score } } } repository { name } number } }
22+
pageInfo { hasNextPage endCursor }
23+
}
24+
}
25+
}' --paginate
26+
}) | jq -srf dependabot.jq --slurpfile topics topics_map.json > dependabot.csv
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### the csv headers
2+
["repo","type","created","fixed","resolution","state","url","topics"],
3+
(.[] | select(.rule.severity!="severity")|
4+
### the json path
5+
[.repository.name,.secret_type,.created_at,.resolved_at,.resolution,.state,.html_url,($topics[][.repository.name]|join(" "))]
6+
) | @csv

troubleshooting/codeql-builds/compiled-languages-csharp.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,22 @@ Using `dotnet` is best documented at: https://docs.github.com/en/actions/automat
5555
#### NuGet Error NU1301
5656
This can indicate your custom package server is not configured which may fail the `dotnet restore` command. For private package servers, the follwing guidance shows how to add package sources: [Setting up authentication for nuget feeds](https://github.com/actions/setup-dotnet#setting-up-authentication-for-nuget-feeds)
5757

58-
### .NET Framework Manual Build Steps on Windows Runners
58+
#### NuGet.targets(132,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
59+
60+
Consider adding auth for your GitHub Packages hosted NuGet feed using the nuget CLI tooling. Add this before the `autobuild` / custom build steps in your workflow.
61+
62+
```yml
63+
- name: add nuget auth
64+
run: dotnet nuget add source https://nuget.pkg.github.com/<org-goes-here>/index.json -n "GitHub" -u USERNAME -p "${{ secrets.GH_PACKAGES_READ_ONLY }}" --store-password-in-clear-text
65+
```
66+
67+
68+
### .NET Framework
69+
70+
#### NuGet Authentication
71+
Utilize the [nuget/setup-nuget](https://github.com/nuget/setup-nuget#basic) action to pass package key/source to nuget exe.
72+
73+
#### Manual Build Steps on Windows Runners
5974
NOTE: if you require windows OS to build, ensure you are using a windows runner.
6075
6176
Example using `windows-latest`:
@@ -118,6 +133,21 @@ Running low on disk using the default Actions runner? Try a few of these workaro
118133
119134
- See also: [Vertical Scaling](#vertical-scaling---throw-hardware-at-the-software-problem)
120135

136+
## MvcBuildViews target failures
137+
138+
This can manifest through a variety of errors
139+
- `error ASPPARSE`
140+
- `[error]C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config(113,0): Error ASPCONFIG: Could not load type`
141+
- `Error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.`
142+
- `(AfterBuildCompiler target) -> D:\a\Orchard\Orchard\src\Orchard.Web\Modules\Orchard.Glimpse\web.config(38): error ASPCONFIG: Could not load file or assembly 'System.Web.Mvc, Version=5.2.3, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)`
143+
144+
The CodeQL compiler tracer used for `csharp` will auto inject the /p:MvcBuildViews=true flag. This pre-compilation of Views gives us the ability to extract the generated code from those files, leading to (potentially) better error reporting and location information if a query does flag an issue. The lack of view information passing through CodeQL to the compiler will lead to an incomplete database, where important dataflow sources/sinks/taint-steps are not included in the analysis.
145+
146+
The recommendation here is to ensure that passing /p:MvcBuildViews=true to your CI build will compile even outside of CodeQL. Having a developer reivew this on their local machine is the best scenario. This can be on done on the specific web project by adding `<MvcBuildViews>true</MvcBuildViews>` to the local .csproj ( you will often find this defaulted to false). The MVC full framework steps are listed [here](https://learn.microsoft.com/en-us/archive/blogs/jimlamb/turn-on-compile-time-view-checking-for-asp-net-mvc-projects-in-tfs-build-2010). There are a few different reasons why this can cause your project to fail compilation.
147+
148+
For `Error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.`, change the locations of the obj and publish folder to not be located under the project folder of the website. If you have bin/obj files checked into source then this could be a likely culprit: https://gunnarpeipman.com/aspnet-mvc-allowdefinition-machinetoapplication/. You will find [various permutations of this recommendation](https://stackoverflow.com/questions/12778088/allowdefinition-machinetoapplication-error-setting-mvcbuildviewstrue-mvcbui) out there!
149+
150+
For `Error ASPCONFIG: Could not load type 'X.Y.Z'`, ensure that you do not have excluded `.cshtml`, `.ashx`, `.ashx.cs`, `.aspx` or `.aspx.cs` files on disk in existing `Views` folders or the Root folder of your project! You can show hidden files in your solution view to hunt these down and remove from these folders. MvcBuildViews does not observe the file include from the csproj when compiling the application. You may have to hunt these down one by one, so adding `<MvcBuildViews>true</MvcBuildViews>` to your local .csproj may help you get this done on your local machine with Visual Studio. The `Error List` view in Visual Studio will have a column that shows you the actual File name you need to delete.
121151

122152
# Speed up C# Analysis
123153

@@ -126,10 +156,10 @@ Start here: [CodeQL Docs - The build takes too long](https://docs.github.com/en
126156
## Optimization - Caching Dependencies
127157
Depending on the number of dependencies, it may be faster to restore packages for your project using the Actions dependency cache. Projects with many large dependencies should see a performance increase as it cuts down the time required for downloading. Projects with fewer dependencies may not see a significant performance increase and may even see a slight decrease due to how NuGet installs cached dependencies. The performance varies from project to project. See [this article](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net#caching-dependencies) for configuring the NuGet dependency cache.
128158

129-
## Optimization - Removing Unit Tests
130-
CodeQL will extract and analyze any code that is passed through the compiler. Consider excluding any code you do not wish to include in a security scan to speed up and remove noise from this process.
159+
## Optimization - Removing Code From Scans
160+
CodeQL will extract and analyze any code that is passed through the compiler. Consider excluding any code you do not wish to include in a security scan to speed up and remove noise from this process. This is commonly employed for unit tests, demo code, or code that would not benefit from being scanned (ex: DacPacs).
131161

132-
With .NET we can employ a few mechanisms to remove test/demo code from CodeQL scans (e.g. you would want to run your unit test in another workflow ):
162+
With .NET we can employ a few mechanisms to remove code from CodeQL scans (e.g. you would want to run your unit test in another workflow ):
133163
- A [solution filter](https://docs.microsoft.com/en-us/visualstudio/msbuild/solution-filters?view=vs-2019) to only build required projects
134164
- An explicit [solution file that excludes projects](https://docs.microsoft.com/en-us/visualstudio/ide/how-to-exclude-projects-from-a-build?view=vs-2022)
135165
- example from the Open Source project: [Identity Server](https://github.com/DuendeSoftware/IdentityServer/)

troubleshooting/codeql-builds/compiled-languages-java.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
# Private Package Registries
33

4-
## The codeql for java is failing when it tries to do mvn command and tries to access a artifactory repo where our pom.xml are stored.
5-
6-
Assuming the given package registry instance is publicly accessible:
4+
## The autobuild for java is failing when running Maven build command and a private package registry is needed - `status: 401 Unauthorized `
5+
- ex: artifactory where our pom.xml dependencies are stored
76

7+
Assuming the given package registry instance is publicly accessible and needs credentials:
88

99
Option 1 - Pass credentials via environment variable from Actions secrets and configure Maven settings to utilize those credentials (see sample [here](https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#yaml-example))
1010

@@ -24,7 +24,20 @@ ex `settings.xml`
2424
</server>
2525
```
2626

27-
Option 2 - Use the [maven-settings-action](https://github.com/s4u/maven-settings-action) to dynamically create/overrite a `settings.xml` that contains the credentials for your specified package manager.
27+
Option 2 - Use the GitHub https://github.com/actions/setup-java#maven-options action to generate maven's settings.xml on the fly and pass the values to Apache Maven GPG Plugin as well as Apache Maven Toolchains.
28+
29+
```yml
30+
- name: Set up Apache Maven Central
31+
uses: actions/setup-java@v3
32+
with:
33+
distribution: 'temurin'
34+
java-version: '11'
35+
server-id: maven # Value of the distributionManagement/repository/id field of the pom.xml
36+
server-username: MAVEN_USERNAME # env variable for username in deploy
37+
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
38+
```
39+
40+
Option 3 - Use the [maven-settings-action](https://github.com/s4u/maven-settings-action) to dynamically create/overrite a `settings.xml` that contains the credentials for your specified package manager.
2841

2942
```yml
3043
- if: matrix.language == 'java'
@@ -34,6 +47,8 @@ Option 2 - Use the [maven-settings-action](https://github.com/s4u/maven-settings
3447
servers: '[{"id": "central", "username": "${{ secrets.MAVEN_USERNAME }}", "password": "${{ secrets.MAVEN_CENTRAL_TOKEN }}"}]'
3548
```
3649

50+
See also: [401 due to private package server configuration](compiled-languages.md#401-due-to-private-package-server-configuration)
51+
3752
# Build Failures
3853

3954
## java.lang.IllegalArgumentException: Unsupported class file major version ##
@@ -42,10 +57,15 @@ Ensure you are compiling your java application using CodeQL tracing on a support
4257

4358
## Fatal error compiling: error: invalid target release: \##
4459

45-
Specify your [desired java version via the setup-java action](https://github.com/actions/setup-java#supported-version-syntax)
60+
Alternative error:
61+
```
62+
> error: invalid source release:
63+
```
64+
65+
Resolution here is to specify your [desired java version via the setup-java action](https://github.com/actions/setup-java#supported-version-syntax)
4666
```yml
47-
uses: actions/setup-java@v3
48-
with:
49-
java-version: 17
50-
distribution: 'microsoft'
51-
```
67+
- uses: actions/setup-java@v3
68+
with:
69+
java-version: 17
70+
distribution: 'microsoft'
71+
```

troubleshooting/codeql-builds/compiled-languages.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ See [language specific guidance](#language-specific-guidance) for common resolut
2424
Ensure network access from GitHub runners to your private registry is open
2525
- For IP Whitelisting, consider using [Larger Runners with Static IP](https://docs.github.com/en/actions/using-github-hosted-runners/using-larger-runners#networking-for-larger-runners)
2626
- See Also: [Connecting Actions to a private network](https://docs.github.com/en/actions/using-github-hosted-runners/connecting-to-a-private-network)
27+
- Alternatively, consider a self-hosted actions runner that will execute within your existing private network. See ["Hosting your own runners"](https://docs.github.com/en/actions/hosting-your-own-runners)
2728

2829
See [language specific guidance](#language-specific-guidance) for authentication options to popular package mangers
2930

@@ -48,9 +49,9 @@ alternatively we can further define limits
4849
- name: Perform CodeQL Analysis
4950
uses: github/codeql-action/analyze@v2
5051
with:
51-
# Increase Values seen in logs:
52+
# Increase Values seen in logs:
5253
#2022-06-01T19:37:19.0200037Z CODEQL_RAM: 119741
53-
#2022-06-01T19:37:19.0200307Z CODEQL_THREADS: 32
54+
#2022-06-01T19:37:19.0200307Z CODEQL_THREADS: 32
5455
ram: 64000
5556
threads: 16
5657
```
@@ -64,5 +65,6 @@ Helpful Articles to understand how to review, troubleshoot, and debug logs:
6465
- [Adding artifacts on every CodeQL Run](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/troubleshooting-the-codeql-workflow#creating-codeql-debugging-artifacts-using-a-workflow-flag)
6566
- [Exit Codes](https://codeql.github.com/docs/codeql-cli/exit-codes/)
6667
67-
## Optimizaitons
68-
- CodeQL Docs - [The build takes too long](https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/troubleshooting-the-codeql-workflow)
68+
69+
## Optimizations
70+
- CodeQL Docs - [The build takes too long](https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/troubleshooting-the-codeql-workflow)

troubleshooting/sarif-upload/troubleshooting.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
### SARIF Upload Errors
1+
## SARIF Upload Errors
2+
* Test environment - GHES 3.2.1 + CodeQL CLI 2.7.2
23

34
:gift: wrong ref:
45
```
@@ -58,9 +59,37 @@ More information on the API can be found [here](https://docs.github.com/en/rest/
5859

5960
### Test environments
6061
- GHES 3.2.1 + CodeQL CLI 2.7.2
62+
=======
63+
## SARIF Parsing Errors
6164

65+
### Code Scanning could not process the submitted SARIF file: rejecting SARIF, as there are more runs than allowed (123 > 15)
66+
The GitHub api for accepting SARIF uploads has a limiter to prevent that number from being greater than specified (>15) for each upload.
6267

63-
### Tools to rewrite SARIF
68+
See limits for various thresholds on the [REST API documentation](https://docs.github.com/en/rest/code-scanning?apiVersion=2022-11-28#upload-an-analysis-as-sarif-data)
69+
* Runs per file
70+
* Results per run
71+
* Rules per run
72+
* Tool extensions per run
73+
* Thread Flow Locations per result
74+
* Location per result
75+
* Tags per rule
76+
77+
### A fatal error occurred: SARIF file is too large. The GitHub code scanning API accepts a max file size of 2000MB. This file is xxxxMB. File: "xyz.sarif"
78+
- aleternatively - `failed decompressing file from the path: "upload /xyz.sarif.gz": maximum SARIF size exceeded`
79+
80+
First, review recommendedations per language to reduce the amount of code being scanned (e.g. removing test or demo code from the scan in an attempt to remove unwanted detections from SARIF). A detailed analysis of the SARIF file may indicate a massive number of a single rule, in this case [excluding a specific rule from the analysis](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning#excluding-specific-queries-from-analysis) would be the best solution. Alternatively, use a tool like [filter-sarif action](https://github.com/advanced-security/filter-sarif) to rewrite the SARIF file to exclude specific detections via an exclusion pattern.
81+
82+
If there are many deep code paths highlighted in the SARIF, use `--max-path=0` (or 1) passed into the analyze step or `database analyze` cli command to get rid of the dataflow paths and reduce the SARIF size that way (NOTE this will impact all rules).
83+
84+
```yml
85+
- name: Perform CodeQL Analysis
86+
uses: github/codeql-action/analyze@v2
87+
env:
88+
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths", 1]}}'
89+
```
90+
91+
## Tools to rewrite SARIF
6492
- `jq`
6593
- [Microsoft's SARIF tool](https://github.com/microsoft/sarif-sdk/blob/main/docs/multitool-usage.md)
6694
- [Dr. House's SARIF CLI](https://github.com/hohn/sarif-cli)
95+
- [advanced-security/filter-sarif action](https://github.com/advanced-security/filter-sarif)

0 commit comments

Comments
 (0)