How the attack works
Protected branches decide who may push, merge and force push to a branch, and whether code owner approval is required. They also gate CI/CD: protected variables and protected runners are available only to pipelines that run on protected branches or tags. Users with the Maintainer or Owner role, or a custom role with the manage protected branches permission, can change or remove the rules of a project.
An attacker who holds such a role on a project that builds or deploys software removes the protection or widens it, pushes a change to the branch without a merge request, and lets the pipeline do the rest. GitLab records removal as protected_branch_removed, a change to who can push or merge as protected_branch_updated, and the force push and code owner options as their own event types with the old and new value in details.
What an attacker needs
- The Maintainer or Owner role on the project, a custom role with the manage protected branches permission, or a token with the
apiscope that carries one of them. - Log collection: audit event streaming (Ultimate) for the top-level group or the instance, to an HTTP destination, received as JSON.
Impact
Unreviewed code on a release or default branch, history rewritten by force push, and pipelines on that branch running with the project's deployment credentials. This is a direct route to shipping tampered software and to the cloud accounts the pipeline deploys to.
Detection rules
GitLab Protected Branch Removed
Detects a protected branch rule being removed from a GitLab project (audit event type protected_branch_removed). After removal, users with the Developer role can push and force push to the branch.
title: GitLab Protected Branch Removed
id: 0dab33de-deca-48c4-a1e0-c7b26b368868
status: experimental
description: >-
Detects a protected branch rule being removed from a GitLab project (audit
event type protected_branch_removed). After removal, users with the
Developer role can push and force push to the branch.
references:
- https://docs.gitlab.com/user/compliance/audit_event_types/
- https://docs.gitlab.com/user/project/repository/branches/protected/
- https://attack.mitre.org/techniques/T1195/002/
author: Forestall
date: 2026-11-11
tags:
- attack.initial-access
- attack.t1195.002
logsource:
product: gitlab
service: audit
detection:
selection:
event_type: protected_branch_removed
condition: selection
falsepositives:
- Cleanup of rules for branches that no longer exist, and migrations from project rules to group rules.
level: high
False positives
- Cleanup of rules for branches that no longer exist, and migrations from project rules to group rules.
GitLab Protected Branch Rule Weakened
Detects changes that loosen a GitLab protected branch: force push allowed, code owner approval no longer required, or a change to who is allowed to push or merge (protected_branch_updated, which is reported for every such change and needs review of details.from and details.to). The details keys were checked against the GitLab source; the object has no fixed schema.
title: GitLab Protected Branch Rule Weakened
id: 7acf59f3-c629-4999-852c-1e25d0f6288e
status: experimental
description: >-
Detects changes that loosen a GitLab protected branch: force push allowed,
code owner approval no longer required, or a change to who is allowed to
push or merge (protected_branch_updated, which is reported for every such
change and needs review of details.from and details.to). The details keys
were checked against the GitLab source; the object has no fixed schema.
references:
- https://docs.gitlab.com/user/compliance/audit_event_types/
- https://docs.gitlab.com/user/project/repository/branches/protected/
- https://attack.mitre.org/techniques/T1195/002/
author: Forestall
date: 2026-11-11
tags:
- attack.initial-access
- attack.t1195.002
logsource:
product: gitlab
service: audit
detection:
selection_force_push:
event_type: protected_branch_allow_force_push_updated
details.to: 'true'
selection_code_owner:
event_type: protected_branch_code_owner_approval_required_updated
details.to: 'false'
selection_access:
event_type: protected_branch_updated
condition: 1 of selection_*
falsepositives:
- Routine maintenance of branch rules. The access selection also fires when a rule is tightened; drop it if it is too noisy.
level: medium
False positives
- Routine maintenance of branch rules. The access selection also fires when a rule is tightened; drop it if it is too noisy.
Detection logic
Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.
Branch protection lifted, project pushed to, and protection restored
Someone who wants one unreviewed push on a release branch can remove its protection or allow force push, push, and put the rule back, so that the branch rules look unchanged afterwards. A removal followed by a new rule for the same branch in the same project within a short time, with a push to the project in between, is rarely maintenance.
- Protection is lifted:
protected_branch_removed, orprotected_branch_allow_force_push_updatedwithdetails.totrue. Keep the project (entity_path), the branch name or pattern (target_details),author_idand the time. - Within 60 minutes the rule is back:
protected_branch_createdfor the sameentity_pathandtarget_details, orprotected_branch_allow_force_push_updatedwithdetails.tofalse. - Between both, look for a push to that project: the streamed
repository_git_operationwith the sameentity_pathwhose Git action indetails.custom_messageis notgit-upload-pack, the fetch action of GitLab's examples. - Alert on the pair when such a push exists, and raise the priority when the push came from the same
author_id.
Eventsprotected_branch_removedprotected_branch_allow_force_push_updatedprotected_branch_createdrepository_git_operation
LimitsInfrastructure-as-code tools that reapply branch rules, and Maintainers who correct a mistake, produce the pair without a push. repository_git_operation is not saved to the database and reaches streaming destinations only, and its custom message does not name the branch, so the push has to be checked in the repository. GitLab's examples show only the fetch action, so read the value a push carries from one of your own events. The 60 minutes are a starting point.
Triage
- Read
entity_pathfor the project andtarget_detailsfor the branch name or pattern. - Identify the actor (
author_name,ip_address) and confirm the change through a separate channel. - For updates, compare
details.fromanddetails.toto see what was loosened. - Review pushes to the branch and pipelines that ran on it after the change, and restore the rule.
Response
Once the attack is confirmed:
- Recreate the rule with its previous values before anything else is merged, and hold deployments from the branch until the commits made since the change are reviewed.
- Revert the commits that reached the branch without a merge request. If force push was allowed, compare the branch history with a trusted clone or mirror, because earlier commits may have been rewritten.
- Treat releases, packages and images built from the branch after the change as untrusted. Withdraw them and rebuild from a reviewed commit.
- Rotate the protected CI/CD variables of the project if the branch stayed protected under a loosened rule, because pipelines on it still received them.
- Take the Maintainer or Owner role from the acting account until the change is explained, reset its credentials and revoke its tokens.
- Check the rules on every default and release branch of the project, and of the other projects the account maintains.
Mitigation
- Protect default and release branches at the top-level group, where project Maintainers cannot modify the rule.
- Set Allowed to push and merge to No one on those branches so every change needs a merge request, and require code owner approval.
- Keep the Maintainer role small on projects whose pipelines hold deployment credentials.
- Mark deployment credentials as protected variables and scope them to protected environments with approvals.
- Alert on every removal or weakening of a protected branch rule.
Frequently asked questions
Which is worse, a removed rule or a loosened one?
Both let unreviewed code reach the branch, but they differ for CI/CD. Protected variables and protected runners are available only to pipelines that run on protected branches or tags. A branch with a loosened rule is still protected, so a direct push to it runs with those variables. After a removal, users with the Developer role can push and force push to the branch.
Why does the weakened rule fire when someone tightens a branch rule?
GitLab reports every change to who is allowed to push or merge as `protected_branch_updated`, whether it loosens or tightens the rule. Compare `details.from` and `details.to` to see the direction. If the volume is too high, drop that selection and keep the force push and code owner selections, which match only the loosening value.
Do these rules show what was pushed after the protection changed?
No. They report the change to the branch rule, with the project in `entity_path` and the branch name or pattern in `target_details`. What was pushed afterwards has to be read from the repository history and from the pipelines that ran on the branch.
Who can remove branch protection in a project?
Users with the Maintainer or Owner role on the project, a custom role with the manage protected branches permission, or a token with the `api` scope that carries one of them. A rule set at the top-level group cannot be modified by project Maintainers. That is why default and release branches are best protected there.