Summary
A branch protection bypass can occur when retargeting a pull request preserves a stale official approval flag from its previous target branch. If the approval is trusted after the target changes, an attacker may merge changes without satisfying the protections configured for the new branch.
Affected context
This issue can affect pull request workflows that:
- Track approval or review state across pull request target-branch changes
- Use an
officialapproval flag as evidence that branch protection requirements were met - Do not recompute or invalidate approval state when a pull request is retargeted
- Permit the pull request to proceed based on stale authorization-related metadata
Exploit preconditions
- Attack surface: Pull request creation, update, and branch-retargeting workflows
- Required access: Ability to create or modify a pull request and change its target branch, subject to repository permissions
- Trigger point: Evaluation of branch protection after the pull request is retargeted
- Why exploitation is possible: The system may continue trusting an approval flag issued for a previous target branch instead of reevaluating requirements for the new protected branch
Why this happens
The underlying bug is a failure to invalidate security-sensitive state when the object it describes changes. An approval marker associated with one target branch remains trusted after retargeting makes that approval context stale.
This maps to CWE-284: Improper Access Control, because authorization decisions can be made using state that no longer reflects the applicable policy. The insecure pattern is treating cached approval metadata as authoritative without binding it to the protected branch, commit state, reviewer scope, and current policy evaluation.
Potential impact
- An attacker may merge changes without obtaining the reviews required for the destination branch
- Protected branches could receive unauthorized or insufficiently reviewed code
- Repository security controls may be weakened without an obvious failed-check signal
- Malicious changes could enter build, release, or deployment workflows
- Audit records may inaccurately represent which branch received the approval
General mitigation guidance
Mitigation generally focuses on making approval state explicitly dependent on the current authorization context.
Common defensive patterns include:
- Invalidate approvals and related flags whenever a pull request target branch, commit, policy, or review scope changes
- Reevaluate all branch protection requirements against the current target branch at merge time
- Bind approval records to immutable or verifiable identifiers for the target branch and reviewed commit
- Treat derived approval flags as untrusted cache data rather than authoritative authorization
- Apply least-privilege repository permissions and require independent checks for sensitive branches
- Maintain auditable, tamper-resistant records of branch protection decisions
How teams detect issues like this
Organizations can look for this class of defect through:
- Static analysis and code review checks for approval flags reused across branch or commit changes
- Tests that retarget pull requests between branches with different protection policies
- Regression tests covering branch changes, force-pushes, policy updates, reviewer changes, and stale review state
- Runtime policy checks that compare approval metadata with the current target branch and commit
- Audit monitoring for merges where approval timestamps or review targets do not match the merged branch
- Repository policies requiring server-side reevaluation immediately before merge

