Skip to content

Create ghas-bootcamp-codeql-cli-example-00.yml #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 151 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
1dd2808
Create azure-pipeline-00.yml
Oct 15, 2021
b6c4b5a
Update advanced-security-reporting.md
ThibaudLopez Oct 18, 2021
c3a9b37
Update setup-codeql-cli.md
Oct 20, 2021
09077dd
Create Dockerfile.go-example
Oct 26, 2021
0c5c887
Rename Dockerfile.go-example to Dockerfile.example
Oct 26, 2021
7fa4a93
Create uniform-setup-for-cli-and-vs-code.md
hohn Oct 27, 2021
fcc66a9
Update run-pr-codeql-analysis.sh
Nov 2, 2021
c841911
Update run-pr-codeql-analysis.sh
Nov 2, 2021
fea067f
Update advanced-security-reporting.md
Nov 3, 2021
3d5b353
Merge pull request #1 from ThibaudLopez/patch-1
Nov 3, 2021
bc12f23
Update advanced-security-material.md
Nov 3, 2021
d563a67
Create index.md
Nov 3, 2021
e0c8af3
Rename index.md to README.md
Nov 3, 2021
10b660f
Reusable workflow for Code Scanning
mbaluda Nov 8, 2021
0f1d40c
Update reusable_code_scanning-00.yml
mbaluda Nov 8, 2021
1d9879c
Update code-scanning-third-party-integrations.md
mbaluda Nov 8, 2021
43b4790
Update code-scanning-third-party-integrations.md
mbaluda Nov 9, 2021
6814251
Update reusable_code_scanning-00.yml
mbaluda Nov 17, 2021
9a6018a
Update reusable_code_scanning-00.yml
mbaluda Nov 17, 2021
ef1324f
Update code-scanning-third-party-integrations.md
mbaluda Nov 22, 2021
d9a8e48
Update code-scanning-third-party-integrations.md
mbaluda Nov 22, 2021
838e4fa
Create troubleshooting.md
Dec 6, 2021
6450e35
Update troubleshooting.md
Dec 6, 2021
27ea829
Merge pull request #2 from advanced-security/cmboling/update-links
Dec 6, 2021
ef51187
Update setup-codeql-cli.md
Dec 8, 2021
f9176f7
Update setup-codeql-cli.md
Dec 8, 2021
6628f63
Rename advanced-security-reporting.md to reporting/advanced-security-…
Dec 8, 2021
066076f
Create ghes-sql-queries.md
Dec 8, 2021
c0be84f
Update ghes-sql-queries.md
Dec 8, 2021
6897797
Update ghes-sql-queries.md
Dec 8, 2021
b68f01d
Update ghes-sql-queries.md
Dec 9, 2021
f7d76f7
Update ghes-sql-queries.md
Dec 9, 2021
10c03da
Update ghes-sql-queries.md
Dec 9, 2021
8c84ae1
Update ghes-sql-queries.md
Dec 9, 2021
c04a6d2
Update ghes-sql-queries.md
Dec 9, 2021
f9184a0
Update ghes-sql-queries.md
Dec 9, 2021
9bd3350
Update ghes-sql-queries.md
Dec 9, 2021
cb33713
Update ghes-sql-queries.md
Dec 9, 2021
c11093b
Update ghes-sql-queries.md
Dec 9, 2021
ae22c22
Delete ghes-sql-queries.md
Dec 9, 2021
51db969
Create ghes-mysql-connect.md
Dec 9, 2021
9f887f9
Update ghes-mysql-connect.md
Dec 9, 2021
8a9db25
Update troubleshooting.md
Jan 13, 2022
42b27ba
Update troubleshooting.md
Jan 13, 2022
2c7c8f4
Merge pull request #4 from cmboling/patch-1
Jan 14, 2022
4fb74b3
Create get-languages.sh
Feb 10, 2022
4b03506
Update advanced-security-reporting.md
Feb 10, 2022
093fe06
fixed broken semmle links
zerotyr Feb 17, 2022
ee7cd96
Update reusable_code_scanning-00.yml
mbaluda Feb 24, 2022
3269a74
Create user-defined-patterns-considerations.md
Mar 1, 2022
5e8d086
Merge pull request #6 from zerotyr/patch-1
Mar 2, 2022
bf34522
Merge pull request #7 from mbaluda/patch-1
Mar 2, 2022
69438fb
Update advanced-security-reporting.md
Mar 2, 2022
10dc831
Merge pull request #5 from advanced-security/cmboling-patch-1
Mar 2, 2022
cc54727
Create combine-n-databases.sh
Mar 4, 2022
d0db269
Create README.md
mbaluda Apr 22, 2022
0df0a12
Add files via upload
mbaluda Apr 22, 2022
3347707
Update README.md
mbaluda Apr 22, 2022
19a78da
Initial Docs
felickz Oct 7, 2022
8315199
CPP init
felickz Oct 17, 2022
c07d458
language links
felickz Oct 17, 2022
b002a77
relative links
felickz Oct 17, 2022
7cd91eb
interpreted autobuilder troubleshooting
felickz Oct 17, 2022
382d374
yml
felickz Oct 17, 2022
717c5f7
Links
felickz Oct 21, 2022
d4dd678
java private package registries
felickz Oct 21, 2022
0bc1084
csharp links
felickz Oct 21, 2022
0b446ab
fix MD
felickz Oct 21, 2022
e4926bd
directory move
felickz Oct 24, 2022
96ab5a5
Add java
felickz Oct 24, 2022
c399fa4
Java
felickz Oct 24, 2022
52e0923
python
felickz Oct 26, 2022
e43fb45
Docs enhancements
felickz Oct 28, 2022
70b1a5c
Links for autobuild + runtime customization
felickz Oct 28, 2022
f3dce72
clean up sections
felickz Oct 28, 2022
1834f3b
Reporting updates
felickz Oct 28, 2022
6ed0e27
clean up
felickz Oct 28, 2022
cb5ed80
fix python link
felickz Oct 28, 2022
9c68174
Merge pull request #9 from felickz/main
NickLiffen Nov 1, 2022
f23d8af
CodeQL - CSharp - NuGet Cache
felickz Jan 11, 2023
2a6fe64
Update compiled-languages-csharp.md
felickz Jan 11, 2023
bcbbea8
Update compiled-languages-csharp.md
felickz Jan 11, 2023
7dbc1b5
Update compiled-languages-csharp.md
felickz Jan 11, 2023
835a906
Fix typo in compiled-languages.md
peksin Jan 28, 2023
9ba480c
add API export when there is an SLL certificate not trusted
adrienpessu Feb 7, 2023
e3f0940
Update compiled-languages-csharp.md
felickz Feb 8, 2023
d8d920e
Update compiled-languages-java.md
felickz Feb 13, 2023
e42a961
Update troubleshooting.md
felickz Feb 19, 2023
944cb5e
Update troubleshooting.md
felickz Feb 19, 2023
b970ecf
Update troubleshooting.md
felickz Feb 19, 2023
be43abe
Update compiled-languages.md
felickz Feb 27, 2023
5e8e41f
Update compiled-languages.md
felickz Feb 27, 2023
ad24927
Update compiled-languages.md
felickz Feb 27, 2023
d2d8737
Update compiled-languages-csharp.md
felickz Mar 10, 2023
9c38092
Update compiled-languages-java.md
felickz Mar 13, 2023
41fa177
Update compiled-languages-csharp.md
felickz Mar 30, 2023
0d723df
Update compiled-languages-java.md
felickz Mar 31, 2023
bdb7c6d
Update compiled-languages-java.md
felickz Mar 31, 2023
56a9a24
Update compiled-languages.md
felickz Mar 31, 2023
ae7e0a5
Update compiled-languages.md
felickz Mar 31, 2023
00ca803
Merge branch 'main' into main
felickz Mar 31, 2023
23baa77
Merge pull request #10 from peksin/main
felickz Mar 31, 2023
cde7a42
Merge pull request #8 from mbaluda/patch-1
felickz Mar 31, 2023
096ad60
Update advanced-security-reporting.md
felickz Mar 31, 2023
4c2082d
Update compiled-languages-csharp.md
felickz Mar 31, 2023
720329c
Update compiled-languages-csharp.md
felickz Apr 3, 2023
5cfd015
Update compiled-languages-csharp.md
felickz Apr 3, 2023
3e720ef
Update compiled-languages-csharp.md
felickz Apr 3, 2023
e0bb3f5
add actions/setup-java to generate settings.xml
felickz May 1, 2023
1ad7098
Add C# Troubleshooting - Nuget Packages Auth
felickz May 11, 2023
b539eec
Merge branch 'main' into add/sarif_import_issue_with_ssl_troubleshooting
adrienpessu May 12, 2023
d6c9b17
Merge pull request #11 from adrienpessu/add/sarif_import_issue_with_s…
adrienpessu May 12, 2023
7a5a2bb
Update compiled-languages-csharp.md
felickz May 19, 2023
99744ba
Update compiled-languages-csharp.md
felickz May 30, 2023
c65ae7d
Update compiled-languages-csharp.md
felickz May 30, 2023
4202457
Update README.md
leftrightleft Jun 15, 2023
28190e9
Update README.md
leftrightleft Jun 15, 2023
258444c
Update README.md
leftrightleft Jun 15, 2023
d59f698
Create GHAS-on-GHES-feature-matrix.md
leftrightleft Jun 15, 2023
2443f9a
Update GHAS-on-GHES-feature-matrix.md
leftrightleft Jun 15, 2023
d59027b
Update GHAS-on-GHES-feature-matrix.md
leftrightleft Jun 15, 2023
96ed1b4
Update GHAS-on-GHES-feature-matrix.md
leftrightleft Jun 15, 2023
92443f3
Update GHAS-on-GHES-feature-matrix.md
leftrightleft Jun 16, 2023
6438e25
Merge pull request #13 from leftrightleft/feature-matrix
leftrightleft Jun 20, 2023
a61f0dd
update all links to GHES instead of GHEC@latest
felickz Jun 21, 2023
27444d9
Update compiled-languages-csharp.md
felickz Jun 21, 2023
0dd0719
add dependency matrix for ghes
some-natalie Jul 6, 2023
e17f286
Merge pull request #16 from some-natalie/main
leftrightleft Jul 17, 2023
04d2215
add link to new Dependabot quickstart guide
felickz Aug 1, 2023
daf1d7b
Merge pull request #17 from advanced-security/readme-dep-quickstart
felickz Aug 1, 2023
90a9b86
Update README.md
felickz Aug 1, 2023
976e296
Create compiled-languages-go.md
felickz Aug 1, 2023
c852b3e
Update compiled-languages.md
felickz Aug 1, 2023
7f67731
Merge pull request #18 from advanced-security/codeql-troubleshooting-…
felickz Aug 1, 2023
a20b5d3
Merge branch 'main' into matrix-ghes-links
felickz Aug 1, 2023
b1020e4
Merge pull request #14 from advanced-security/matrix-ghes-links
felickz Aug 1, 2023
c07d2b1
update links from 3.9 to (latest)
felickz Aug 1, 2023
9a413bd
Merge pull request #19 from advanced-security/ghes-matrix-39-to-latest
felickz Aug 1, 2023
d394c30
GHES + Codeql Versions
felickz Aug 2, 2023
9006b76
Add link to Releases of GitHub Enterprise Server
felickz Aug 2, 2023
21d2943
Merge pull request #20 from advanced-security/ghes-features-codeql-ve…
leftrightleft Aug 3, 2023
c42883d
Create owasp-webgoat-codeql.yml
GeekMasher Aug 16, 2023
5d8ae8d
Update WebGoat
GeekMasher Aug 16, 2023
6ac7b17
Merge pull request #21 from advanced-security/owasp-webgoat
GeekMasher Aug 16, 2023
3ecb38b
Update and rename owasp-webgoat-codeql.yml to owasp-webgoat.yml
GeekMasher Aug 16, 2023
65ae0ab
Update owasp-webgoat.md
GeekMasher Aug 16, 2023
660ee49
Merge pull request #22 from advanced-security/webgoat-2
GeekMasher Aug 16, 2023
0424cb9
Init GHES 3.10 changes
felickz Aug 16, 2023
9d65433
Update GHAS-on-GHES-feature-matrix.md
leftrightleft Aug 29, 2023
bf34e3e
Merge pull request #23 from advanced-security/ghes-3.10
NickLiffen Aug 30, 2023
bd05c22
Create code-scanning-codeql-cli-example-00.yml
Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Dockerfile.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu
LABEL description="Security & Quality CodeQL Container Build for Cool Applications"
SHELL ["/bin/bash", "-c"]
ENV TZ=America/New_York

