Skip to main content

Managing code scanning alerts for your repository

From the security view, you can view, fix, or dismiss 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.

代码扫描 is available for all public repositories on GitHub.com. To use 代码扫描 in a private repository owned by an organization, you must have a license for GitHub Advanced Security. 更多信息请参阅“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, the code scanning alerts page is filtered to show alerts for the default branch of the repository only.

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

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

  3. 在左侧边栏中,单击 Code scanning alerts(代码扫描警报)"Code scanning alerts(代码扫描警报)" 选项卡

  4. Optionally, use the free text search box or the drop-down menus to filter alerts. For example, you can filter by the tool that was used to identify alerts. Filter by tool

  5. 在 "代码扫描" 下,单击要探索的警报。 Summary of alerts

     警报页面上的状态和详细信息仅反映存储库的默认分支上的警报状态,即使警报存在于其他分支中也是如此。 可以在警报页面右侧 **Affected branches(受影响的分支)**部分中查看非默认分支上警报状态。 如果默认分支中不存在警报,则警报的状态将显示为“在拉取请求中”或“在分支中”,并将显示为灰色。
     ![The "Affected branches" section in an alert](/assets/images/help/repository/code-scanning-affected-branches.png)
    
  6. 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

  7. 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

For more information, see "About 代码扫描 alerts."

Note: For 代码扫描 analysis with CodeQL, you can see information about the latest run in a header at the top of the list of 代码扫描 alerts for the repository.

For example, you can see when the last scan ran, the number of lines of code analyzed compared to the total number of lines of code in your repository, and the total number of alerts that were generated. UI banner

Filtering 代码扫描 alerts

You can filter the alerts shown in the 代码扫描 alerts view. This is useful if there are many alerts as you can focus on a particular type of alert. There are some predefined filters and a range of keywords that you can use to refine the list of alerts displayed.

  • To use a predefined filter, click Filters, or a filter shown in the header of the list of alerts, and choose a filter from the drop-down list. Predefined filters
  • To use a keyword, either type directly in the filters text box, or:
    1. Click in the filters text box to show a list of all available filter keywords.
    2. Click the keyword you want to use and then choose a value from the drop-down list. Keyword filters list

The benefit of using keyword filters is that only values with results are shown in the drop-down lists. This makes it easy to avoid setting filters that find no results.

If you enter multiple filters, the view will show alerts matching all these filters. For example, is:closed severity:high branch:main will only display closed high-severity alerts that are present on the main branch. The exception is filters relating to refs (ref, branch and pr): is:open branch:main branch:next will show you open alerts from both the main branch and the next branch.

请注意,如果已筛选非默认分支上的警报,但默认分支上存在相同的警报,则任何给定警报的警报页面仍将仅反映默认分支上的警报状态,即使该状态与非默认分支上的状态冲突也是如此。 例如,如果警报已在默认分支上修复,则出现在 branch-x 警报摘要的“打开”列表中的警报可能会在警报页面上显示“已修复”状态。 可以在警报页面右侧 Affected branches(受影响的分支)部分中查看已筛选分支的警报状态。

You can prefix the tag filter with - to exclude results with that tag. For example, -tag:style only shows alerts that do not have the style tag and -tag:experimental will omit all experimental alerts. For more information, see "About 代码扫描 alerts."

Restricting results to application code only

You can use the "Only alerts in application code" filter or autofilter:true keyword and value to restrict results to alerts in application code. See "About labels for alerts not in application code" above for more information about the types of code that are not application code.

Searching 代码扫描 alerts

You can search the list of alerts. This is useful if there is a large number of alerts in your repository, or if you don't know the exact name for an alert for example. GitHub Enterprise Cloud performs the free text search across:

  • The name of the alert

  • The alert details (this also includes the information hidden from view by default in the Show more collapsible section)

    The alert information used in searches

Supported searchSyntax exampleResults
Single word searchinjectionReturns all the alerts containing the word injection
Multiple word searchsql injectionReturns all the alerts containing sql or injection
Exact match search
(use double quotes)
"sql injection"Returns all the alerts containing the exact phrase sql injection
OR searchsql OR injectionReturns all the alerts containing sql or injection
AND searchsql AND injectionReturns all the alerts containing both words sql and injection

