Join our Newsletter — 33% off our NHI Course
Home› Guides› Push Protection Guide: Blocking Secrets Before They Reach…
Guide Secrets Management

Push Protection Guide: Blocking Secrets Before They Reach the Repository

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 13 min read
On this page

Once a secret is pushed to a shared repository it lives in Git history, forks and clones, so every secret scanning alert after the fact starts a rotation, not a clean-up. Push protection moves detection to the moment of the push: the Git server inspects incoming commits and rejects the push if it contains a recognised credential. GitHub, GitLab and Azure DevOps all offer it, with different defaults, bypass mechanics and blind spots, and client-side hooks such as gitleaks add a layer before the push. This guide explains how push protection works on each platform, who can bypass it and how bypasses are recorded, how to cover tokens and service accounts, what to monitor, and a rollout baseline. It is for application security engineers, platform teams and DevSecOps leads. Scanning existing history is covered in the Git Secret Scanning Guide; this page focuses on prevention at push time.

Key takeaways

  • Push protection only blocks what it can recognise with confidence. Provider patterns with fixed prefixes (AWS AKIA keys, GitHub tokens, Stripe keys) are blocked; passwords and most generic secrets are not.
  • Bypass is the control that matters. On GitHub anyone with write access can bypass by giving a reason unless delegated bypass is on; on GitLab and Azure DevOps a commit message string skips the check.
  • A bypass should create evidence. GitHub and Azure DevOps create alerts and GitHub writes an audit log event; route both to the team that rotates secrets.
  • It does not see everything. GitLab skips binary files, files over 1 MiB and very large pushes; GitHub scans after the push if the inline scan times out; existing history is out of scope.
  • Layer client and server checks. A pre-commit hook catches secrets before they enter local history; the server check is the one a developer cannot switch off.

How push protection works

Push protection runs on the Git server as part of receiving a push (GitLab documents it as a pre-receive check). It scans the new content against a set of high-confidence patterns and, on a match, rejects the push with the commit, file, line and secret type. The developer must remove the secret from every commit that contains it, not just the latest, then push again. A secret that has already been accepted, with an existing alert, is not blocked a second time on GitHub.

AspectGitHubGitLabAzure DevOps
LicenceGitHub Secret Protection for repository push protection; push protection for users is free on github.comUltimate tier (GA in 17.5)GitHub Advanced Security for Azure DevOps or GitHub Secret Protection for Azure DevOps
Default stateRepository protection off by default; push protection for users on by default for public repositoriesOff; Self-Managed and Dedicated admins must first allow itBuilt into Azure DevOps Git once the product is enabled
Entry points coveredCommand-line pushes, web UI commits, file uploads, REST API (Create a blob, Create or update file contents), GitHub MCP server (public repositories)HTTP(S) and SSH pushes, Web IDECommand-line and web pushes
What is scannedNew content in the pushDiffs of pushed commits only (since 17.11)New content in the push
BypassReason selected in the block message, or delegated bypass approvalPush option secret_push_protection.skip_all or [skip secret push protection] in a commit messageskip-secret-scanning:true in the commit message
Bypass evidenceAlert, audit log event, email to owners and watchersAudit events for skips, blocks and timeouts (19.3 and later)A secret scanning alert once the secret is pushed

Which secrets are blocked

Pattern category (GitHub)ExamplePush protectionImplication
Provider patternsaws_access_key_id, GitHub personal access tokensOn by default for mostCovers the cloud and SaaS keys attackers test first
Generic patternsRSA private keys, database connection stringsConfigurable, off by defaultEnable deliberately and measure false positives
AI-detectedPasswordsNot supportedPasswords are only found after the push
Custom patternsInternal token formatsCan be enabled per patternGive internal tokens a unique prefix so they can be blocked

GitHub notes that push protection only supports the most recent token versions it can identify with confidence, and Microsoft says the same about legacy token formats on Azure DevOps. GitLab uses only high-confidence rules, so personal access tokens with custom prefixes are not detected. The practical lesson is that token format design matters: credentials with a fixed, documented prefix can be blocked; random strings cannot. See the API Key Management Guide.

Choosing where to enforce

Control pointStrengthWeaknessBest for
IDE or editor pluginFeedback while typingPer developer, easily absentDeveloper experience
Pre-commit hookSecret never enters local historyOpt-in and skippableTeams with shared repository templates
Server push protectionCannot be skipped without a recorded bypass (GitHub) or markerHigh-confidence patterns only, size limitsOrganisation-wide enforcement
Post-push and history scanningBroadest detection, including passwords and old commitsSecret is already exposedBackstop and measurement