# create directories
RUN mkdir /tools

# setup tools
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get install -y golang zip wget
RUN wget -q https://github.com/github/codeql-action/releases/download/codeql-bundle-20211005/codeql-bundle-linux64.tar.gz
RUN tar xzf /codeql-bundle-linux64.tar.gz -C tools

# copy source
COPY . /usr/src/myapp

# set working directory
WORKDIR /usr/src/myapp

# example repo used: https://github.com/ghas-bootcamp/ghas-bootcamp

# codeql create
RUN /tools/codeql/codeql database create db --language=javascript, java --db-cluster --no-run-unnecessary-builds -vvvv

# codeql analyze with default queries
RUN /tools/codeql/codeql database analyze codeql-database/go go-code-scanning.qls --format=sarif-latest --output=codeql-go-results.sarif --sarif-category=goiscool
RUN /tools/codeql/codeql database analyze db javascript-code-scanning.qls --format=sarif-latest --output=codeql-javascript-results.sarif --sarif-category=javascriptiscool

# upload results
# remember to get the MERGE commit for a PR
RUN /tools/codeql/codeql github upload-results --github-url=<ghes-url> --repository=oreos/miniature-invention --ref=refs/pull/1/merge --commit=778337f84a5abe2cda468c7abf6038b8a193cea2 --sarif=codeql-go-results.sarif --github-auth-stdin=<github PAT>
RUN /tools/codeql/codeql github upload-results --github-url=<ghes-url> --repository=oreos/miniature-invention --ref=refs/pull/1/merge --commit=778337f84a5abe2cda468c7abf6038b8a193cea2 --sarif=codeql-javascript-results.sarif --github-auth-stdin=<github PAT>
181 changes: 181 additions & 0 deletions GHAS-on-GHES-feature-matrix.md

