Skip to main content
Skip to content

保护存储库快速入门

管理对你的代码的访问。 自动查找和修复易受攻击的代码和依赖项。

谁可以使用此功能?

具有管理员角色的存储库所有者、组织所有者、安全管理员和用户

Introduction

This guide shows you how to configure security features for a repository.

Your security needs are unique to your repository, so you may not need to enable every feature for your repository. For more information, see GitHub安全功能.

Some features are available for repositories on all plans. Additional features are available to organizations and enterprises that use GitHub Secret Protection, GitHub Code Security, or GitHub Advanced Security. GitHub Advanced Security features are also enabled for all public repositories on GitHub. For more information, see 关于GitHub高级安全性.

Managing access to your repository

The first step to securing a repository is to establish who can see and modify your code. For more information, see 管理存储库的设置和功能.

From the main page of your repository, click Settings, then scroll down to the "Danger Zone."

Managing the dependency graph

Repository administrators can enable or disable the dependency graph for repositories. The dependency graph interprets manifest and lock files in a repository to identify dependencies.

  1. From the main page of your repository, click Settings.
  2. Click Advanced Security.
  3. Next to Dependency graph, click Enable or Disable.

For more information, see 启用依赖项关系图.

Managing Dependabot alerts

Dependabot alerts are generated when GitHub identifies a dependency in the dependency graph with a vulnerability. You can enable Dependabot alerts for any repository.

Additionally, you can use Dependabot auto-triage rules to manage your alerts at scale, so you can auto-dismiss or snooze alerts, and specify which alerts you want Dependabot to open pull requests for. For information about the different types of auto-triage rules, and whether your repositories are eligible, see Dependabot 自动分类规则.

For an overview of the different features offered by Dependabot and instructions on how to get started, see Dependabot 快速入门指南.

  1. Click your profile picture, then click Settings.
  2. Click Advanced Security.
  3. Click Enable next to Dependabot alerts.

For more information, see Dependabot 警报 and 管理安全和分析功能.

Managing dependency review

Dependency review lets you visualize dependency changes in pull requests before they are merged into your repositories. For more information, see 依赖项审查.

Dependency review is a GitHub Code Security feature. Dependency review is enabled for all repositories with the dependency graph enabled. Organizations that use GitHub Team or GitHub Enterprise Cloud with GitHub Code Security can additionally enable dependency review for private and internal repositories.

To enable dependency review for a repository, ensure that the dependency graph is enabled.

  1. From the main page of your repository, click Settings.
  2. Click Advanced Security.
  3. To the right of Code Security, click Enable.
  4. Under Code Security, check that dependency graph is enabled for the repository.

Managing Dependabot security updates

For any repository that uses Dependabot alerts, you can enable Dependabot security updates to raise pull requests with security updates when vulnerabilities are detected.

  1. From the main page of your repository, click Settings.
  2. Click Advanced Security.
  3. Next to Dependabot security updates, click Enable.

For more information, see Dependabot 安全更新 and 配置 Dependabot 安全更新.

Managing Dependabot version updates

You can enable Dependabot to automatically raise pull requests to keep your dependencies up-to-date. For more information, see Dependabot 版本更新.

  1. From the main page of your repository, click Settings.
  2. Click Advanced Security.
  3. Next to Dependabot version updates, click Enable to create a basic dependabot.yml configuration file.
  4. Specify the dependencies to update and any associated configuration options, then commit the file to the repository. For more information, see 配置 Dependabot 版本更新.

Configuring Code Security

注意

Code Security features are available for all public repositories, and for private repositories owned by organizations that are part of a team or an enterprise that uses GitHub Code Security or GitHub Advanced Security.

GitHub Code Security includes code scanning, CodeQL CLI and Copilot Autofix, as well as other features that find and fix vulnerabilities in your codebase.

You can configure code scanning to automatically identify vulnerabilities and errors in the code stored in your repository by using a CodeQL analysis workflow or third-party tool. Depending on the programming languages in your repository, you can configure code scanning with CodeQL using default setup, in which GitHub automatically determines the languages to scan, query suites to run, and events that will trigger a new scan. For more information, see 配置代码扫描的默认设置.

  1. From the main page of your repository, click Settings.
  2. In the "Security" section of the sidebar, click Advanced Security.
  3. If "Code Security" or "GitHub Advanced Security" is not already enabled, click Enable.
  4. To the right of "CodeQL analysis", select Set up , then click Default.
  5. In the pop-up window that appears, review the default configuration settings for your repository, then click Enable CodeQL.
  6. Choose whether you want to enable additional features, such as Copilot Autofix.

As an alternative to default setup, you can use advanced setup, which generates a workflow file you can edit to customize your code scanning with CodeQL. For more information, see 配置代码扫描的高级设置.

You can separately enable AI Scan to extend code scanning coverage to supported languages and frameworks that CodeQL does not cover. AI Scan requires code scanning, but does not require CodeQL default setup. See 用于拉取请求的 AI 扫描.

Configuring Secret Protection

注意

Secret Protection features are available for all public repositories, and for private repositories owned by organizations that are part of a team or an enterprise that uses GitHub Secret Protection or GitHub Advanced Security.

GitHub Secret Protection includes secret scanning and push protection, as well as other features that help you detect and prevent secret leaks in your repository.

  1. From the main page of your repository, click Settings.
  2. Click Advanced Security.
  3. If "Secret Protection" or "GitHub Advanced Security" is not already enabled, click Enable.
  4. If the option "Secret scanning" is shown, click Enable.
  5. Choose whether you want to enable additional features, such as scanning for generic patterns and push protection.

Setting a security policy

If you are a repository maintainer, it's good practice to specify a security policy for your repository by creating a file named SECURITY.md in the repository. This file instructs users about how to best contact you and collaborate with you when they want to report security vulnerabilities in your repository. You can view the security policy of a repository from the repository’s Security and quality tab.

  1. From the main page of your repository, click Security and quality.
  2. In the left sidebar, under "Reporting", click Security policy.
  3. Click Start setup.
  4. Add information about supported versions of your project and how to report vulnerabilities.

For more information, see 将安全策略添加到存储库.

Next steps

You can view and manage alerts from security features to address dependencies and vulnerabilities in your code. For more information, see 查看和更新 Dependabot 警报, 管理依赖项更新的所有拉取请求, 访问存储库的代码扫描警报, and 管理机密扫描警报.

You can also use GitHub's tools to audit responses to security alerts. For more information, see 审核安全警报.

If you have a security vulnerability in a public repository, you can create a security advisory to privately discuss and fix the vulnerability. For more information, see 存储库安全公告 and 创建存储库安全公告.

If you use GitHub Actions, you can use GitHub's security features to increase the security of your workflows. For more information, see 安全使用指南.