Self-hosted Git servers without a built-in feature can approximate push protection with a server-side pre-receive hook that runs a scanner on incoming commits; test its performance on large pushes before enforcing, because a slow hook blocks every developer.

Admin roles and bypass privileges

On GitHub, repository administrators, organisation owners, security managers and enterprise owners can enable push protection. By default every user with write access can bypass a block by choosing a reason, and the reason determines the alert state.

Bypass reason (GitHub)Alert createdWhat to do
It's used in testsClosed, resolved as "used in tests"Sample closed alerts weekly: real secrets are often labelled as test data
It's a false positiveClosed, resolved as "false positive"Review trends per pattern; tune or report the pattern
I'll fix it laterOpen alertTreat as an exposed secret: rotate, then remove from history
  • Delegated bypass: restricts who can bypass. Named roles or teams get bypass privileges and review requests from everyone else; requests expire after seven days. Organisation owners, security managers and holders of the "review and manage secret scanning bypass requests" fine-grained permission can always bypass.
  • Exemptions: GitHub can exempt actors from push protection entirely, intended for trusted automation such as migration bots. Keep the list short, because an exempt bot account that is compromised pushes anything.
  • Configuration at scale: apply push protection through an organisation or enterprise security configuration rather than repository by repository, so new repositories inherit it.
  • GitLab and Azure DevOps: skip strings are available to any pusher. Compensate with audit events (GitLab) or alerts (Azure DevOps), pipeline secret detection that rescans after the push, and alerting on the skip markers in commit messages.

Integrations, API tokens and service accounts

The secrets push protection blocks are mostly non-human identity credentials: cloud access keys, CI tokens, API keys and private keys. The platforms' own automation is also a source and a gap.

  • Bots and automation that commit: dependency bots, release tools and code generators push commits. Do not exempt them by default; exempt only accounts that legitimately write files which look like secrets, and monitor their pushes.
  • REST API writers: integrations that write files through the API receive an HTTP 409 when GitHub detects a secret. Make sure integration code handles the error instead of retrying through another path, and that any use of the "Create a push protection bypass" endpoint is reviewed.
  • AI coding agents: agents push through the same Git and API paths and can paste credentials from their context into code. GitHub's push protection covers the GitHub MCP server for public repositories; for private repositories rely on repository push protection. See the GitHub Copilot Security Guide.
  • Developer tokens: the push itself is authenticated with a personal access token, SSH key or OAuth token, which is also an NHI credential to manage. See the GitHub Personal Access Tokens Security Guide.

Client-side layer

A pre-commit hook stops the secret before it is ever in a local commit, which avoids the history rewrite that a server block requires. Gitleaks can run through the pre-commit framework (pre-commit install) or as a script in .git/hooks/. Its escape hatches are worth knowing: SKIP=gitleaks disables the hook for one commit, a gitleaks:allow comment suppresses one line, and a .gitleaksignore file suppresses findings by fingerprint. Client hooks are opt-in and can be skipped (for example with git commit --no-verify), so treat them as developer convenience and keep the server control as the enforcement point.

Logging and detection

EventWhere to find itResponse
Push blockedGitHub push protection metrics; GitLab audit event for blocked pushTrend by repository and secret type; target training where blocks cluster
Bypass with "I'll fix it later"GitHub open alert, audit log, emailRotate the credential within the secret's SLA, then clean history
Bypass request pending or approvedGitHub delegated bypass queue and audit logReviewers check the secret is not real before approving
Skip marker in commit messageGit history, GitLab skip audit events (method, account, project, branch, commits)Rescan the commits with pipeline detection; follow up with the pusher
Scan timed out or push too largeGitLab audit events; GitHub scans after the pushEnsure post-push scanning catches what the inline check skipped
Exemption list changeOrganisation or enterprise audit logAlert security; exemptions should change rarely

The threat being prevented is attackers harvesting credentials from code (ATT&CK T1552.001 Credentials In Files) found by searching public and private repositories (T1593.003 Code Repositories, T1213.003 Code Repositories). In the CISA Private-CISA GitHub leak, administrative AWS GovCloud keys and other credentials sat in a public contractor repository for about six months; keeping push protection enabled was one of the stated lessons.

Hardening baseline

