Supply chainGitHub
Static analysis in CI: CodeQL, Semgrep and less noise
CodeQL and Semgrep both report problems they find in source code. Each documents ways to limit what a pull request shows and what blocks a merge: results for changed code only, severity thresholds, baselines and suppressions that record a reason.

CodeQL on GitHub
CodeQL is the code analysis engine developed by GitHub. Its results are shown as code scanning alerts in the repository.
GitHub's documentation describes two Advanced Security products: GitHub Secret Protection and GitHub Code Security. Code scanning is part of GitHub Code Security. The same page says code scanning is enabled for public repositories by default, and that private and internal repositories need the product. Buying it requires a GitHub Team plan or a GitHub Enterprise plan.
There are two setup types:
- Default setup needs no workflow file. GitHub creates the configuration from the code in the repository. It scans on each push to the default branch and protected branches, on pull requests against them (except pull requests from forks) and on a weekly schedule.
- Advanced setup is the choice when you need a workflow of your own. GitHub's examples: building compiled languages, running a matrix build and changing the analysis schedule. It also covers analysis in an external CI system.
GitHub recommends starting with default setup. With advanced setup, GitHub creates a default CodeQL analysis workflow file. The documentation shows its steps in parts: a checkout, init with the languages and the build mode, and analyze.
steps:
- uses: actions/checkout@v7
- uses: github/codeql-action/init@v4
with:
languages: javascript-typescript
build-mode: none
- uses: github/codeql-action/analyze@v4Semgrep
Semgrep's open-source edition is named Semgrep Community Edition (CE). The command for it is semgrep scan, which the CLI reference describes as suitable for scanning with no Semgrep account. --config takes a YAML rule file, a directory of rule files, a URL or a Semgrep Registry entry name such as p/default.
semgrep scan --config p/default --error --severity=ERROR \
--baseline-commit=<base-commit-hash> --sarif-output=semgrep.sarifBy default, semgrep scan does not return a failing exit code on findings. --error makes it exit with 1 when there are findings. GitHub code scanning accepts SARIF files from third-party tools through the upload-sarif action.
Semgrep's README states the limit of the edition: in security contexts, Community Edition will miss many true positives, because it can only analyze code within the boundaries of a single function or file. The CLI reference says semgrep ci uses the policies and rules defined by your organization, with cross-file and cross-function analysis.
1. Show new results only
Code scanning shows an alert in a pull request only when every line of code the alert identifies is part of the pull request's diff. New alerts on changed lines appear as annotations.
In Semgrep, --baseline-commit sets a baseline: it shows only the results that are not found in the commit hash you pass. Semgrep aborts the run if the given baseline hash does not exist. actions/checkout fetches a single commit by default, and fetch-depth: 0 fetches all history.
2. Set a severity threshold
By default the code scanning results check fails when it finds a problem with a severity of error, critical or high. With lower severities the check succeeds. A ruleset can prevent a merge when a required tool finds an alert of a severity that the ruleset defines.
In Semgrep, --severity reports findings only from rules that match the given level. The CLI reference lists INFO, WARNING and ERROR.
The security-extended CodeQL suite holds every query of the default suite and adds queries of lower severity and lower precision.
3. Keep a scheduled full scan
Keep a full scan on a schedule next to the pull request scan. GitHub's documentation gives the reason: a scheduled scan reports the newest vulnerabilities and errors found by GitHub, by security researchers and by the community, and it does so even while nobody changes the repository.
4. Name an owner for triage
There are two ways of closing a code scanning alert: fix the problem in the code, or dismiss the alert. After a fix, GitHub closes the alert by itself. Dismissing is for an alert that you do not think needs to be fixed. Name the person or team in each repository who makes that call.
5. Suppress with a reason
When you dismiss a code scanning alert, you choose a reason. The dismissal applies to all branches, and the reason is recorded. You can add a comment, which goes on the alert timeline and can serve as justification during auditing and reporting.
In Semgrep, an inline comment with the word nosemgrep, on the first line of the match or on the line before it, ignores the match. These are the forms from Semgrep's documentation:
bad_func1() # nosemgrep: rule-id-1
# nosemgrep: rule-id-1, rule-id-2
bad_func2()With no rule ID, Semgrep ignores all rule matches at that place. A rule ID limits the comment to that rule, and it must be written with its namespace. Add the reason in a comment next to it.
Where to start
- Enable CodeQL default setup, or add a
semgrep scanstep. Without--error, Semgrep findings do not fail the job. - Go through the results. Fix the problems, and dismiss the rest with a reason.
- Decide which severity fails the check, and require the check with a ruleset.
- Add the
nosemgreprule ID and a reason to every suppression in code.
Sources
- About setup types for code scanning, GitHub Docs
- About GitHub Advanced Security, GitHub Docs
- Workflow configuration options for code scanning, GitHub Docs
- Code scanning alerts, GitHub Docs
- Triaging code scanning alerts in pull requests, GitHub Docs
- Resolving code scanning alerts, GitHub Docs
- CLI reference, Semgrep
- Ignore files, folders, and code, Semgrep
Want a second pair of eyes on yours? We do this work for a living.
More guides

Scan container images with Trivy in CI
Supply chain · 4 min read
The flags, the ignore file, the pinned action and the limits of scanning an image with Trivy.

GitHub rulesets: protect branches and tags
Supply chain · 4 min read
Targets, bypass lists, layering and a JSON ruleset you can import to protect main.

Scan Terraform before it applies: Checkov and Trivy
Supply chain · 4 min read
Checkov and Trivy on Terraform code and plans, with skip comments and a gate you can roll out.