MSBA-361 · Lesson 11 of 12 · 18 min
Integrating with development workflow
▶ Video coming soon A video version of this lesson is on the way.
By the eleventh session, the backlog was shrinking, but Freya pointed out that a shrinking backlog with an open tap is a temporary achievement. New code was still adding alerts every day. The last technical session was about closing the tap: making security part of how code is written, reviewed and merged, so that problems are prevented rather than collected.
The developer's path
A change at Skerry passed through a sequence of points where security tooling could act. Each point has a different cost and a different chance of catching a problem.
| Point | Control | What it stops |
|---|---|---|
| Editor | CodeQL extension for Visual Studio Code; linters | Problems before they are committed, for developers who use it |
| Push | Secret scanning push protection | Credentials entering the repository |
| Pull request | Code scanning and dependency review checks | New alerts and vulnerable or disallowed dependencies |
| Review | Autofix suggestions and reviewers who read alerts | Merging changes with unexplained alerts |
| Merge | Rulesets requiring code scanning results | Merging when serious alerts remain |
| After merge | Default branch and scheduled scans, campaigns | Problems found by new queries; existing backlog |
The earlier controls are cheaper but less complete. The later ones are complete but more expensive. A program needs both, which is why MSBA-360's push protection, this course's code scanning in pull requests and the scheduled scans all remain in place.
Code scanning checks in pull requests
When code scanning runs on a pull request, it reports a check for each tool and analysis. The check summarizes new alerts introduced by the change compared with the base branch, and the alerts appear as annotations on the changed lines. By default, a check can pass or fail based on the alerts it finds, but a failing check alone does not stop merging unless something requires it.
The CodeQL check and the Code scanning results check play different roles. The first reports whether the CodeQL analysis job ran successfully, like any workflow job. The second reports whether the analysis found new alerts that meet the configured threshold. Teams that require only the first will block merges when analysis breaks, but not when it finds problems.
Requiring code scanning results with rulesets
Rulesets, which MSBA-291 covered for branch and tag rules, include a rule that requires code scanning results before merging. The rule names the tools that must have reported results, and for each tool sets two thresholds: an alerts threshold based on the severity levels error, warning and note, and a security alerts threshold based on security severity. A pull request that introduces alerts at or above a threshold cannot be merged until they are fixed or dismissed.
| Threshold setting | Blocks merge when the pull request introduces |
|---|---|
| Security alerts: critical | Critical security alerts only |
| Security alerts: high or higher | High or critical security alerts |
| Security alerts: medium or higher | Medium, high or critical security alerts |
| Security alerts: all | Any security alert |
| Alerts: errors | Alerts with error severity |
| Alerts: errors and warnings | Error and warning alerts |
| Alerts: all | Any alert, including notes |
| None | Nothing; the result is informational |
Skerry's organization ruleset, called Code scanning gate, targeted repositories with data-classification confidential or restricted and required results from CodeQL with the security threshold set to high or higher and the general alerts threshold set to none. Third-party tools were added only for the repositories where they ran: the firmware analyzer for firmware repositories, the infrastructure scanner for platform repositories.
{
"name": "Code scanning gate",
"target": "branch",
"enforcement": "evaluate",
"conditions": {
"ref_name": { "include": ["~DEFAULT_BRANCH"], "exclude": [] },
"repository_property": {
"include": [{ "name": "data-classification", "property_values": ["confidential", "restricted"] }]
}
},
"rules": [{
"type": "code_scanning",
"parameters": { "code_scanning_tools": [
{ "tool": "CodeQL", "security_alerts_threshold": "high_or_higher", "alerts_threshold": "none" }
]}
}],
"bypass_actors": []
}Following MSBA-291's practice, the ruleset ran in evaluate mode from November 2 to November 16, which recorded what would have been blocked without blocking anything. Rule insights showed 57 pull requests in two weeks that would have been stopped. Seraphine read all of them. Forty-four introduced real high-severity alerts; nine were caused by a single noisy query in one framework, which the data group fixed with a model pack; four were in pull requests that only moved files and triggered alerts on code that already had them. The ruleset became active on November 16.
Dismissals and the merge gate
A merge gate creates pressure to dismiss alerts to get unblocked. Delegated dismissal from lesson 9 handles that pressure in sensitive repositories, because a dismissal request must be approved. In other repositories, dismissal remains possible but leaves a record, and the monthly dismissal review samples them. Freya also kept the ruleset's bypass list empty. If an urgent fix had to merge despite an alert, the route was an approved dismissal with an expiry date for revisiting, not a bypass.
Merge queues and required checks
Repositories using a merge queue, introduced in MSBA-291, run checks on the combination of a pull request and the changes ahead of it. Code scanning must run on the merge_group event for the required results to be available in the queue. Default setup does not add that trigger, so the checkout monorepo's advanced workflow listed merge_group among its triggers; without it, every queued pull request would have waited for a check that never came.
Dependency review and secrets in the same gate
MSBA-360 introduced dependency review as a required check for confidential and restricted repositories. In practice, the pull request gate combined three controls: code scanning results, dependency review and the push protection that had already acted on the push. The GH-500 security operations domain describes this as cross-suite enforcement, rulesets and policies working across Code Security, Secret Protection and supply chain features together. A developer sees all three in one pull request.
| Control in the pull request | Product | Required at Skerry for |
|---|---|---|
| Code scanning results (CodeQL) | Code Security | Confidential and restricted repositories |
| Code scanning results (third-party) | Code Security | Repositories where the tool runs |
| Dependency review | Code Security for private repositories | Confidential and restricted repositories |
| Push protection (before the pull request) | Secret Protection | All repositories with Secret Protection |
Making it easy to do the right thing
Gates catch problems; habits prevent them. The session's last half was about the habits.
Shared fixes. The commerce team's parameterized query helper and the store portals' output encoding helper were moved into shared packages, with documentation linked from campaign descriptions and from rule help where possible.
Editor feedback. Leocadie ran two short sessions showing developers how to run CodeQL queries locally with the Visual Studio Code extension, mostly for the data group's custom pack. Uptake was modest, which was fine; the pull request remained the main point of feedback.
Copilot instructions. Several teams used GitHub Copilot, as MSBA-303 and MSBA-304 described. The commerce team added repository instructions asking Copilot to use the shared query and encoding helpers, so that suggested code started from the safe pattern.
Security champions. The forty champions from lesson 9 became the first people to read alerts in their teams' pull requests, and met monthly with the application security team to share patterns.
Pull request templates. For confidential and restricted repositories, the template asked authors to say whether the change handled new input from users or other systems, which prompted reviewers to look for the source, sink and sanitizer pattern from lesson 1.
Tidewater's version
Priya applied a smaller version to TrailCheck. A repository ruleset on main required CodeQL results with the high-or-higher security threshold, and a pull request template asked contributors whether their change read files or user input. Because TrailCheck accepted contributions from volunteers' forks, the code scanning check ran on pull requests from forks with read-only permissions, which code scanning supports for public repositories. Her first blocked pull request was her own: a new route-import feature that built a file path from an uploaded file's name. Autofix suggested a fix; she preferred an allow list, wrote it, and merged.
Worked problem
Designing a gate
A team wants to require CodeQL results with the threshold set to all alerts on a repository with 300 existing medium and low alerts. Developers fear every pull request will be blocked. What should the security team explain and recommend?
Show solution
- Explain that thresholds apply to alerts the pull request introduces, not to existing alerts on the base branch.
- Point out that all alerts includes notes and low-severity quality findings, which will block for minor issues.
- Recommend high or higher for security alerts and none or errors for general alerts.
- Run the ruleset in evaluate mode for two weeks and review what it would block before activating.
Answer: Existing alerts do not block new pull requests, but an all-alerts threshold will block for minor new findings. Start with high or higher for security alerts, evaluate for two weeks, then activate.
When the gate is wrong
No query is perfect, and a merge gate built on code scanning will sometimes block a pull request for an alert that is not a real problem. How the security team handles that moment decides whether developers trust the gate. Skerry's process had three parts. The developer dismisses the alert with a reason, which in restricted repositories becomes a dismissal request. The app security team aims to answer within one working day. And if the same rule produces the same false positive in several repositories, the team fixes the cause by tuning the query or adding a model, as the data group did in November, instead of approving the same dismissal over and over.
| Signal | Response |
|---|---|
| One false positive in one repository | Approve the dismissal with a clear comment |
| The same false positive across several repositories | Tune the query, add a model or exclude the path in the configuration file |
| Many dismissal requests from one team | Talk to the team; the rule may not fit their framework, or they may need help with the fix |
| Dismissal requests waiting more than a day | Add reviewers or adjust the target; slow approvals push people toward workarounds |
Code review with security in mind
Tools find patterns; reviewers find intent. Seraphine's short guide for reviewers asked three questions of any pull request in a confidential or restricted repository. Does this change accept input from somewhere new? Does it change who can reach an existing function? Does it change what is logged or returned? A yes to any of them meant reading the code scanning annotations carefully and, if there were none, asking why not, since a new input with no analysis may mean the code is in a path the configuration excludes.
Reviewers were also asked to read Autofix commits with the same care as human ones. A commit message that says it fixes an alert is a claim to check, not a reason to approve, and lesson 4's sample had shown that a fix can close one path and leave another.
What changed in November
By November 20, four days after the gate became active, Freya could report three early signs. High and critical alerts reaching the default branch had fallen sharply. Dismissal requests had risen but were being answered within the one-working-day target. And no release had been held up by the gate, because the evaluate period had removed the noisiest rule before enforcement. She was careful to call these early signs, not results, since four days is too short to judge a control.
Common mistakes
MistakeRequiring only the CodeQL job check.
InsteadRequire code scanning results with thresholds, which block on findings rather than only on failed analysis.
MistakeSetting the strictest thresholds on day one.
InsteadStart with high or higher for security alerts and test in evaluate mode.
MistakeUsing ruleset bypass for urgent merges with alerts.
InsteadUse an approved, documented dismissal with a revisit date.
MistakeForgetting the merge_group trigger in repositories with a merge queue.
InsteadAdd merge_group so required results are available in the queue.
Summary and key terms
- Security controls act at different points: editor, push, pull request, review, merge and after merge.
- Code scanning reports checks and annotations on pull requests for alerts the change introduces.
- Rulesets can require code scanning results with separate thresholds for general and security alerts.
- Evaluate mode shows what a gate would block before it is enforced.
- Delegated dismissal manages the pressure a merge gate creates.
- Merge queues need code scanning on the merge_group event.
- Shared fixes, editor feedback, Copilot instructions, champions and templates prevent problems before gates are needed.
- Code scanning results rule
- A ruleset rule that requires code scanning tools to report results and blocks merging when new alerts meet a threshold.
- Security alerts threshold
- The security severity at or above which new security alerts block merging.
- Alerts threshold
- The error, warning or note level at or above which new alerts block merging.
- Evaluate mode
- A ruleset enforcement status that records what would be blocked without blocking.
- merge_group
- The workflow event that runs checks for entries in a merge queue.
- Cross-suite enforcement
- Rules and policies that combine Code Security, Secret Protection and supply chain controls.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Do existing alerts on the base branch block a pull request under a code scanning results rule?
Show answer
No; thresholds apply to alerts the pull request introduces.
What should a repository with a merge queue add to its CodeQL workflow?
Show answer
The merge_group trigger.
Why keep the ruleset's bypass list empty?
Show answer
So urgent cases go through an approved, recorded dismissal rather than an untracked bypass.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.