Skip to main content

Protecting pushes with secret scanning

You can use secret scanning to prevent supported secrets from being pushed into your organization or repository by enabling push protection.

Secret scanning for advanced security is available for organization-owned repositories in GitHub Enterprise Cloud if your enterprise has a license for GitHub Advanced Security. For more information, see "GitHub's products."

Note: Secret scanning as a protection push is currently in beta and subject to change. To request access to the beta release, contact your account management team.

About push protection for secrets

Up to now, secret scanning for advanced security checks for secrets after a push and alerts users to exposed secrets. When you enable push protection, secret scanning also checks pushes for high-confidence secrets (those identified with a low false positive rate). Secret scanning lists any secrets it detects so the author can review the secrets and remove them or, if needed, allow those secrets to be pushed.

Secret scanning as a push protection currently scans repositories for secrets issued by the following service providers.

ProviderSupported secretSecret type
Adafruit IOAdafruit IO Keyadafruit_io_key
Alibaba CloudAlibaba Cloud Access Key IDalibaba_cloud_access_key_id
Alibaba CloudAlibaba Cloud Access Key Secretalibaba_cloud_access_key_secret
AmazonAmazon OAuth Client IDamazon_oauth_client_id
AmazonAmazon OAuth Client Secretamazon_oauth_client_secret
Amazon Web Services (AWS)Amazon AWS Access Key IDaws_access_key_id
Amazon Web Services (AWS)Amazon AWS Secret Access Keyaws_secret_access_key
Amazon Web Services (AWS)Amazon AWS Session Tokenaws_session_token
Amazon Web Services (AWS)Amazon AWS Temporary Access Key IDaws_temporary_access_key_id
AsanaAsana Personal Access Tokenasana_personal_access_token
AtlassianBitbucket Server Personal Access Tokenbitbucket_server_personal_access_token
AzureAzure Active Directory Application Secretazure_active_directory_application_secret
AzureAzure Cache for Redis Access Keyazure_cache_for_redis_access_key
AzureAzure DevOps Personal Access Tokenazure_devops_personal_access_token
Checkout.comCheckout.com Production Secret Keycheckout_production_secret_key
ClojarsClojars Deploy Tokenclojars_deploy_token
DatabricksDatabricks Access Tokendatabricks_access_token
DigitalOceanDigitalOcean Personal Access Tokendigitalocean_personal_access_token
DigitalOceanDigitalOcean OAuth Tokendigitalocean_oauth_token
DigitalOceanDigitalOcean Refresh Tokendigitalocean_refresh_token
DigitalOceanDigitalOcean System Tokendigitalocean_system_token
DiscordDiscord Bot Tokendiscord_bot_token
DopplerDoppler Personal Tokendoppler_personal_token
DopplerDoppler Service Tokendoppler_service_token
DopplerDoppler CLI Tokendoppler_cli_token
DopplerDoppler SCIM Tokendoppler_scim_token
DopplerDoppler Audit Tokendoppler_audit_token
DropboxDropbox Short Lived Access Tokendropbox_short_lived_access_token
DuffelDuffel Live Access Tokenduffel_live_access_token
EasyPostEasyPost Production API Keyeasypost_production_api_key
FlutterwaveFlutterwave Live API Secret Keyflutterwave_live_api_secret_key
FullstoryFullStory API Keyfullstory_api_key
GitHubGitHub Personal Access Tokengithub_personal_access_token
GitHubGitHub OAuth Access Tokengithub_oauth_access_token
GitHubGitHub Refresh Tokengithub_refresh_token
GitHubGitHub App Installation Access Tokengithub_app_installation_access_token
GitHubGitHub SSH Private Keygithub_ssh_private_key
GoogleGoogle Cloud Storage Access Key Secretgoogle_cloud_storage_access_key_secret
GoogleGoogle Cloud Storage Service Account Access Key IDgoogle_cloud_storage_service_account_access_key_id
GoogleGoogle Cloud Storage User Access Key IDgoogle_cloud_storage_user_access_key_id
GrafanaGrafana API Keygrafana_api_key
HubspotHubspot API Keyhubspot_api_key
IntercomIntercom Access Tokenintercom_access_token
JFrogJFrog Platform Access Tokenjfrog_platform_access_token
JFrogJFrog Platform API Keyjfrog_platform_api_key
IonicIonic Personal Access Tokenionic_personal_access_token
IonicIonic Refresh Tokenionic_refresh_token
LinearLinear API Keylinear_api_key
LinearLinear OAuth Access Tokenlinear_oauth_access_token
MidtransMidtrans Production Server Keymidtrans_production_server_key
New RelicNew Relic Personal API Keynew_relic_personal_api_key
New RelicNew Relic REST API Keynew_relic_rest_api_key
New RelicNew Relic Insights Query Keynew_relic_insights_query_key
npmnpm Access Tokennpm_access_token
NuGetNuGet API Keynuget_api_key
OnfidoOnfido Live API Tokenonfido_live_api_token
OpenAIOpenAI API Keyopenai_api_key
PlanetScalePlanetScale Database Passwordplanetscale_database_password
PlanetScalePlanetScale OAuth Tokenplanetscale_oauth_token
PlanetScalePlanetScale Service Tokenplanetscale_service_token
PostmanPostman API Keypostman_api_key
ProctorioProctorio Secret Keyproctorio_secret_key
redirect.pizzaredirect.pizza API Tokenredirect_pizza_api_token
SamsaraSamsara API Tokensamsara_api_token
SamsaraSamsara OAuth Access Tokensamsara_oauth_access_token
SendGridSendGrid API Keysendgrid_api_key
SendinblueSendinblue API Keysendinblue_api_key
SendinblueSendinblue SMTP Keysendinblue_smtp_key
ShippoShippo Live API Tokenshippo_live_api_token
ShopifyShopify App Shared Secretshopify_app_shared_secret
ShopifyShopify Access Tokenshopify_access_token
SlackSlack API Tokenslack_api_token
StripeStripe Live API Secret Keystripe_api_key
Tencent CloudTencent Cloud Secret IDtencent_cloud_secret_id
TypeformTypeform Personal Access Tokentypeform_personal_access_token
WorkOSWorkOS Production API Keyworkos_production_api_key

