Repository default branch requires code owner approval for changes to owned code
GitHub repository default branch requires Code Owners approval for pull requests that modify paths declared in CODEOWNERS. This protection can be enforced through classic branch protection or repository rulesets.
Risk
Without required Code Owners review, non-owners can merge changes to sensitive code, undermining integrity. This increases the chance of malicious code injection, hidden backdoors, or fragile changes that enable data exfiltration or cause outages, impacting confidentiality and availability.
Run this check with Prowler
Run in Prowler Cloudprowler github --checks repository_default_branch_requires_codeowners_reviewRecommendation
Enforce Code Owners review on the default branch and keep CODEOWNERS accurate and team-based.
Apply least privilege, require status checks and signed commits, extend protections to admins, and audit ownership regularly. Co-own critical paths to ensure coverage and reduce single-point approval gaps.
Remediation
CLI
gh api -X PATCH repos/<OWNER>/<REPO>/branches/<DEFAULT_BRANCH>/protection/required_pull_request_reviews -f require_code_owner_reviews=trueTerraform
resource "github_branch_protection" "<example_resource_name>" {
repository_id = "<example_resource_id>"
pattern = "<DEFAULT_BRANCH>"
required_pull_request_reviews {
require_code_owner_reviews = true # Critical: enforces CODEOWNERS approval on the default branch
}
}Other
Check Code
from typing import List
from prowler.lib.check.models import Check, CheckReportGithub
from prowler.providers.github.services.repository.repository_client import (
repository_client,
)
class repository_default_branch_requires_codeowners_review(Check):
"""Check if code owner approval is required for changes to owned code
This class verifies whether each repository requires code owner review for changes to code they own.
"""
def execute(self) -> List[CheckReportGithub]:
"""Execute the Github Repository Code Owner Approval Requirement check
Iterates over all repositories and checks if they require code owner review for changes.
Returns:
List[CheckReportGithub]: A list of reports for each repository
"""
findings = []
for repo in repository_client.repositories.values():
if repo.default_branch.require_code_owner_reviews is not None:
report = CheckReportGithub(metadata=self.metadata(), resource=repo)
if repo.default_branch.require_code_owner_reviews:
report.status = "PASS"
report.status_extended = f"Repository {repo.name} requires code owner approval for changes to owned code."
else:
report.status = "FAIL"
report.status_extended = f"Repository {repo.name} does not require code owner approval for changes to owned code."
if (
repo.default_branch.require_code_owner_reviews_source
== "ruleset_not_active"
):
report.status_extended = f"Repository {repo.name} has code owner approval configured in a ruleset, but the ruleset is not active."
findings.append(report)
return findingsReferences
- https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches#require-review-from-code-owners
- https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule
- https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets