我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

Managing code scanning alerts for your repository

From the security view, you can view, fix, or close alerts for potential vulnerabilities or errors in your project's code.

If you have write permission to a repository you can manage 代码扫描 alerts for that repository.

代码扫描 可用于您有 Advanced Security 许可的组织拥有的私有仓库。

本文内容

注意:代码扫描 目前处于测试阶段,可能会更改。 有关参加公测的更多信息,请在此注册

关于 代码扫描 中的警报

You can set up 代码扫描 to check the code in a repository using the default CodeQL analysis, a third-party analysis, or multiple types of analysis. When the analysis is complete, the resulting alerts are displayed alongside each other in the security view of the repository. Results from third-party tools or from custom queries may not include all of the properties that you see for alerts detected by GitHub's default CodeQL analysis. 默认 代码扫描 工作流程使用 on.push 事件触发代码扫描 - 每次推送到任何包含工作流程文件的分支时触发。

By default, 代码扫描 analyzes your code periodically on the default branch and during pull requests. For information about managing alerts on a pull request, see "Triaging 代码扫描 alerts in pull requests."

About alerts details

每个警报都会高亮显示代码的问题以及识别该问题的工具名称。 您可以看到触发警报的代码行以及警报的属性,例如问题的严重程度和性质。 警报还会告知该问题第一次被引入的时间。 对于由 CodeQL 分析确定的警报,您还会看到如何解决问题的信息。

来自 代码扫描 的警报示例

如果使用 CodeQL 启用 代码扫描,也可以检测代码中的数据流问题。 数据流分析将查找代码中的潜在安全问题,例如:不安全地使用数据、将危险参数传递给函数以及泄漏敏感信息。

当 代码扫描 报告数据流警报时,GitHub 将显示数据在代码中如何移动。 代码扫描 可用于识别泄露敏感信息的代码区域,以及可能成为恶意用户攻击切入点的代码区域。

Viewing the alerts for a repository

Anyone with read permission for a repository can see 代码扫描 annotations on pull requests. For more information, see "Triaging 代码扫描 alerts in pull requests."

You need write permission to view a summary of all the alerts for a repository on the Security tab. By default, alerts are shown for the default branch.

  1. 在 GitHub Enterprise Server 上,导航到仓库的主页面。
  2. 在仓库名称下,单击 Security(安全)
    Security 选项卡
  3. 在左侧边栏中,单击 Code scanning alerts(代码扫描警报)。 (可选)选择您使用的代码扫描工具。
    "Code scanning alerts(代码扫描警报)" 选项卡
  4. Under "代码扫描," click the alert you'd like to explore.
    Summary of alerts
  5. Optionally, if the alert highlights a problem with data flow, click Show paths to display the path from the data source to the sink where it's used.
    The "Show paths" link on an alert
  6. Alerts from CodeQL analysis include a description of the problem. Click Show more for guidance on how to fix your code.
    Details for an alert

Fixing an alert

Anyone with write permission for a repository can fix an alert by committing a correction to the code. If the repository has 代码扫描 scheduled to run on pull requests, it's best to raise a pull request with your correction. This will trigger 代码扫描 analysis of the changes and test that your fix doesn't introduce any new problems. For more information, see "Configuring 代码扫描" and "Triaging 代码扫描 alerts in pull requests."

If you have write permission for a repository, you can view fixed alerts by viewing the summary of alerts and clicking Closed. For more information, see "Viewing the alerts for a repository." The "Closed" list shows fixed alerts and alerts that users have closed.

Alerts may be fixed in one branch but not in another. You can use the "Branch" drop-down menu, on the summary of alerts, to check whether an alert is fixed in a particular branch.

Filtering alerts by branch

关闭警报

Closing an alert is a way to resolve an alert that you don't think needs to be fixed. 例如,仅用于测试的代码中有错误,或者修复错误的工作超过改进代码的潜在益处。

  1. 在 GitHub Enterprise Server 上,导航到仓库的主页面。

  2. 在仓库名称下,单击 Security(安全)

    Security 选项卡

  3. 在左侧边栏中,单击 Code scanning alerts(代码扫描警报)。 (可选)选择您使用的代码扫描工具。

    "Code scanning alerts(代码扫描警报)" 选项卡

  4. 在“Code Scanning(代码扫描)”下,单击要探索的警报。

    来自 代码扫描 的警报列表

  5. Select the Close drop-down menu and click a reason for closing the alert.

    Choosing reason for closing the alert via the Close drop-down

如果将 CodeQL 警报作为误报予以关闭,例如,因为代码使用不受支持的净化库,则考虑参与 CodeQL 仓库并改进分析。 有关 CodeQL 的更多信息,请参阅“参与 CodeQL”。

延伸阅读

此文档对您有帮助吗?

Privacy policy

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。