Skip to main content

此版本的 GitHub Enterprise Server 已于以下日期停止服务 2026-03-17. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

关于机密扫描

通过在利用机密之前自动检测公开的凭据,防止机密的欺诈性使用。

When credentials like API keys and passwords are committed to repositories, they become targets for unauthorized access. Secret scanning automatically detects these exposed secrets so you can secure them before they're exploited.

How secret scanning protects your code

Secret scanning scans your entire Git history on all branches of your repository for API keys, passwords, tokens, and other known secret types. GitHub also periodically rescans repositories when new secret types are added.

GitHub also automatically scans:

  • Descriptions and comments in issues
  • Titles, descriptions, and comments, in open and closed historical issues
  • Titles, descriptions, and comments in pull requests
  • Titles, descriptions, and comments in GitHub Discussions
  • Secret gists

注意

The scanning of content in pull requests and GitHub Discussions is currently in beta and subject to change.

Secret scanning alerts and remediation

When secret scanning finds a potential secret, GitHub generates an alert on your repository's Security tab with details about the exposed credential.

Review the alert and rotate the affected credential immediately to ensure it can no longer be used. While you can also remove secrets from your Git history, this is time-intensive and often unnecessary if you've already revoked the credential.

Customizability

Beyond the default detection of partner and provider secrets, you can expand and customize secret scanning to fit your needs.

  • Non-provider patterns. Expand detection to secrets that aren't tied to a specific service provider, such as private keys, connection strings, and generic API keys.
  • Custom patterns. Define your own regular expressions to detect organization-specific secrets that aren't covered by default patterns.
  • Validity checks. Prioritize remediation by checking whether detected secrets are still active.

How can I access this feature?

Secret scanning is available for the following repository types:

  • Public repositories: Secret scanning runs automatically for free.
  • Organization-owned private and internal repositories: Available with GitHub Advanced Security enabled on GitHub Team or GitHub Enterprise Cloud.
  • User-owned repositories: Available on GitHub Enterprise Cloud with Enterprise Managed Users. Available on GitHub Enterprise Server when the enterprise has GitHub Advanced Security enabled.

Next steps

Further reading