ControlSettingWhy
CoveragePush protection on for every repository through an organisation or enterprise security configurationNew repositories inherit protection
BypassDelegated bypass with a small security reviewer team (GitHub)Removes self-service bypass for every writer
ExemptionsOnly named automation accounts, reviewed quarterlyExempt actors are invisible to push protection
PatternsProvider defaults plus selected generic patterns and custom patterns for internal tokensExtends coverage beyond public provider formats
Post-push scanningSecret scanning or pipeline secret detection on all repositories and historyCatches timeouts, skips, binaries and passwords
Client hooksPre-commit secret scanning in developer templatesAvoids history rewrites
Rotation pathDocumented owner and rotation runbook for each credential typeA blocked push is cheap; a bypassed one needs action

Phased rollout

  1. Measure first: run a full history scan (GitHub offers a free risk report for Team and Enterprise organisations) and fix live secrets before enabling blocks, so developers are not blocked on old leaks.
  2. Pilot: enable push protection for a few active repositories, publish a short guide on removing a secret from commits (git commit --amend --all for the latest commit, interactive rebase for earlier ones).
  3. Organisation-wide: apply through security configurations; GitLab Self-Managed admins first allow the feature, then enable per project or by API.
  4. Tighten bypass: once false positive rates are known, turn on delegated bypass and limit exemptions.
  5. Extend patterns: add generic and custom patterns one at a time, checking the metrics for bypass rates after each.

Rollback: push protection can be disabled per repository or pattern without data loss. If a pattern causes widespread false positives, remove it from push protection while keeping it in post-push scanning rather than switching the feature off.

Small and large organisations: a small team on github.com can rely on push protection for users plus repository push protection on its private repositories and a pre-commit hook. A large enterprise needs enterprise-level configuration, delegated bypass with a staffed review queue, custom patterns for internal tokens and SIEM ingestion of bypass and exemption events.

Common misconfigurations

  • Relying on push protection for users: it is on by default but only protects pushes to public repositories and creates no alerts on bypass unless repository protection is also on.
  • Every writer can bypass: without delegated bypass, "It's used in tests" closes the alert and a real key stays live.
  • Treating a bypassed secret as fixed when it is deleted: once pushed, the secret is in history and clones; it must be revoked. GitHub's guidance is to revoke real secrets and remove them from history.
  • Unrecognisable internal tokens: internal API keys without a prefix cannot be blocked, so they leak freely.
  • Ignoring skip markers: on GitLab and Azure DevOps a commit message string disables the check; nobody watches for it.
  • Exempting the CI bot broadly: a compromised automation token then pushes secrets, or secret-stealing code, unchecked.

Framework mapping

Control areaNIST SP 800-53 Rev. 5NIST CSF 2.0CIS Controls v8.1ISO/IEC 27001:2022 Annex A
No embedded static authenticatorsIA-5(7)PR.AA-0116A.8.4, A.8.28
Secure configuration of repositoriesCM-6PR.PS-014, 16A.8.9, A.8.25
Bypass and exemption governanceAC-6, AC-2PR.AA-056A.8.2
Alerting and audit of bypassesAU-2, AU-6, SI-4DE.CM-098A.8.15, A.8.16

Detection and measurement

  • Coverage: percentage of active repositories with push protection enabled.
  • Block to bypass ratio: pushes blocked versus bypassed, from push protection metrics, per organisation and per secret type.
  • Open "fix it later" alerts: count and age; each one is a live exposure.
  • Exemptions: number of exempt actors and days since last review.
  • Post-push findings: secrets found by history scanning that push protection should have blocked, which shows pattern or coverage gaps.

Practitioner checklist

  • Run a full history scan and rotate live secrets before turning on blocking.
  • Enable repository push protection through organisation or enterprise configuration.
  • Turn on delegated bypass and name a security review team.
  • Limit exemptions to named automation accounts and review them quarterly.
  • Add custom patterns for internal token formats and give new tokens a unique prefix.
  • Alert on "I'll fix it later" bypasses, skip markers and exemption changes.
  • Keep post-push secret scanning on to catch timeouts, large pushes, binaries and passwords.
  • Ship a pre-commit secret scanning hook in developer templates.
  • Publish a developer guide to removing secrets from commits and to rotation contacts.

Standards and references

Related NHI Mgmt Group resources: Git Secret Scanning Guide · Secrets Scanning Buyer's Guide · Leaked Credential Response Playbook · AWS Access Keys Security Guide · OWASP NHI Top 10 NHI2 Secret Leakage Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.