Skip to content

Commit ed0553c

Browse files
committed
Gate loading ML models behind a hidden setting
1 parent 84ecbfc commit ed0553c

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

extensions/ql-vscode/src/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,15 @@ export function getRemoteControllerRepo(): string | undefined {
333333
export async function setRemoteControllerRepo(repo: string | undefined) {
334334
await REMOTE_CONTROLLER_REPO.updateValue(repo, ConfigurationTarget.Global);
335335
}
336+
337+
/**
338+
* Whether to insecurely load ML models from CodeQL packs.
339+
*
340+
* This setting is for internal users only.
341+
*/
342+
const SHOULD_INSECURELY_LOAD_MODELS_FROM_PACKS =
343+
new Setting('shouldInsecurelyLoadModelsFromPacks', RUNNING_QUERIES_SETTING);
344+
345+
export function shouldInsecurelyLoadMlModelsFromPacks(): boolean {
346+
return SHOULD_INSECURELY_LOAD_MODELS_FROM_PACKS.getValue<boolean>();
347+
}

extensions/ql-vscode/src/run-queries.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
TextDocument,
99
TextEditor,
1010
Uri,
11-
window
11+
window,
12+
workspace
1213
} from 'vscode';
1314
import { ErrorCodes, ResponseError } from 'vscode-languageclient';
1415

@@ -617,12 +618,18 @@ export async function compileAndRunQueryAgainstDatabase(
617618
}
618619

619620
let availableMlModels: cli.MlModelInfo[] = [];
620-
if (await cliServer.cliConstraints.supportsResolveMlModels()) {
621+
// The `capabilities.untrustedWorkspaces.restrictedConfigurations` entry in package.json doesn't
622+
// work with hidden settings, so we manually check that the workspace is trusted before looking at
623+
// whether the `shouldInsecurelyLoadMlModelsFromPacks` setting is enabled.
624+
if (workspace.isTrusted &&
625+
config.shouldInsecurelyLoadMlModelsFromPacks() &&
626+
await cliServer.cliConstraints.supportsResolveMlModels()) {
621627
try {
622628
availableMlModels = (await cliServer.resolveMlModels(diskWorkspaceFolders)).models;
623629
void logger.log(`Found available ML models at the following paths: ${availableMlModels.map(x => `'${x.path}'`).join(', ')}.`);
624630
} catch (e) {
625-
const message = `Couldn't resolve available ML models for ${qlProgram.queryPath}: ${e}`;
631+
const message = `Couldn't resolve available ML models for ${qlProgram.queryPath}. Running the ` +
632+
`query without any ML models: ${e}.`;
626633
void logger.log(message);
627634
void showAndLogErrorMessage(message);
628635
}

0 commit comments

Comments
 (0)