Skip to content

Commit cc66b83

Browse files
committed
Fixed SARIF upload to add gzip
1 parent a02a601 commit cc66b83

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/malwareMatcher.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RepositorySbom, SbomPackage } from "./types.js";
33
import { createOctokit } from "./octokit.js";
44
import fs from "fs";
55
import path from "path";
6+
import zlib from "zlib";
67
import * as semver from "semver";
78

89
const 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,

0 commit comments

Comments
 (0)