Default Branch Should Restrict Who Can Push To It
policy name: pushes_are_not_restricted
severity: LOW
Description
By default, commits can be pushed directly to protected branches without going through a Pull Request. Restrict who can push commits to protected branches so that commits can be added only via merges, which require Pull Request.
Threat Example(s)
An attacker with write credentials may introduce vulnerabilities to your code without your knowledge. Alternatively, contributors may commit unsafe code that is buggy or easy to exploit that could have been caught using a review process.
Remediation
Note: The remediation steps apply to legacy branch protections, rules set-based protection should be updated from the rules set page
- Make sure you have admin permissions
- Go to the repo’s settings page
- Enter ‘Branches’ tab
- Under ‘Branch protection rules’
- Click ‘Edit’ on the default branch rule
- Check ‘Restrict who can push to matching branches’
- Choose who should be allowed to push
- Click ‘Save changes’