Sub topic 8
Reading alerts in the Security tab and on pull requests
This chapter assumes you can read a CodeQL workflow like the one from the earlier chapters, and that you know how pull requests and branches work. After a scan finishes, its results appear in two places: the repository's Security tab and the pull request checks. Knowing how to read both saves you from fixing the wrong thing or dismissing a real problem.
Where results appear
CodeQL writes its findings as SARIF, and the analyze step uploads that file to GitHub. GitHub then turns each result into a code scanning alert.
- Security tab, Code scanning: lists alerts for the whole repository. Alerts are grouped by branch, and the default branch is shown first.
- Pull request: shows alerts that the pull request introduces. These appear as a check named "Code scanning results" and as annotations on the changed lines in the Files changed view.
Anatomy of an alert
Open an alert from the Security tab. Each alert page has the same parts.
| Part | What it tells you |
|---|---|
| Rule name and ID | The query that fired, for example `js/sql-injection`. |
| Severity | Critical, High, Medium or Low for security queries. Other queries show Error, Warning or Note. |
| Location | The file and line where the problem is reported. |
| Message | A short description of what is wrong. |
| Branches | Which branches the alert currently exists on. |
| Status | Open, Closed as fixed, or Closed as dismissed. |
The rule ID is the most useful field for searching. It names the exact query, so you can find its documentation and any related alerts.
Reading data flow paths
Many security alerts come from taint tracking queries. These follow untrusted data from a source, such as an HTTP request parameter, to a sink, such as a database call. The alert page then shows a Show paths link.
Click it and read the path from top to bottom:
- The first step is the source, where untrusted input enters.
- The middle steps show how the value moves through variables and function calls.
- The last step is the sink, where the value becomes dangerous.
To fix the alert, break the path between source and sink. You can validate the input, escape it, or use a safe API such as a parameterized query. Fixing the sink is usually better than fixing only one step in the middle, because other paths may reach the same sink.
// Alert: user input flows into the query string.
app.get("/user", (req, res) => {
db.query("SELECT * FROM users WHERE id = " + req.query.id);
});
// Fixed: the value is passed as a parameter.
app.get("/user", (req, res) => {
db.query("SELECT * FROM users WHERE id = ?", [req.query.id]);
});Alerts on pull requests
On a pull request, GitHub compares the scan of the merge result with the scan of the base branch. It reports only the alerts that are new. Alerts that already exist on main do not block or clutter the pull request.
Two details cause confusion:
- An annotation appears only on lines that the pull request changed. If an alert is reported on a line outside the diff, you still see it in the check summary, but not as an inline comment.
- The check needs a scan on the base branch to compare against. If the workflow has never run on
main, results can look incomplete. This is why the earlier workflow also triggers onpushtomain.
Common mistakes
- Reading the wrong branch. The Security tab defaults to the default branch. Use the branch filter to see alerts on your feature branch.
- Ignoring the category. If you scan several languages, each upload has its own category such as
/language:python. An alert is tied to its category, so a missing language usually means that matrix job failed or did not upload. - Fixing only the reported line. For data flow alerts, the reported location is the sink. The real fix may belong earlier in the path.
- Treating "Closed as fixed" as permanent. If the next scan finds the same problem, GitHub reopens the alert.
Exercise
A pull request changes one file, but the code scanning check lists an alert in a file the pull request did not touch. The same alert is also open on main. What is the most likely explanation, and where would you look to confirm it?
Show answer
The alert is probably not new. Check the alert page's Branches section and compare the pull request's results with main. If the alert exists on main with the same rule and location, it is an existing alert. It may also appear in the check summary if the pull request's changes affect the code path that reaches it. If it exists only on the pull request branch, the change introduced it indirectly, for example by adding a new source that reaches an existing sink.