A security problem in an application rarely appears out of nowhere. In many cases, the weakness has been sitting in the source code, a dependency, a configuration file, or an authentication flow for weeks or even months. It becomes a serious incident when someone discovers and exploits it, often at a time when the development team is least prepared to respond.
Consider a common situation in an ASP.NET Core application. A developer adds a new API endpoint that accepts a customer ID and retrieves the corresponding order details. The endpoint works correctly during development, and the pull request passes its build and unit tests. However, the implementation does not verify whether the authenticated user is authorized to access that customer's orders. The code is technically correct, but the missing authorization check creates a security vulnerability.
A traditional code review may catch this issue, but that depends on the reviewer's experience, available time, and understanding of the application. As repositories grow, manually checking every method, dependency, configuration file, and authentication flow becomes increasingly difficult.
GitHub provides several security capabilities that help development teams identify these problems earlier. Code scanning, Dependabot, secret scanning, dependency review, and repository security settings address different parts of the application security lifecycle.
The important part is understanding what each feature detects, how to configure it, and how to make security checks a normal part of development rather than something performed only after an incident.
Understand the Security Risks Inside a Repository
Before enabling security tools, it helps to understand where vulnerabilities commonly enter an application. A repository contains more than business logic. It includes dependencies, configuration, authentication rules, deployment workflows, scripts, and sometimes sensitive information.
Each area introduces a different category of risk.
For example, an application might use an outdated version of a NuGet package containing a known vulnerability. The application code may be well-written, but the vulnerable dependency can still expose it to an attack. In another situation, a developer may accidentally commit an API key into a configuration file. The application might continue working normally, but anyone with access to the repository could potentially obtain the credential.
There are also vulnerabilities that come directly from application logic. An API might construct a database query using untrusted input, expose sensitive information through an error response, or perform an administrative operation without checking the user's permissions.
These problems cannot all be detected using the same tool. A dependency scanner cannot reliably identify every authorization mistake in business logic, and a static code analyzer cannot replace a credential scanner.
A practical repository security strategy therefore combines multiple checks:
Security area | Typical problem | GitHub capability |
|---|
Source code | SQL injection, insecure data handling, missing security checks | Code scanning with CodeQL |
Dependencies | Known vulnerabilities in third-party packages | Dependabot alerts |
Pull request dependencies | Introduction of vulnerable packages | Dependency review |
Credentials | Exposed API keys, tokens, passwords | Secret scanning |
Git pushes | Accidentally committing supported secrets | Push protection |
Repository visibility and access | Unauthorized access to code and security findings | Repository permissions and rules |
The goal is to identify a problem as close as possible to the point where it is introduced. Finding a vulnerable dependency during a pull request is generally easier to address than discovering it after deployment.
Find Vulnerabilities in Source Code With CodeQL
CodeQL is GitHub's code analysis engine for identifying security vulnerabilities and coding errors. Instead of relying only on simple text matching, it analyzes source code and uses queries to identify potentially dangerous patterns and relationships between different parts of an application.
This is particularly useful for problems where the vulnerability depends on how data moves through the application.
For example, consider an API that accepts a search term from a user and constructs a SQL query.
[HttpGet("search")]
public IActionResult Search(string name)
{
var query =
"SELECT * FROM Customers WHERE Name = '" + name + "'";
var result = _database.ExecuteQuery(query);
return Ok(result);
}
The endpoint accepts external input and directly combines it with a SQL statement. An attacker could supply specially constructed input that changes the meaning of the query.
The problem is not simply that the code contains a SQL statement. The security risk comes from allowing untrusted input to influence the query structure.
A safer implementation uses parameterized queries:
[HttpGet("search")]
public IActionResult Search(string name)
{
var query =
"SELECT * FROM Customers WHERE Name = @Name";
var result = _database.ExecuteQuery(
query,
new { Name = name });
return Ok(result);
}
The database receives the search value as a parameter instead of interpreting it as part of the SQL command.
This is the kind of issue that static security analysis can help identify. CodeQL supports analysis of data flow, allowing it to examine how potentially untrusted values move through an application and whether they reach sensitive operations.
For a repository using supported languages, administrators can configure CodeQL through GitHub's default setup or advanced setup. Default setup is a convenient starting point because GitHub selects the languages and analysis configuration automatically. Advanced setup provides more control over the workflow and query configuration.
Configure CodeQL using GitHub Actions
For teams that need a customizable workflow, CodeQL can be integrated into GitHub Actions.
The following example demonstrates an advanced setup for a C# repository:
name: CodeQL Security Analysis
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '30 2 * * 1'
jobs:
analyze:
name: Analyze CSharp Code
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [csharp]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: autobuild
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
The workflow runs analysis when code is pushed to the main branch, when a pull request targets that branch, and on the scheduled weekly run. The scheduled scan is useful because not every security issue is introduced through a new pull request. Changes in dependencies, analysis rules, or the surrounding code can make an existing problem worth investigating again.
The security-events: write permission allows the workflow to upload code scanning results to GitHub. The other permissions are kept read-only because the analysis job does not need to modify repository content.
For a more complex .NET solution, review the build requirements and CodeQL language configuration before using autobuild. Some repositories require an explicit build step or a different configuration.
Once the analysis completes, findings appear in the repository's code scanning results. Depending on the configuration, new alerts can also appear as annotations on pull requests. Developers can inspect the affected code, understand the reported issue, and review the suggested remediation information.
Detect Vulnerable Dependencies With Dependabot
Modern applications depend on libraries maintained by external developers and organizations. These dependencies save development time, but they also introduce security risks when vulnerabilities are discovered in the packages an application uses.
Consider an ASP.NET Core application that uses a third-party package for processing uploaded documents. The package works correctly, but a security vulnerability is later reported in the version used by the application.
The application team may not be aware of the issue unless someone regularly checks the package's security advisories.
Dependabot helps automate this process. It uses the repository's dependency information to identify packages with known vulnerabilities and creates alerts when affected dependencies are detected.
For example, a project might contain the following package reference:
<ItemGroup>
<PackageReference Include="Example.Library"
Version="1.2.0" />
</ItemGroup>
If the dependency is affected by a published security advisory, Dependabot can notify the repository maintainers and provide information about the affected package and available remediation.
Developers can review the alert, examine the recommended version, and update the package after checking compatibility with the application.
Dependabot can also create security update pull requests when a suitable fix is available. This gives developers an opportunity to review and test the update through their existing CI process instead of manually searching for every affected package.
However, automatically accepting every dependency update is not a good security strategy. A newer version may introduce breaking changes, alter application behavior, or require additional configuration. Run the relevant tests and review the package changes before merging.
For larger repositories, enabling Dependabot alerts and security updates provides a useful baseline for keeping third-party dependencies under control.
Review New Dependencies Before Merging Pull Requests
Dependabot alerts help identify vulnerabilities in dependencies already present in a repository. Dependency review addresses a different question: Does the pull request introduce a dependency that has a known security vulnerability?
This distinction is important because a pull request can introduce a new package that is vulnerable even when the existing dependency set is clean.
GitHub's Dependency Review feature can inspect dependency changes in pull requests and report vulnerable packages before they are merged. Teams can also use the Dependency Review Action to make dependency checks part of a GitHub Actions workflow.
For example:
name: Dependency Review
on:
pull_request:
branches:
- main
permissions:
contents: read
jobs:
dependency-review:
name: Review Dependencies
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: high
This workflow checks dependency changes introduced by a pull request and fails the check when it identifies vulnerabilities at the configured severity threshold.
The threshold is a policy decision. Some teams may block only high and critical findings, while applications handling financial, healthcare, or sensitive customer data may adopt stricter rules.
The important point is to make the policy explicit. If a high-severity dependency finding appears, developers should understand why the update is required and what process to follow when an immediate upgrade is not possible.
Prevent Credentials From Being Exposed With Secret Scanning
Credentials are another common source of repository security incidents. A developer might commit an API key while testing an integration, include a database password in a configuration file, or accidentally add a private key to a deployment script.
These mistakes can happen even in experienced teams, especially when a repository contains many configuration files and developers work across multiple environments.
GitHub Secret Scanning examines repository content for supported secret patterns and reports detected credentials. Push protection provides an additional preventive control by blocking supported secrets before they are pushed to the repository.
For example, an insecure configuration might look like this:
{
"PaymentService": {
"ApiKey": "actual-production-api-key"
}
}
A safer approach is to keep the credential outside the repository:
{
"PaymentService": {
"ApiKey": ""
}
}
The application can then retrieve the actual value from an environment variable or an approved secret-management service.
Secret scanning is useful even when developers follow these practices because accidental exposure is still possible through documentation, test files, scripts, or copied configuration.
If a real credential is detected, deleting it from the latest commit is not enough. The credential should be revoked or rotated, and the team should investigate whether it was exposed through earlier commits, logs, or other systems.
Make Security Findings Part of the Pull Request Process
Security tools provide limited value if their findings are ignored. A repository may have hundreds of alerts, but without ownership and a clear remediation process, the security backlog can continue growing.
The pull request workflow is a good place to establish accountability because developers are already reviewing the changes that introduce new behavior.
For example, a team can configure the following checks:
CodeQL analysis for source-code vulnerabilities.
Dependency review for vulnerable packages introduced by pull requests.
Secret scanning and push protection for credential exposure.
Build and unit tests for application correctness.
These checks should be configured according to the repository's risk and available GitHub features. Where appropriate, repository administrators can make selected checks required before merging.
Code scanning results can appear directly in pull requests as annotations when the relevant configuration supports pull request analysis. This helps reviewers inspect the affected lines instead of navigating through several unrelated dashboards.
However, not every security finding should automatically block every pull request. Teams should define severity thresholds and exception procedures. A low-risk informational alert may require review, while a critical vulnerability in an exposed application component may need to prevent merging until it is resolved.
The important thing is that exceptions are documented and assigned to someone responsible for reviewing them. Otherwise, security checks gradually become warnings that developers learn to ignore.
Manage Security Findings Across Multiple Repositories
A development organization may maintain dozens or hundreds of repositories. Checking each repository individually makes it difficult to understand the overall security position.
GitHub Security Overview helps organizations examine security coverage and findings across repositories. Teams can use it to understand where security features are enabled, review code scanning and Dependabot information, and coordinate remediation efforts.
For example, an organization might discover that several repositories have code scanning enabled, but a number of important services still have no dependency alerts configured. This is not simply a tooling issue. It indicates that security practices are inconsistent across development teams.
Security campaigns can also help organize remediation work by grouping related alerts, assigning responsibilities, and tracking progress toward reducing risk.
For engineering managers and security teams, this visibility is valuable because it changes the discussion from how many alerts exist to which repositories and vulnerabilities need attention first.
A repository containing an old, unused development dependency does not necessarily carry the same risk as an internet-facing application with an exploitable vulnerability in an authentication component. Prioritization should consider severity, exposure, exploitability, business impact, and the availability of a fix.
Common Mistakes When Securing GitHub Repositories
One mistake is enabling security scanning without deciding who owns the findings. Alerts may appear in the repository, but nobody investigates them. Assign clear ownership to application teams and define a reasonable remediation process for high-risk issues.
Another mistake is treating a clean security dashboard as proof that an application is secure. Static analysis has limitations, secret scanning detects supported patterns, and dependency scanners focus on known vulnerabilities. None of these tools can guarantee that an application has no security weaknesses.
Teams also sometimes enable security checks but allow every pull request to bypass them. Exceptions are sometimes necessary, but they should be controlled, reviewed, and documented rather than becoming the normal way of merging code.
Finally, avoid focusing exclusively on newly introduced vulnerabilities. Existing repositories may contain older problems that were never detected or were previously ignored. Run scheduled scans, review existing alerts, and gradually reduce the backlog based on risk.
Build a Continuous Repository Security Practice
Repository security works best when it is integrated into everyday development. Developers should understand that security is part of implementing a feature, not a separate activity that begins before production deployment.
Start by enabling the dependency graph, Dependabot alerts, secret scanning, and other available security features. Configure CodeQL for supported languages, add dependency review to pull requests, and enable push protection where available.
Next, define which checks must pass before merging. Make sure the team knows how to investigate alerts, update vulnerable packages, rotate exposed credentials, and request an exception when a vulnerability cannot be fixed immediately.
For organizations managing multiple repositories, use centralized security visibility to identify gaps in coverage and prioritize remediation work. Review the security process regularly because new dependencies, application features, and development workflows can introduce risks that existing controls do not cover.
The objective is not to collect the largest possible number of security alerts. It is to identify meaningful problems early, give them to the right people, and make sure they are resolved before they become production incidents.
Summary
Security vulnerabilities can enter a repository through application code, third-party dependencies, configuration files, credentials, and development workflows. Relying only on manual code reviews makes it difficult to identify every issue, particularly as applications and development teams grow.
GitHub provides several capabilities that address these risks. CodeQL helps identify vulnerabilities in source code, Dependabot detects vulnerable dependencies, dependency review checks new packages introduced by pull requests, and secret scanning helps identify exposed credentials. Repository security settings and Security Overview help teams enforce and monitor these practices.
When these capabilities are combined with automated tests, required pull request checks, clear ownership, and regular remediation, security becomes part of the development lifecycle. Finding a vulnerability during development is considerably easier to manage than responding after an attacker has already exploited it.
Join the conversation! Your thoughts help the community grow.