Skip to content

Commit

Permalink
Support security-experimental as a well-known suite
Browse files Browse the repository at this point in the history
  • Loading branch information
angelapwen committed Feb 3, 2023
1 parent b95df0b commit 5039ea0
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 11 deletions.
6 changes: 5 additions & 1 deletion lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ export const CODEQL_VERSION_ML_POWERED_QUERIES_WINDOWS = "2.9.0";
*/
export const CODEQL_VERSION_BETTER_RESOLVE_LANGUAGES = "2.10.3";

/**
* Versions 2.11.1+ of the CodeQL CLI introduces `security-experimental` query suites for all languages.
*/
export const CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE = "2.12.1";

/**
* Set up CodeQL CLI access.
*
Expand Down
23 changes: 21 additions & 2 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ test(
process.platform === "win32" ? undefined : "~0.1.0"
);
// Test that ML-powered queries aren't run when the user hasn't specified that we should run the
// `security-extended` or `security-and-quality` query suite.
// `security-experimental`, `security-extended`, or `security-and-quality` query suite.
test(mlPoweredQueriesMacro, "2.7.5", true, undefined, undefined, undefined);
// Test that ML-powered queries are run on non-Windows platforms running `security-extended` on
// versions of the CodeQL CLI prior to 2.9.0.
Expand Down Expand Up @@ -2074,7 +2074,6 @@ test(
"security-extended",
"~0.4.0"
);

// Test that ML-powered queries are run on all platforms running `security-and-quality` on CodeQL
// CLI 2.11.3+.
test(
Expand All @@ -2085,6 +2084,26 @@ test(
"security-and-quality",
"~0.4.0"
);
// Test that ML-powered queries aren't run on all platforms running `security-experimental` on CodeQL
// CLI version prior to 2.12.1, because this suite is unsupported.
test(
mlPoweredQueriesMacro,
"2.12.0",
true,
undefined,
"security-experimental",
"~0.4.0"
);
// Test that ML-powered queries are run on all platforms running `security-experimental` on CodeQL
// CLI 2.12.1+.
test(
mlPoweredQueriesMacro,
"2.12.1",
true,
undefined,
"security-experimental",
"~0.4.0"
);

const calculateAugmentationMacro = test.macro({
exec: async (
Expand Down
22 changes: 20 additions & 2 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CodeQL,
CODEQL_VERSION_GHES_PACK_DOWNLOAD,
CODEQL_VERSION_ML_POWERED_QUERIES_WINDOWS,
CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE,
ResolveQueriesOutput,
} from "./codeql";
import * as externalQueries from "./external-queries";
Expand Down Expand Up @@ -380,7 +381,11 @@ async function addDefaultQueries(
}

// The set of acceptable values for built-in suites from the codeql bundle
const builtinSuites = ["security-extended", "security-and-quality"] as const;
const builtinSuites = [
"security-experimental",
"security-extended",
"security-and-quality",
] as const;

/**
* Determine the set of queries associated with suiteName's suites and add them to resultMap.
Expand All @@ -401,6 +406,17 @@ async function addBuiltinSuiteQueries(
if (!found) {
throw new Error(getQueryUsesInvalid(configFile, suiteName));
}
if (
suiteName === "security-experimental" &&
!(await codeQlVersionAbove(
codeQL,
CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE
))
) {
throw new Error(
`'security-experimental' suite is not supported on CodeQL versions less than ${CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE}.`
);
}

// If we're running the JavaScript security-extended analysis (or a superset of it), the repo is
// opted into the ML-powered queries beta, and a user hasn't already added the ML-powered query
Expand All @@ -413,7 +429,9 @@ async function addBuiltinSuiteQueries(
CODEQL_VERSION_ML_POWERED_QUERIES_WINDOWS
))) &&
languages.includes("javascript") &&
(found === "security-extended" || found === "security-and-quality") &&
(found === "security-experimental" ||
found === "security-extended" ||
found === "security-and-quality") &&
!packs.javascript?.some(isMlPoweredJsQueriesPack) &&
(await featureEnablement.getValue(Feature.MlPoweredQueriesEnabled, codeQL))
) {
Expand Down

0 comments on commit 5039ea0

Please sign in to comment.