Tips:

  • The multiple word search is equivalent to an OR search.
  • The AND search will return results where the search terms are found anywhere, in any order in the alert name or details.
  1. 在 GitHub.com 上,导航到仓库的主页面。
  2. 在仓库名称下,单击 Security(安全)Security 选项卡
  3. 在左侧边栏中,单击 Code scanning alerts(代码扫描警报)"Code scanning alerts(代码扫描警报)" 选项卡
  4. To the right of the Filters drop-down menus, type the keywords to search for in the free text search box. The free text search box
  5. Press return. The alert listing will contain the open 代码扫描 alerts matching your search criteria.

Tracking 代码扫描 alerts in issues

注意: 议题中 代码扫描 警报的跟踪处于测试阶段,可能会发生更改。

此功能支持使用 GitHub Actions 在本地运行分析,或使用现有 CI/CD 基础结构以及第三方 代码扫描 工具在外部运行分析,但使用第三方跟踪工具。

代码扫描 警报与 GitHub Issues 中的任务列表集成,可让您轻松地在所有开发工作中确定警报的优先级并进行跟踪。 有关议题的更多信息,请参阅“关于议题”。

要跟踪议题中的代码扫描警报,请将警报的 URL 添加为议题中的任务列表项。 有关任务列表的更多信息,请参阅“关于任务列表”。

有关创建议题以跟踪 代码扫描 警报的详细信息,请参阅“使用任务列表跟踪议题中的 代码扫描 警报”。

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 dismissed.

You can use the free text search or the filters to display a subset of alerts and then in turn mark all matching alerts as closed.

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

Filtering alerts by branch

请注意,如果已筛选非默认分支上的警报,但默认分支上存在相同的警报,则任何给定警报的警报页面仍将仅反映默认分支上的警报状态,即使该状态与非默认分支上的状态冲突也是如此。 例如,如果警报已在默认分支上修复,则出现在 branch-x 警报摘要的“打开”列表中的警报可能会在警报页面上显示“已修复”状态。 可以在警报页面右侧 Affected branches(受影响的分支)部分中查看已筛选分支的警报状态。

Note: If you run code scanning using multiple configurations, then sometimes an alert will have multiple analysis origins. Unless you run all configurations regularly, you may see alerts that are fixed in one analysis origin but not in another. For more information, see "About analysis origins."

Dismissing alerts

There are two ways of closing an alert. You can fix the problem in the code, or you can dismiss the alert.

Dismissing an alert is a way of closing an alert that you don't think needs to be fixed. 例如,仅用于测试的代码中有错误,或者修复错误的工作超过改进代码的潜在益处。 You can dismiss alerts from 代码扫描 annotations in code, or from the summary list within the Security tab.

When you dismiss an alert:

  • It's dismissed in all branches.
  • The alert is removed from the number of current alerts for your project.
  • The alert is moved to the "Closed" list in the summary of alerts, from where you can reopen it, if required.
  • The reason why you closed the alert is recorded.
  • Optionally, you can comment on a dismissal to record the context of an alert dismissal.
  • Next time 代码扫描 runs, the same code won't generate an alert.

To dismiss alerts:

  1. 在 GitHub.com 上,导航到仓库的主页面。
  2. 在仓库名称下,单击 Security(安全)Security 选项卡
  3. 在左侧边栏中,单击 Code scanning alerts(代码扫描警报)"Code scanning alerts(代码扫描警报)" 选项卡
  4. If you want to dismiss an alert, it's important to explore the alert first, so that you can choose the correct dismissal reason. Click the alert you'd like to explore.

Open an alert from the summary list

  1. Review the alert, then click Dismiss alert and choose, or type, a reason for closing the alert. Screenshot of code scanning alert with dropdown to choose dismissal reason emphasized

    从下拉菜单中选择合适的原因很重要,因为这可能会影响到是否继续将查询纳入未来的分析。 (可选)您可以对取消进行注释,以记录警报解除的上下文。 取消注释将添加到警报时间线中,并可在审核和报告期间用作理由。 您可以使用代码扫描 REST API 检索或设置注释。 注释包含在 alerts/{alert_number} 端点的 dismissed_comment 中。 更多信息请参阅“代码扫描”。

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

Dismissing multiple alerts at once

If a project has multiple alerts that you want to dismiss for the same reason, you can bulk dismiss them from the summary of alerts. Typically, you'll want to filter the list and then dismiss all of the matching alerts. For example, you might want to dismiss all of the current alerts in the project that have been tagged for a particular Common Weakness Enumeration (CWE) vulnerability.

Further reading