Branch Protection Not Enforced

Main and release branches accept direct pushes, force pushes or unreviewed merges, so a single account can change the code that is built and deployed without review.

SeverityMedium
CVSS 3.16.5 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N Open in the calculator
CVSS 4.07.1 CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-266: Incorrect Privilege Assignment
OWASP Top 10A06:2025 Insecure Design
MITRE ATT&CKT1195.002 Compromise Software Supply Chain
CategorySecurity Misconfiguration

Description

The repositories' default and release branches, which feed builds and deployments, are not protected by enforced rules on the hosting platform. Typical gaps are that contributors can push directly to the branch without a pull or merge request; that changes can be merged without approval from another reviewer or, where the platform allows it, with the author's own approval; that required status checks, such as tests and security scans, are not enforced; that force pushes and branch deletion are allowed, so history can be rewritten; that administrators are exempt from the rules; and that code owner review is not required for sensitive paths such as pipeline definitions and infrastructure code. Rules that exist but are not enforced, for example rules on a branch name pattern that does not match the release branch, or rules that apply only to some users, leave the same gaps.

Without these controls, a single account, whether a developer acting alone, a malicious insider or an attacker who has compromised a developer account or access token, can push malicious code, such as a backdoor or code that steals data or credentials, into the branch that is built and released without anyone else seeing it first, and can change or remove pipeline definitions and their security checks along with it. Where the branch deploys automatically, the change can reach production within minutes, and force pushes can then remove the evidence from the branch history. The attacker needs write access to the repository, so the weakness exposes nothing by itself, but it removes the review that would otherwise stop a single compromised account from changing production software.

The weakness is identified by reviewing branch protection rules or rulesets on GitHub, protected branch settings on GitLab, or branch policies in Azure Repos for each repository that feeds production, and by checking the audit log for direct pushes and bypasses. Where agreed, it can be confirmed by attempting a direct push of a harmless change with a test account that has ordinary write access.

Remediation

Enforce protection on every branch that feeds builds and deployments:

  • Require changes to reach the default and release branches through pull or merge requests, with at least one approval from someone other than the author, and dismiss existing approvals when new commits are pushed.
  • Require status checks, such as builds, tests and security scans, to pass before merging, and require branches to be up to date with the target branch.
  • Block force pushes and branch deletion, and apply the rules to administrators as well, keeping any bypass to a small, audited break-glass group.
  • Require code owner review for sensitive paths, such as CI/CD workflow files, infrastructure templates and authentication code, using a CODEOWNERS file.
  • Apply the rules at organisation level, for example through organisation rulesets, so that new repositories are protected by default, and consider requiring signed commits.
  • Limit write access to the people who need it, and require multi-factor authentication for every account with access to the organisation's repositories.

Review the audit log for direct pushes and bypasses made before the rules were enforced. Confirm the fix by checking the rules on each repository that feeds production, and by confirming that a direct push to a protected branch is rejected.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Source Code and Supply Chain Findings

Every Source Code and Supply Chain finding