Enabling secret scanning as a push protection

For you to use secret scanning as a push protection, the organization or repository needs to have both GitHub Advanced Security and secret scanning enabled. For more information, see "Managing security and analysis settings for your organization," "Managing security and analysis settings for your repository," and "About GitHub Advanced Security."

Organization owners, security managers, and repository administrators can enable push protection for secret scanning via the UI and API. For more information, see "Repositories" and expand the "Properties of the security_and_analysis object" section in the REST API documentation.

Enabling secret scanning as a push protection for an organization

  1. On GitHub.com, navigate to the main page of the organization.

  2. Under your organization name, click Settings.

    Organization settings button

  1. In the "Security" section of the sidebar, click Code security and analysis.

  2. Under "Code security and analysis", find "GitHub Advanced Security."

  3. Under "Secret scanning", under "Push protection", click Enable all. Screenshot showing how to enable push protection for secret scanning for an organization

  4. Optionally, click "Automatically enable for private repositories added to secret scanning."

Enabling secret scanning as a push protection for a repository

  1. On GitHub.com, navigate to the main page of the repository.

  2. Under your repository name, click Settings. Repository settings button

  3. In the "Security" section of the sidebar, click Code security and analysis.

  4. Under "Code security and analysis", find "GitHub Advanced Security."

  5. Under "Secret scanning", under "Push protection", click Enable. Screenshot showing how to enable push protection for secret scanning for a repository

Using secret scanning as a push protection from the command line

