Skip to content

Commit fdea2a5

Browse files
committed
Remove result pruning for CodeQL 2.11.2
1 parent a36fc67 commit fdea2a5

File tree

6 files changed

+5
-292
lines changed

6 files changed

+5
-292
lines changed

lib/upload-lib.js

Lines changed: 1 addition & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.test.js

Lines changed: 0 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib.test.ts

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import test from "ava";
66
import { getRunnerLogger, Logger } from "./logging";
77
import { setupTests } from "./testing-utils";
88
import * as uploadLib from "./upload-lib";
9-
import { pruneInvalidResults } from "./upload-lib";
10-
import { initializeEnvironment, SarifFile, withTmpDir } from "./util";
9+
import { initializeEnvironment, withTmpDir } from "./util";
1110

1211
setupTests(test);
1312

@@ -307,59 +306,6 @@ test("validateUniqueCategory for multiple runs", (t) => {
307306
t.throws(() => uploadLib.validateUniqueCategory(sarif2));
308307
});
309308

310-
test("pruneInvalidResults", (t) => {
311-
const loggedMessages: string[] = [];
312-
const mockLogger = {
313-
info: (message: string) => {
314-
loggedMessages.push(message);
315-
},
316-
} as Logger;
317-
318-
const sarif: SarifFile = {
319-
runs: [
320-
{
321-
tool: otherTool,
322-
results: [resultWithBadMessage1, resultWithGoodMessage],
323-
},
324-
{
325-
tool: affectedCodeQLVersion,
326-
results: [
327-
resultWithOtherRuleId,
328-
resultWithBadMessage1,
329-
resultWithBadMessage2,
330-
resultWithGoodMessage,
331-
],
332-
},
333-
{
334-
tool: unaffectedCodeQLVersion,
335-
results: [resultWithBadMessage1, resultWithGoodMessage],
336-
},
337-
],
338-
};
339-
const result = pruneInvalidResults(sarif, mockLogger);
340-
341-
const expected: SarifFile = {
342-
runs: [
343-
{
344-
tool: otherTool,
345-
results: [resultWithBadMessage1, resultWithGoodMessage],
346-
},
347-
{
348-
tool: affectedCodeQLVersion,
349-
results: [resultWithOtherRuleId, resultWithGoodMessage],
350-
},
351-
{
352-
tool: unaffectedCodeQLVersion,
353-
results: [resultWithBadMessage1, resultWithGoodMessage],
354-
},
355-
],
356-
};
357-
358-
t.deepEqual(result, expected);
359-
t.deepEqual(loggedMessages.length, 1);
360-
t.assert(loggedMessages[0].includes("Pruned 2 results"));
361-
});
362-
363309
test("accept results with invalid artifactLocation.uri value", (t) => {
364310
const loggedMessages: string[] = [];
365311
const mockLogger = {
@@ -377,62 +323,6 @@ test("accept results with invalid artifactLocation.uri value", (t) => {
377323
"Warning: 'not a valid URI' is not a valid URI in 'instance.runs[0].results[0].locations[0].physicalLocation.artifactLocation.uri'.",
378324
);
379325
});
380-
const affectedCodeQLVersion = {
381-
driver: {
382-
name: "CodeQL",
383-
semanticVersion: "2.11.2",
384-
},
385-
};
386-
387-
const unaffectedCodeQLVersion = {
388-
driver: {
389-
name: "CodeQL",
390-
semanticVersion: "2.11.3",
391-
},
392-
};
393-
394-
const otherTool = {
395-
driver: {
396-
name: "Some other tool",
397-
semanticVersion: "2.11.2",
398-
},
399-
};
400-
401-
const resultWithOtherRuleId = {
402-
ruleId: "doNotPrune",
403-
message: {
404-
text: "should not be pruned even though it says MD5 in it",
405-
},
406-
locations: [],
407-
partialFingerprints: {},
408-
};
409-
410-
const resultWithGoodMessage = {
411-
ruleId: "rb/weak-cryptographic-algorithm",
412-
message: {
413-
text: "should not be pruned SHA128 is not a FP",
414-
},
415-
locations: [],
416-
partialFingerprints: {},
417-
};
418-
419-
const resultWithBadMessage1 = {
420-
ruleId: "rb/weak-cryptographic-algorithm",
421-
message: {
422-
text: "should be pruned MD5 is a FP",
423-
},
424-
locations: [],
425-
partialFingerprints: {},
426-
};
427-
428-
const resultWithBadMessage2 = {
429-
ruleId: "rb/weak-cryptographic-algorithm",
430-
message: {
431-
text: "should be pruned SHA1 is a FP",
432-
},
433-
locations: [],
434-
partialFingerprints: {},
435-
};
436326

437327
function createMockSarif(id?: string, tool?: string) {
438328
return {

src/upload-lib.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from "fs";
22
import * as path from "path";
3-
import { env } from "process";
43
import zlib from "zlib";
54

65
import * as core from "@actions/core";
@@ -15,7 +14,7 @@ import * as fingerprints from "./fingerprints";
1514
import { Logger } from "./logging";
1615
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
1716
import * as util from "./util";
18-
import { SarifFile, SarifResult, SarifRun, UserError, wrapError } from "./util";
17+
import { SarifFile, UserError, wrapError } from "./util";
1918

2019
// Takes a list of paths to sarif files and combines them together,
2120
// returning the contents of the combined sarif file.
@@ -372,9 +371,6 @@ async function uploadFiles(
372371
environment,
373372
);
374373

375-
if (env["CODEQL_DISABLE_SARIF_PRUNING"] !== "true")
376-
sarif = pruneInvalidResults(sarif, logger);
377-
378374
const toolNames = util.getToolNames(sarif);
379375

380376
validateUniqueCategory(sarif);
@@ -596,45 +592,6 @@ function sanitize(str?: string) {
596592
return (str ?? "_").replace(/[^a-zA-Z0-9_]/g, "_").toLocaleUpperCase();
597593
}
598594

599-
export function pruneInvalidResults(
600-
sarif: SarifFile,
601-
logger: Logger,
602-
): SarifFile {
603-
let pruned = 0;
604-
const newRuns: SarifRun[] = [];
605-
for (const run of sarif.runs || []) {
606-
if (
607-
run.tool?.driver?.name === "CodeQL" &&
608-
run.tool?.driver?.semanticVersion === "2.11.2"
609-
) {
610-
// Version 2.11.2 of the CodeQL CLI had many false positives in the
611-
// rb/weak-cryptographic-algorithm query which we prune here. The
612-
// issue is tracked in https://github.com/github/codeql/issues/11107.
613-
const newResults: SarifResult[] = [];
614-
for (const result of run.results || []) {
615-
if (
616-
result.ruleId === "rb/weak-cryptographic-algorithm" &&
617-
(result.message?.text?.includes(" MD5 ") ||
618-
result.message?.text?.includes(" SHA1 "))
619-
) {
620-
pruned += 1;
621-
continue;
622-
}
623-
newResults.push(result);
624-
}
625-
newRuns.push({ ...run, results: newResults });
626-
} else {
627-
newRuns.push(run);
628-
}
629-
}
630-
if (pruned > 0) {
631-
logger.info(
632-
`Pruned ${pruned} results believed to be invalid from SARIF file.`,
633-
);
634-
}
635-
return { ...sarif, runs: newRuns };
636-
}
637-
638595
/**
639596
* An error that occurred due to an invalid SARIF upload request.
640597
*/

0 commit comments

Comments
 (0)