Skip to main content

About push protection

Secure your secrets by stopping them from ever reaching your repository with push protection.

What is push protection?

Push protection is a secret scanning feature designed to prevent sensitive information, such as secrets or tokens, from ever being pushed to your repository. Unlike secret scanning, which detects secrets after they have been committed, push protection proactively scans your code for secrets during the push process, then blocks the push if any are detected.

How push protection works

Push protection blocks secrets detected in:

  • Pushes from the command line
  • Commits made in the GitHub UI
  • File uploads to a repository on GitHub
  • Requests to the REST API
  • Interactions with the GitHub MCP server (public repositories only)

When push protection detects a potential secret during a push attempt, it will block the push and provide a detailed message explaining the reason for the block. You will need to review the code in question, remove any sensitive information, and reattempt the push.

Types of push protection

There are two types of push protection:

Push protection for repositories

You can enable push protection for repositories at the repository, organization, or enterprise level. This form of push protection:

  • Requires GitHub Secret Protection to be enabled
  • Is disabled by default, and can be enabled by a repository administrator, organization owner, security manager, or enterprise owner
  • Blocks pushes containing secrets from reaching specific protected repositories
  • Generates alerts for push protection bypasses in the Security tab of the repository, organization, and enterprise

Push protection for users

Push protection for users is only available on GitHub.com, and is specific to your GitHub account. This form of push protection:

  • Is enabled by default
  • Stops you from pushing secrets to public repositories on GitHub
  • Does not generate alerts when you bypass push protection unless push protection is also enabled at the repository level

Push protection bypass and alerts

For push protection for repositories, by default, anyone with write access to the repository can bypass push protection by specifying a bypass reason. When a contributor bypasses a push protection block, GitHub:

  • Creates an alert in the Security tab of the repository, organization, and enterprise
  • Adds the bypass event to the audit log
  • Sends an email alert to personal account, organization, and enterprise owners, security managers, and repository administrators who are watching the repository, with a link to the secret and the reason it was allowed

This table shows the behavior of alerts for each bypass reason a user can specify.

Bypass reasonAlert behavior
It's used in testsGitHub creates a closed alert, resolved as "used in tests"
It's a false positiveGitHub creates a closed alert, resolved as "false positive"
I'll fix it laterGitHub creates an open alert

If you want greater control over which contributors can bypass push protection and which pushes containing secrets should be allowed, you can configure a designated group of reviewers to oversee and manage bypass requests.

Benefits of push protection

  • Preventative security: Push protection acts as a frontline defense mechanism by scanning code for secrets at the time of the push. This preventative approach helps to catch potential issues before they are merged into a repository.
  • Immediate feedback: Developers receive instant feedback if a potential secret is detected during a push attempt. This immediate notification allows for quick remediation, reducing the likelihood of sensitive information being exposed.
  • Reduced risk of data leaks: By blocking commits that contain sensitive information, push protection significantly reduces the risk of accidental data leaks. This helps in safeguarding against unauthorized access to your infrastructure, services, and data.
  • Efficient secret management: Instead of retrospectively dealing with exposed secrets, developers can address issues at the source. This makes secret management more efficient and less time-consuming.
  • Bypass functionality for flexibility: For cases where false positives occur or when certain patterns are necessary, you can bypass push protection for users, and designated users can use the delegated bypass feature to bypass push protection for repositories. This provides flexibility without compromising overall security.
  • Ability to detect custom patterns (for repositories in organizations): Organizations can define custom patterns for detecting secrets unique to their environment. This customization ensures that push protection can effectively identify and block even non-standard secrets.

Customization

After you enable push protection for repositories, you can customize it by:

  • Defining custom patterns to block pushes containing unique secret patterns
  • Designating contributors who can bypass push protection and approve bypass requests for other contributors

Next steps

To enable push protection:

For a list of secrets and service providers supported by push protection, see Supported secret scanning patterns.