When you attempt to push a supported secret to a repository or organization with secret scanning as a push protection enabled, GitHub will block the push. You can remove the secret from your commit or follow a provided URL to allow the push.

Up to five detected secrets will be displayed at a time on the command line. If a particular secret has already been detected in the repository and an alert already exists, GitHub will not block that secret.

Screenshot showing that a push is blocked when a user attempts to push a secret to a repository

If you need to remove the secret from your latest commit (that is, HEAD) on the branch being pushed and any earlier commits that contain the secret, you can remove the secret from HEAD, then squash the commits between when the commit was introduced and the first version of HEAD for which the secret has been removed.

Notes:

  • If your git configuration supports pushes to multiple branches, and not only to the default branch, your push may be blocked due to additional and unintended refs being pushed. For more information, see the push.default options in the Git Docs.
  • If secret scanning upon a push times out, GitHub will still run a scan after the push.

Allowing a blocked secret to be pushed

If GitHub blocks a secret that you believe is safe to push, you can allow the secret and specify the reason why it should be allowed.

If you confirm a secret is real and that you intend to fix it later, you should aim to remediate the secret as soon as possible. For example, you might revoke the secret and remove the secret from the repository's commit history. For more information, see "Removing sensitive data from a repository."

When you allow a secret to be pushed, an alert is created in the "Security" tab. GitHub closes the alert and doesn't send a notification if you specify that the secret is a false positive or used only in tests. If you specify that the secret is real and that you will fix it later, GitHub keeps the security alert open and sends notifications to the author of the commit, as well as to repository administrators. For more information, see "Managing alerts from secret scanning."

  1. Visit the URL returned by GitHub when your push was blocked. Screenshot showing form with options for unblocking the push of a secret
  2. Choose the option that best describes why you should be able to push the secret.
    • If the secret is only used in tests and poses no threat, click It's used in tests.
    • If the detected string is not a secret, click It's a false positive.
    • If the secret is real but you intend to fix it later, click I'll fix it later.
  3. Click Allow me to push this secret.
  4. Reattempt the push on the command line within three hours. If you have not pushed within three hours, you will need to repeat this process.

Using secret scanning as a push protection from the web UI

When you use the web UI to attempt to commit a supported secret to a repository or organization with secret scanning as a push protection enabled, GitHub will block the commit. You will see a banner at the top of the page with information about the secret's location, and the secret will also be underlined in the file so you can easily find it.

Screenshot showing commit in web ui blocked because of secret scanning push protection

GitHub will only display one detected secret at a time in the web UI. If a particular secret has already been detected in the repository and an alert already exists, GitHub will not block that secret.

You can remove the secret from the file using the web UI. Once you remove the secret, the banner at the top of the page will change and tell you that you can now commit your changes.

Screenshot showing commit in web ui allowed after secret fixed

Bypassing push protection for a secret

If GitHub blocks a secret that you believe is safe to push, you can allow the secret and specify the reason why it should be allowed. If you confirm a secret is real and that you intend to fix it later, you should aim to remediate the secret as soon as possible.

When you allow a secret to be pushed, an alert is created in the "Security" tab. GitHub closes the alert and doesn't send a notification if you specify that the secret is a false positive or used only in tests. If you specify that the secret is real and that you will fix it later, GitHub keeps the security alert open and sends notifications to the author of the commit, as well as to repository administrators. For more information, see "Managing alerts from secret scanning."

If you confirm a secret is real and that you intend to fix it later, you should aim to remediate the secret as soon as possible.

  1. In the banner that appeared at the top of the page when GitHub blocked your commit, click Bypass protection.

  2. Choose the option that best describes why you should be able to push the secret.

    • If the secret is only used in tests and poses no threat, click It's used in tests.
    • If the detected string is not a secret, click It's a false positive.
    • If the secret is real but you intend to fix it later, click I'll fix it later.

    Screenshot showing form with options for unblocking the push of a secret

  3. Click Allow secret.