File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { RepositorySbom, SbomPackage } from "./types.js";
33import { createOctokit } from "./octokit.js" ;
44import fs from "fs" ;
55import path from "path" ;
6+ import zlib from "zlib" ;
67import * as semver from "semver" ;
78
89const our_tool_name = "SBOM Toolkit" ;
@@ -275,7 +276,16 @@ export async function uploadSarifPerRepo(opts: {
275276 continue ;
276277 }
277278 const sarifContent = fs . readFileSync ( sarifPath , "utf8" ) ;
278- const sarifB64 = Buffer . from ( sarifContent , "utf8" ) . toString ( "base64" ) ;
279+ // The Code Scanning SARIF upload API expects a base64-encoded *gzip* of the SARIF JSON.
280+ // See error: "Could not decode SARIF content. Expected Base64 encoded gzip'd file." if raw JSON is provided.
281+ let sarifB64 : string ;
282+ try {
283+ const gz = zlib . gzipSync ( sarifContent ) ;
284+ sarifB64 = gz . toString ( "base64" ) ;
285+ } catch ( e ) {
286+ console . error ( `Failed to gzip SARIF file ${ sarifPath } : ${ e instanceof Error ? e . message : String ( e ) } . Sending uncompressed base64.` ) ;
287+ continue ;
288+ }
279289 await octokit . request ( "POST /repos/{owner}/{repo}/code-scanning/sarifs" , {
280290 owner,
281291 repo : name ,
You can’t perform that action at this time.
0 commit comments