MSBA-361 · Lesson 1 of 12 · 21 min
Code scanning concepts
▶ Video coming soon A video version of this lesson is on the way.
The security sessions at Skerry Outdoor Group moved from secrets and dependencies to the company's own code in the second half of November. Freya Abernathy-Oduya opened the first of them with a slide that had only two numbers on it. In MSBA-360 the team had dealt with credentials that leaked and with libraries written by other people. Both were real risks, she said, but both were in a sense someone else's mistake. The two numbers on the slide were about Skerry's own mistakes: 712 repositories classified confidential or restricted, which now had GitHub Code Security switched on through the enforced Skerry code security configuration, and 6,912 open code scanning alerts on their default branches after the first week of scans.
Priya Nair, observing from Tidewater as she prepared for the GH-500 exam, wrote the second number down twice to be sure. Tidewater's own public TrailCheck repository had produced eleven alerts when she switched on code scanning the month before, and she had found even eleven hard to work through. Seraphine Kowalik-Duarte, the application security engineer who ran the hands-on work, said the size of the number was less important than what was inside it, and that the first job was to understand what code scanning actually finds and how it finds it.
This course is the second half of the GitHub Advanced Security pair. MSBA-360 covered Secret Protection and supply chain security. This course covers GitHub Code Security, the product that includes code scanning with CodeQL, Copilot Autofix and security campaigns, and then the security operations that tie all the alert types together across an organization: security overview, configurations, roles, metrics and workflow integration.
What code scanning is
Code scanning is static analysis of source code to find security vulnerabilities and coding errors before they reach production. Static means the tool reads the code rather than running the application. It looks for patterns and data flows that are known to cause problems, such as user input that reaches a database query without being made safe, or a cryptographic function used with a weak setting.
GitHub's code scanning is a feature that receives results from analysis tools, stores them as alerts attached to a repository, shows them in pull requests and in the Security tab, and tracks each alert from the moment it appears until it is fixed or dismissed. The analysis itself can come from GitHub's own engine, CodeQL, or from third-party tools that produce results in a standard format called SARIF. Either way the alerts look the same to developers and can be managed with the same tools.
Code scanning is not the same as the other scanning features in the Advanced Security family, and the GH-500 exam expects candidates to keep them apart.
| Feature | What it examines | What it finds | Product |
|---|---|---|---|
| Code scanning | Your own source code | Vulnerabilities and coding errors in logic and data flow | GitHub Code Security |
| Secret scanning | Repository content and history, plus issues and other text | Credentials such as tokens, keys and passwords | GitHub Secret Protection |
| Dependabot alerts | The dependency graph | Known vulnerabilities in packages you depend on | Included with the dependency graph; dependency review needs Code Security for private repositories |
| Dependency review | Dependency changes in a pull request | Vulnerable or disallowed packages being added | GitHub Code Security for private repositories |
Seraphine summarized it for the room: secret scanning asks whether something sensitive is sitting in the code, Dependabot asks whether the code depends on something known to be broken, and code scanning asks whether the code itself is written in a way that can be attacked.
Products and plans
Since April 2025, GitHub has sold its security features as two products. GitHub Secret Protection covers secret scanning, push protection and related features. GitHub Code Security covers code scanning, CodeQL, Copilot Autofix for code scanning alerts, security campaigns, dependency review and premium security overview features. At launch the list prices were 19 US dollars per active committer per month for Secret Protection and 30 US dollars per active committer per month for Code Security, and both became available to GitHub Team organizations as well as Enterprise Cloud. The earlier bundle, GitHub Advanced Security, still exists as a name for customers who bought it and as the name of the overall family, which is why the exam is still called GitHub Advanced Security.
For public repositories on GitHub.com, code scanning with CodeQL is free. That is why Priya could switch it on for TrailCheck without a purchase. For private and internal repositories, organizations need a Code Security licence, counted by active committers: people who pushed commits to a repository with Code Security enabled during the billing period.
| Repository | Code scanning available? | What is needed |
|---|---|---|
| Public repository on GitHub.com | Yes | Nothing extra; switch it on |
| Private or internal repository, GitHub Team | Yes, with the add-on | GitHub Code Security for the organization |
| Private or internal repository, Enterprise Cloud | Yes, with the add-on or the older bundle | GitHub Code Security, or an existing GitHub Advanced Security licence |
| GitHub Enterprise Server | Yes, on supported versions | A Code Security or Advanced Security licence for the appliance, and Actions configured for CodeQL workflows |
At Skerry, the decision had been made in MSBA-291: Code Security would follow the data classification custom property. Repositories classified confidential or restricted were in scope, and about 430 active committers worked in them. Public and general repositories kept code scanning only where it was free.
Sources, sinks and data flow
Most serious web vulnerabilities have the same shape. Data enters the application from somewhere an attacker can influence, travels through the code, and reaches an operation that does something dangerous with it. Code scanning tools describe this with three terms.
| Term | Meaning | Examples |
|---|---|---|
| Source | A place where untrusted data enters | An HTTP request parameter, a form field, a file upload, a message from a queue |
| Sink | An operation that is dangerous if it receives untrusted data | A database query, a shell command, a file path, a page rendered to a browser |
| Sanitizer | Code that makes data safe for a particular sink | A parameterized query, an escaping function, a check against an allow list |
A data flow alert says, in effect, that the tool found a path from a source to a sink with no sanitizer suitable for that sink. The same input can be safe for one sink and dangerous for another: a value escaped for display in a web page is still dangerous if it is pasted into a shell command. Good tools therefore track which sanitizer protects which kind of sink.
To show what the alerts would look like, Seraphine put a deliberately simplified example on the screen, taken from a training repository rather than from production code.
// Illustrative only: unsafe pattern from a training repository
app.get("/orders", async (req, res) => {
const store = req.query.store; // source: user-controlled
const sql = "SELECT * FROM orders WHERE store = '" + store + "'";
const rows = await db.query(sql); // sink: query built from input
res.json(rows);
});
// Safer: a parameterized query keeps data separate from the SQL text
app.get("/orders", async (req, res) => {
const rows = await db.query("SELECT * FROM orders WHERE store = ?", [req.query.store]);
res.json(rows);
});The first version builds the query text by joining strings, so the value of the store parameter becomes part of the SQL itself. The second passes the value separately, so the database treats it only as data. Code scanning would raise an alert on the first version and not on the second. The lesson Seraphine wanted the group to take away was not the specific fix but the shape: source, path, sink, and whether anything on the path made the data safe.
CWE, CVE and severity
Code scanning alerts are classified using common vocabularies that the GH-500 security operations domain expects candidates to know.
| Term | What it identifies | Example |
|---|---|---|
| CWE (Common Weakness Enumeration) | A type of weakness in software | CWE-89, SQL injection; CWE-79, cross-site scripting |
| CVE (Common Vulnerabilities and Exposures) | A specific vulnerability in a specific product or version | A numbered vulnerability in one release of a library |
| GHSA (GitHub Security Advisory) | GitHub's identifier for an advisory in the GitHub Advisory Database | Used by Dependabot alerts and repository security advisories |
| CVSS | A scoring system for how serious a vulnerability is | A score from 0 to 10, grouped into low, medium, high and critical |
Code scanning alerts from your own code usually carry a CWE rather than a CVE, because the weakness is in code no one has catalogued. A CVE becomes relevant if the weakness is in software published to others and someone reports it; MSBA-360 covered how repository security advisories handle that.
Each code scanning alert also has two kinds of severity. The severity levels error, warning and note describe how serious a rule's finding is as a coding problem. The security severity levels critical, high, medium and low apply to security rules and are derived from scores that the CodeQL team assigns to each query. Branch protection and rulesets can block merges based on either kind, which lesson 11 covers.
Precision, recall and noise
No static analysis tool is perfect. It can miss real problems, which are false negatives, and it can report problems that are not real or not reachable, which are false positives. Tool designers trade one against the other. A tool tuned for high precision reports fewer false positives but may miss more; a tool tuned for high recall finds more real problems but buries them in noise.
CodeQL's default query suite is tuned for precision: it includes queries that GitHub judges to have a low false positive rate, because developers stop reading alerts that are often wrong. The extended suite, covered in lesson 2, adds queries with lower precision or lower severity for teams that want broader coverage and have time to triage it.
| Outcome | Real problem? | Alert raised? | Effect on the team |
|---|---|---|---|
| True positive | Yes | Yes | The alert is worth fixing |
| False positive | No | Yes | Wasted time; trust in the tool falls |
| False negative | Yes | No | Risk remains unseen |
| True negative | No | No | Nothing to do |
Freya's concern about the 6,912 alerts was mostly about trust. If the developers' first experience was a wall of alerts, many of them low severity or in test code, they would conclude the tool was noise. The plan for the coming weeks was therefore to triage carefully, fix the most serious alerts first, tune what was scanned, and stop new problems entering the code at the pull request.
Where alerts appear
Developers meet code scanning in three places. In a pull request, new alerts introduced by the change appear as annotations on the changed lines and as a check result. In the repository's Security tab, the code scanning alerts list shows all open alerts on the default branch and protected branches, with filters for tool, severity, rule and branch. In security overview, covered in lesson 6, owners and security managers see alerts across all repositories in an organization or enterprise.
The pull request is where code scanning does the most good. An alert raised before merging costs one developer a few minutes; an alert found months later in production code costs a ticket, a context switch, a review and a deployment. Skerry's goal for 2027, Freya said, was that most new alerts would be found and fixed in pull requests rather than discovered on the default branch.
Worked problem
Reading a first-week number
Skerry's first week of default setup produced 6,912 open alerts across 712 repositories: 41 critical and 388 high security severity, with the rest medium, low or non-security quality warnings. The commerce group wants to open one ticket per alert. What should the security team recommend?
Show solution
- Separate security alerts from code quality warnings and notes.
- Start with critical and high security severity alerts on production code: 429 alerts.
- Group them by rule and repository so that repeated patterns can be fixed together.
- Use pull request checks to stop new high-severity alerts while the backlog is reduced.
Answer: Do not open thousands of tickets. Triage the 429 critical and high security alerts first, group repeated patterns for campaigns, and block new high-severity alerts at the pull request.
Shifting left
Security people use the phrase shift left to mean finding problems earlier in the development process, which is drawn as further left on a timeline from writing code to running it in production. Code scanning in pull requests is one shift left. CodeQL in the developer's editor through the CodeQL extension for Visual Studio Code is further left. Push protection, which MSBA-360 covered, and dependency review in pull requests are shifts left for secrets and dependencies.
Priya asked whether shifting left meant Skerry could stop scanning the default branch. Seraphine said no. Default branch and scheduled scans still matter, because CodeQL's queries improve over time and a new query can find a problem in code that was merged clean a year ago. Scanning on a schedule catches those.
Tidewater in miniature
Priya's eleven TrailCheck alerts made a useful small example. Two were real: a path in a script built from an argument without checking it, and a regular expression that could be slow on unusual input. Six were in test files and two in a vendored copy of a mapping library, which she could exclude from analysis. One was a quality note. She fixed the two real ones in an afternoon and learned more from them than from any slide. The same steps, Seraphine said, would work at Skerry's scale, just with more help from automation.
Common mistakes
MistakeTreating code scanning as the same thing as secret scanning or Dependabot.
InsteadCode scanning analyzes your own code for vulnerabilities and errors; the others look for credentials and vulnerable dependencies.
MistakeAssuming every alert is a confirmed vulnerability.
InsteadStatic analysis produces false positives; triage before fixing, and dismiss with a reason when an alert is wrong.
MistakeTurning on the broadest query suite everywhere on day one.
InsteadStart with the default suite, which is tuned for precision, and broaden where teams can triage.
MistakeRelying only on scans of the default branch.
InsteadScan pull requests to prevent new problems, and keep scheduled scans to catch problems found by new queries.
Summary and key terms
- Code scanning is static analysis of your own source code, with results stored as alerts that GitHub tracks.
- Results come from CodeQL or from third-party tools that produce SARIF.
- GitHub Code Security includes code scanning, Copilot Autofix and campaigns; code scanning is free for public repositories on GitHub.com.
- Data flow alerts describe a path from an untrusted source to a dangerous sink without a suitable sanitizer.
- Alerts are classified by CWE and have both a severity and, for security rules, a security severity.
- Precision and recall trade against each other; the default CodeQL suite favours precision.
- Finding problems in pull requests, earlier in development, is cheaper than finding them later.
- Code scanning
- GitHub's feature for running static analysis on source code and tracking the results as alerts.
- CodeQL
- GitHub's semantic code analysis engine, which treats code as data that can be queried.
- SARIF
- Static Analysis Results Interchange Format, a standard JSON format for analysis results.
- Source
- A place where untrusted data enters an application.
- Sink
- An operation that is dangerous if it receives untrusted data.
- Sanitizer
- Code that makes data safe for a particular kind of sink.
- CWE
- Common Weakness Enumeration, a catalogue of software weakness types.
- Security severity
- The critical, high, medium or low rating attached to security queries.
- False positive
- An alert that reports a problem that is not real.
- Shift left
- Finding and fixing problems earlier in the development process.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Which feature would find a hard-coded cloud key, and which would find a query built from user input?
Show answer
Secret scanning finds the key; code scanning finds the injection-prone query.
Why is a CodeQL alert in your own code usually classified by CWE rather than CVE?
Show answer
The weakness is in code nobody has catalogued as a published vulnerability, so it has a weakness type but no vulnerability identifier.
Why keep scheduled scans when pull requests are already scanned?
Show answer
New and improved queries can find problems in code that was merged before the query existed.
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.