Large diffs are not rendered by default.

46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# Advanced Security Material
A place for resources to help you understand and use GitHub Advanced Security
A place for resources to help you understand and use GitHub Advanced Security (GHAS). Browse the directories in this repository for resources and documentation. To help you get started with GHAS, we've provided some introductory documentation in this file.

## Get started with GitHub Advanced Security
The following list of links are great resources to get you started on learning how to use, deploy, and manage GitHub Advanced Security in your environment.

New to GitHub Advanced Security? Start with [GitHub security features](https://docs.github.com/en/enterprise-cloud@latest/code-security/getting-started/github-security-features) :+1:

### Code Scanning
- [About GitHub Code Scanning](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning)
- [Configuring Code Scanning](https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning)
- [Integrating other tools with GHAS](https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning)

### CodeQL
- [Meet CodeQL](https://codeql.github.com/)
- [CodeQL Documentation](https://codeql.github.com/docs/)
- [CWE Query Mapping Documentation](https://codeql.github.com/codeql-query-help/codeql-cwe-coverage)
- [Running additional queries](https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#running-additional-queries)
- [CodeQL CLI Docs](https://codeql.github.com/docs/codeql-cli/getting-started-with-the-codeql-cli)
- [Running CodeQL in your CI System](https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/running-codeql-code-scanning-in-your-ci-system)

### Secret Scanning
- [About Secret Scanning](https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning)
- [Supported secret patterns](https://docs.github.com/en/code-security/secret-scanning/secret-scanning-patterns#supported-secrets-for-partner-patterns)
- [Defining custom secret patterns](https://docs.github.com/en/enterprise-cloud@latest/code-security/secret-scanning/defining-custom-patterns-for-secret-scanning)

### Supply Chain Security (Dependabot)
- [About](https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/about-supply-chain-security)
- [Dependency Graph](https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/about-the-dependency-graph)
- [Dependabot Alerts](https://docs.github.com/en/enterprise-cloud@latest/code-security/dependabot/dependabot-alerts/about-dependabot-alerts)
- [Dependabot Security Updates](https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates)
- [GitHub Advisory Database](https://github.com/advisories)
- [Dependabot Quickstart Guide](https://docs.github.com/en/code-security/getting-started/dependabot-quickstart-guide)

### Security Overview
- [About Security Overview](https://docs.github.com/en/code-security/security-overview/about-the-security-overview)
- [Managing alerts in your repository](https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/managing-code-scanning-alerts-for-your-repository)

### Other Resources
- [SARIF Tutorials](https://github.com/microsoft/sarif-tutorials)
- [GitHub Advanced Security Learning Path](https://docs.microsoft.com/en-us/users/githubtraining/collections/rqymc6yw8q5rey)
- [Scaling GHAS in Your Organization](https://resources.github.com/downloads/Whitepaper-Scaling-GHAS-in-an-Enterprise.pdf)
- [The Complete Guide to Developer-first Security](https://resources.github.com/downloads/GitHubAdvanced%20SecurityEbook.pdf)
- [GitHub Checkout - Code Scanning (video)](https://www.youtube.com/watch?v=z0wvGf3O69E)
- [GitHub Checkout - Secret Scanning (video)](https://www.youtube.com/watch?v=aoL7pDrXt74)
- [GitHub Checkout - Viewing and Managing your Dependencies (video)](https://www.youtube.com/watch?v=gNd_TGdZ1xc)
8 changes: 4 additions & 4 deletions advanced-security-material.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
- [ ] Javascript: https://www.youtube.com/watch?v=pYzfGaLTqC0

#### CodeQL Resources:
- [ ] QL Tutorials: https://help.semmle.com/QL/learn-ql/beginner/ql-tutorials.html
- [ ] CodeQL for VS Code: https://help.semmle.com/codeql/codeql-for-vscode/procedures/about-codeql-for-vscode.html
- [ ] QL Tutorials: https://codeql.github.com/docs/writing-codeql-queries/ql-tutorials/
- [ ] CodeQL for VS Code: https://codeql.github.com/docs/codeql-for-visual-studio-code/
- [ ] VS Code starter workspace to use with the CodeQL VS extension: https://github.com/github/vscode-codeql-starter
- [ ] CodeQL CTF: https://securitylab.github.com/ctf
- [ ] Read about contributing to CodeQL Queries: https://github.com/github/codeql/blob/main/CONTRIBUTING.md
Expand All @@ -34,7 +34,7 @@
- [ ] Configure code scanning: https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning
- [ ] Configuring builds for Compiled Languages: https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-the-codeql-workflow-for-compiled-languages
- [ ] Running additional queries: https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#running-additional-queries
- [ ] Built-in Queries: https://help.semmle.com/QL/ql-built-in-queries.html
- [ ] Built-in Queries: https://github.com/github/codeql, https://github.com/github/codeql-go
- For example, js query suites: https://github.com/github/codeql/tree/master/javascript/ql/src/codeql-suites
- [ ] Troubleshooting code scanning workflow:
https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-the-codeql-workflow
Expand All @@ -46,4 +46,4 @@ https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerab
- [ ] Jenkins + CodeQL CLI: https://github.com/kllund/sample-pipeline-files/blob/main/Jenkinsfile-template-with-codeql-cli-bundle

#### OSS Issue Tracking
- [ ] GitHub Code Scanning + Jira: https://github.com/github/codescanning-jira-integration
- [ ] GitHub Code Scanning + Jira: https://github.com/github/ghas-jira-integration
11 changes: 0 additions & 11 deletions advanced-security-reporting.md

This file was deleted.

17 changes: 7 additions & 10 deletions code-scanning-guides/setup-codeql-cli.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Getting started with the CodeQL CLI

When you want to generate a CodeQL database locally and run the pre-compiled queries against, this is the way to go.
When you want to generate a CodeQL database locally and run the pre-compiled queries against it, this is the way to go.

First let's download the CodeQL bundle! Head over [here](https://github.com/github/codeql-action/releases ) and download the approprate bundle for your operating system.
Once it's downloaded, untar the content to a CodeQL home folder and you can add CodeQL to your path if you'd like
Expand All @@ -15,9 +15,6 @@ Check to make sure you can use the CodeQL CLI
codeql --version
```

You can see in this example how the CodeQL CLI is used in a [workflow](https://github.com/advanced-security/javascript-codeql-cli-test-workflow/blob/main/.github/workflows/codeql-analysis.yml).
Note that it always downloads the latest CodeQL bundle for Linux. In your case, choose the bundle that best fits your operating system.

Now we need to use the CodeQL CLI on an actual repository. Let's start here with our [GHAS training material](https://github.com/ghas-bootcamp/ghas-bootcamp)
There's multiple languages being used here, so for the purposes of this tutorial let's try to scan the Javascript portions of the codebase.

Expand All @@ -29,7 +26,7 @@ Clone this repository and `cd` into it.
The first thing we gotta do when it comes to CodeQL analysis is to create a CodeQL database.
When it comes to interpreted languages and Go, CodeQL will use an autobuild.sh script that will extract the source code and create a snapshot database.
When it comes to compiled languages, we require to build the source code in order to trace the build and create a snapshot database of it.
You can rely on the autobuild.sh script as well, or you can supply your own build instructions via `--comand` flag, which can be used when invoking the `codeql database create` command.
You can rely on the autobuild.sh script as well, or you can supply your own build instructions via the `--command` flag, which can be used when invoking the `codeql database create` command.
Please review this [list](https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/) of currently supported languages and frameworks.


Expand All @@ -41,9 +38,9 @@ CodeQL will create the `db` directory and will choose the autobuild.sh script fo
CodeQL will also finalize the database at the specified `db` directory. Within your codeql database directory (in this case `db`)
you should notice a db-javascript directory which contains the db schemes and a src.zip which contains the source that was extracted.

#### Importing the CodeQL database to Visual Studios
#### Optional: Importing the CodeQL database to Visual Studios
You can actually take this database and import it to your Visual Studios workspace.
To get started on that, please go to this repository and follow the instructions on how to setup the CodeQL starter workspace, as well as installing the CodeQL plugin.
To get started on that, please go to this [repository](https://github.com/github/vscode-codeql-starter) and follow the instructions on how to setup the CodeQL starter workspace, as well as installing the CodeQL plugin.
Once you have the CodeQL plugin installed, import the database you created in this step and try to run a javascript query against the database.


Expand Down Expand Up @@ -77,13 +74,13 @@ Failure to do so, in particular on a pull request, can cause confusion in that C
This step is typically used when you want to see the SARIF in the Code Scanning alerts UI. It's typically used when you want to post results to the default branch of a repository for the first time (baseline analysis) or to a pull request to see any security alert annotations.

Here are some advanced things to note:
- When posting the analysis for the first time to a default analysis, make sure you define a `--sarif-category`. That way for the analyses for subsequent pull requests can also share the same category value.
- When posting the analysis for the first time to a default analysis, make sure you define a `--sarif-category`. That way the analyses for subsequent pull requests can also share the same category value.
Note that this kind of depends on how you're running the builds (whether or not you've broken down a monorepo into separate analyses or you have multiple scans due to multiple languaages) but typically just starting out,
just make sure to have the same category value for subsequent scans, so that Code Scannning can easily figure out what the basline analysis is to compare subsequent analyses.

The `--ref` and `--commit` flag combinations can be one of the following:
- `refs/pulls/<pull request number>/merge` + HEAD commit
- `refs/heads/<branch name>` + MERGE commit
- `refs/pulls/<pull request number>/merge` + MERGE commit
- `refs/heads/<branch name>` + HEAD commit
- ` curl -H "Accept: application/vnd.github.v3+json" \\n -H "Authorization: token $GH_TOKEN" \\n https://api.github.com/repos/<org-name>/<repo-name>/pulls/<pull-request-number> | jq '.merge_commit_sha'`
- The merge commit is a commit created to make sure PR checks are ran; this commit doesn't exist in the actual source tree/`git log`.

Expand Down
15 changes: 15 additions & 0 deletions code-scanning-guides/synthetic-applications/owasp-webgoat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# OWASP WebGoat

[A full Actions workflow can be found here](./owasp-webgoat.yml)

## Common Issues

Scanning OWASP WebGoat can have some issues right out of the box where CodeQL might find very little or worse not find anything at all.
This is due to the following:

1. WebGoat uses JDK 17
- Action uses JDK 8 by default
2. Uses Project Lombok
- Future support will be coming to CodeQL natively
3. Dependencies are not all present in Dependency Graph
- Using [Submission API](https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api#using-pre-made-actions)
61 changes: 61 additions & 0 deletions code-scanning-guides/synthetic-applications/owasp-webgoat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
workflow_dispatch:

permissions:
actions: read
contents: read
security-events: write

env:
# in the future, this flag will not be needed
CODEQL_EXTRACTOR_JAVA_RUN_ANNOTATION_PROCESSORS: true

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'java', 'javascript' ]

steps:
- uses: actions/checkout@v2

# WebGoat requires Java/JDK 17
- name: Set up JDK 17
if: matrix.language == 'java'
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
architecture: x64

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# [optional] enabled extended queries
# queries: +security-extended,security-and-quality
# [optional] Field Config - standard packs, extensions, and extra packs
config-file: advanced-security/codeql-queries/config/codeql.yml@main

- name: Autobuild
uses: github/codeql-action/autobuild@v2

# Run the Analysis
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

# Submit Maven Dependency Tree to GitHub
- name: Maven Dependency Tree Dependency Submission
if: matrix.language == 'java'
uses: advanced-security/[email protected]
5 changes: 5 additions & 0 deletions code-scanning-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Code scanning scripts


- [ ] [Code scanning bulke enable](https://github.com/mario-campos/gh-code-scanning)
- [ ] [Run CodeQL analysis on a pull request](https://github.com/advanced-security/advanced-security-material/blob/main/code-scanning-scripts/run-pr-codeql-analysis.sh)
16 changes: 16 additions & 0 deletions code-scanning-scripts/combine-n-databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# For n number of dirs, initialise each of them. In this example I have two dirs at the root:
codeql database init dbs/db-js1 --language=javascript --source-root dir1 --overwrite
codeql database init dbs/db-js2 --language=javascript --source-root dir2 --overwrite

# After db skeletons are created, use the trace command to call out the extractor/add build instructions
codeql database trace-command dbs/db-js1 -- /Users/cmboling/Projects/codeql-home/codeql-latest/javascript/tools/autobuild.sh
codeql database trace-command dbs/db-js2 -- /Users/cmboling/Projects/codeql-home/codeql-latest/javascript/tools/autobuild.sh

# Then import n unfinalized dbs to the target db
codeql database import dbs/db-js1 db-js2
codeql database finalize --finalize-dataset db-js1

# Analyze target db as usual
codeql database analyze db-js1 javascript-code-scanning.qls --format=sarif-latest --output=codeql-javascript-results.sarif
5 changes: 5 additions & 0 deletions code-scanning-scripts/get-languages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GH_TOKEN" \
https://api.github.com/repos/advanced-security/ghas-bootcamp-dryrun/languages | \
jq 'with_entries(select([.key] | inside(["Go", "Java", "JavaScript", "Python", "C++", "C#", "C", "TypeScript"])) | if .key == "C" then .key = "cpp" else . end | if .key == "C#" then .key = "csharp" else . end | if .key == "C++" then .key = "cpp" else . end | if .key == "Go" then .key = "go" else . end | if .key == "Java" then .key = "java" else . end | if .key == "JavaScript" then .key = "javascript" else . end | if .key == "Python" then .key = "python" else . end | if .key == "TypScript" then .key = "typescript" else . end)' | jq "keys"
7 changes: 2 additions & 5 deletions code-scanning-scripts/run-pr-codeql-analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ CODEQL_SARIF_CATEGORY=.github/workflows/codeql-analysis.yml:analyze/language:go

# run a single language analysis for a PR

# remove db
rm -rf $CODEQL_DATABASE

# get mergit commit sha
# get merge commit sha
GH_MERGE_COMMIT_SHA=$(curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GH_TOKEN" https://api.github.com/repos/$GH_ORG/$GH_REPO/pulls/$GH_PULL_REQUEST_NUMBER | jq '.merge_commit_sha' | sed -e 's/^"//' -e 's/"$//')

# check codeql --version
codeql --version

# codeql database create
codeql database create $CODEQL_DATABASE --language=$CODEQL_LANGUAGE
codeql database create $CODEQL_DATABASE --language=$CODEQL_LANGUAGE --overwrite

# codeql database analyze
codeql database analyze $CODEQL_DATABASE $CODEQL_QUERY_SUITE --output=$CODEQL_SARIF_RESULTS --sarif-category=$CODEQL_SARIF_CATEGORY --format=sarif-latest
Expand Down
Loading