Sub topic 9
Triaging Alerts and Requiring Scan Results Before Merge
This chapter assumes you can read a CodeQL workflow, you know how alerts appear in the Security tab and on pull requests, and you have used branch protection or rulesets on GitHub. It covers how to decide what to do with each alert and how to stop merges when scanning finds serious problems.
Why triage matters
A scan that reports alerts nobody reviews adds noise without adding safety. Triage is the process of reviewing each alert and giving it a decision. Every open alert should end in one of three states: fixed, dismissed with a reason, or deliberately left open with an owner.
Triage workflow
Work through an alert in this order:
- Read the alert message and the data flow path. Confirm that the source is attacker-controlled and that nothing on the path sanitizes the value.
- Check the severity and the rule ID. Security severity (critical, high, medium, low) is separate from the rule's problem severity (error, warning, note).
- Decide whether the alert is real, and act on it.
Dismissing an alert requires a reason. GitHub offers these:
| Reason | Use it when |
|---|---|
| False positive | The code is not vulnerable, for example because a sanitizer the query does not recognize is in use. |
| Used in tests | The code only runs in test or example paths. |
| Won't fix | The risk is real but accepted. Add a comment saying why. |
Always add a dismissal comment. Dismissed alerts stay visible under the closed filter, and the comment is the record that your team reviewed the risk. An alert is closed automatically as fixed when a later scan of the same branch no longer finds it.
Triage flow
Requiring scan results before merge
Alerts on pull requests are only advice until you enforce them. You enforce them with a repository ruleset or a branch protection rule. Both offer two separate controls that work together.
Require the status check
The workflow job appears as a status check. Mark it as required so a pull request cannot merge until the job passes. For the workflow in this tutorial, the check names look like Analyze (javascript-typescript) and Analyze (python). Matrix jobs produce one check per language, so require each one.
A required check only guarantees that the scan ran and finished. A scan that completes and finds a serious alert still passes this check.
Require code scanning results
To block on findings, add the rule "Require code scanning results" to your ruleset, or the equivalent setting in branch protection. You choose:
- Which tool must report results, such as CodeQL.
- The alert severity threshold that blocks the merge, for example errors only or high or higher for security alerts.
The merge is then blocked when the pull request introduces an alert at or above the threshold. It is also blocked when results from the required tool are missing.
Common errors
- A required check stays "Expected". The check name in the rule does not match the job name. Run the workflow once, then pick the check from the list instead of typing it.
- Pull requests from forks have no results. Forked pull requests get a read-only token, so uploading results can fail. Check the permissions and the fork policy for your repository.
- Alerts differ between a pull request and
main. A pull request is scanned on its merge commit. Alerts that exist only on the branch appear as pull request alerts, while older alerts stay onmain. - A blocked merge for an alert that is not yours. Fix it, or dismiss it with a reason if it is a false positive. Dismissing is visible and auditable, so use it only when justified.
Exercise
Your ruleset requires the Analyze (python) status check, but a pull request that adds a SQL injection still merges. Why, and what should you add?
Show answer
The status check only confirms the scan job finished successfully, and CodeQL finding an alert does not fail the job. Add the "Require code scanning results" rule for CodeQL with a severity threshold, such as high or higher for security alerts, so that new alerts at or above that level block the merge.
Exercise
An alert flags a query built from user input, but the value passes through your own validation function that CodeQL does not recognize. Which dismissal reason fits, and what should you write in the comment?
Show answer
Use "False positive". Name the validation function and explain why it makes the value safe, so reviewers can check the reasoning later.