New-GitHubCodeScanningUploadSarif

SYNOPSIS

Upload an analysis as SARIF data

SYNTAX

Default (Default)

New-GitHubCodeScanningUploadSarif [-Owner] <string> [-Repo] <string> -CommitSha <string>
 -Ref <string> -Sarif <string> [-CheckoutUri <string>] [-StartedAt <string>] [-ToolName <string>]
 [-Validate] [-Accept <string>] [-WhatIf] [-Confirm]

Body

New-GitHubCodeScanningUploadSarif [-Owner] <string> [-Repo] <string> -Body <Object>
 [-CommitSha <string>] [-Ref <string>] [-Sarif <string>] [-CheckoutUri <string>]
 [-StartedAt <string>] [-ToolName <string>] [-Validate] [-Accept <string>] [-WhatIf] [-Confirm]

ALIASES

This cmdlet has the following aliases,

  • Get-GHNewCodeScanningUploadSarif

DESCRIPTION

The New-GitHubCodeScanningUploadSarif cmdlet invokes the POST method of the /repos/{owner}/{repo}/code-scanning/sarifs endpoint (Upload an analysis as SARIF data)

Uploads SARIF data containing the results of a code scanning analysis to make the results available in a repository. For troubleshooting information, see “Troubleshooting SARIF uploads (https://docs.github.com/code-security/code-scanning/troubleshooting-sarif).”

There are two places where you can upload code scanning results.

  • If you upload to a pull request, for example ‘–ref refs/pull/42/merge’ or ‘–ref refs/pull/42/head’, then the results appear as alerts in a pull request check. For more information, see “Triaging code scanning alerts in pull requests (/code-security/secure-coding/triaging-code-scanning-alerts-in-pull-requests).”
  • If you upload to a branch, for example ‘–ref refs/heads/my-branch’, then the results appear in the Security tab for your repository. For more information, see “Managing code scanning alerts for your repository (/code-security/secure-coding/managing-code-scanning-alerts-for-your-repository#viewing-the-alerts-for-a-repository).”

You must compress the SARIF-formatted analysis data that you want to upload, using ‘gzip’, and then encode it as a Base64 format string. For example:

gzip -c analysis-data.sarif base64 -w0

SARIF upload supports a maximum number of entries per the following data objects, and an analysis will be rejected if any of these objects is above its maximum value. For some objects, there are additional values over which the entries will be ignored while keeping the most important entries whenever applicable. To get the most out of your analysis when it includes data above the supported limits, try to optimize the analysis configuration. For example, for the CodeQL tool, identify and remove the most noisy queries. For more information, see “SARIF results exceed one or more limits (https://docs.github.com/code-security/code-scanning/troubleshooting-sarif/results-exceed-limit).”

SARIF data Maximum values Additional limits
Runs per file 20  
Results per run 25,000 Only the top 5,000 results will be included, prioritized by severity.
     
Rules per run 25,000  
Tool extensions per run 100  
Thread Flow Locations per result 10,000 Only the top 1,000 Thread Flow Locations will be included, using prioritization.
     
Location per result 1,000 Only 100 locations will be included.
     
Tags per rule 20 Only 10 tags will be included.
     

The ‘202 Accepted’ response includes an ‘id’ value. You can use this ID to check the status of the upload by using it in the ‘/sarifs/{sarif_id}’ endpoint. For more information, see “Get information about a SARIF upload (/rest/code-scanning/code-scanning#get-information-about-a-sarif-upload).”

OAuth app tokens and personal access tokens (classic) need the ‘security_events’ scope to use this endpoint with private or public repositories, or the ‘public_repo’ scope to use this endpoint with only public repositories.

This endpoint is limited to 1,000 requests per hour for each user or app installation calling it.

Endpoint: POST /repos/{owner}/{repo}/code-scanning/sarifs API version: 2026-03-10

EXAMPLES

EXAMPLE 1

' -Body @{ key = 'value' }

Invokes POST /repos/{owner}/{repo}/code-scanning/sarifs

EXAMPLE 2

New-GitHubCodeScanningUploadSarif -Owner 'octocat' -Repo 'Hello-World' -Body @{ commit_sha = '4b6472266afd7b471e86085a6659e8c7f2b119da' }

Sends the request body from a hashtable, parameters override the keys of -Body

PARAMETERS

-Accept

The Accept header (media type) of the request Default value: application/vnd.github+json

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Body

The whole request body as a hashtable or object. Keys that are also available as parameters are overwritten by the parameter values

Type: System.Object
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Body
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-CheckoutUri

The base directory used in the analysis, as it appears in the SARIF file. This property is used to convert file paths from absolute to relative, so that alerts can be mapped to their correct location in the repository.

Body property [ checkout_uri ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-CommitSha

The SHA of the commit to which the analysis you are uploading relates.

Required unless -Body is used

Body property [ commit_sha ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Body
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: Default
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- cf
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Owner

The account owner of the repository. The name is not case sensitive.

Path parameter [ owner ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 0
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Ref

The full Git reference, formatted as ‘refs/heads/', 'refs/tags/', 'refs/pull//merge', or 'refs/pull//head'.

Required unless -Body is used

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Body
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: Default
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Repo

The name of the repository without the ‘.git’ extension. The name is not case sensitive.

Path parameter [ repo ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 1
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Sarif

A Base64 string representing the SARIF file to upload. You must first compress your SARIF file using ‘gzip’ (http://www.gnu.org/software/gzip/manual/gzip.html) and then translate the contents of the file into a Base64 encoding string. For more information, see “SARIF support for code scanning (https://docs.github.com/code-security/secure-coding/sarif-support-for-code-scanning).”

Required unless -Body is used

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Body
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: Default
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-StartedAt

The time that the analysis run began. This is a timestamp in ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601) format: ‘YYYY-MM-DDTHH:MM:SSZ’.

Body property [ started_at ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-ToolName

The name of the tool used to generate the code scanning analysis. If this parameter is not used, the tool name defaults to “API”. If the uploaded SARIF contains a tool GUID, this will be available for filtering using the ‘tool_guid’ parameter of operations such as ‘GET /repos/{owner}/{repo}/code-scanning/alerts’.

Body property [ tool_name ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Validate

Whether the SARIF file will be validated according to the code scanning specifications. This parameter is intended to help integrators ensure that the uploaded SARIF files are correctly rendered by code scanning.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-WhatIf

Runs the command in a mode that only reports what would happen without performing the actions.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Objects with properties named like the path parameters can be piped to this function

{{ Fill in the Description }}

System.String

{{ Fill in the Description }}

OUTPUTS

The response of the GitHub API (objects

{{ Fill in the Description }}

NOTES

OperationId: code-scanning/upload-sarif Category: code-scanning / code-scanning