Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [UNRELEASED]

- Add new configuration option to allow downloading databases from http, non-secure servers. [#2332](https://github.com/github/vscode-codeql/pull/2332)

## 1.8.2 - 12 April 2023

- Fix bug where users could end up with the managed CodeQL CLI getting uninstalled during upgrades and not reinstalled. [#2294](https://github.com/github/vscode-codeql/pull/2294)
Expand Down
5 changes: 5 additions & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@
"scope": "window",
"minimum": 0,
"description": "Report a warning for any join order whose metric exceeds this value."
},
"codeQL.databaseDownload.allowHttp": {
"type": "boolean",
"default": false,
"description": "Allow database to be downloaded via HTTP. Warning: enabling this option will allow downloading from insecure servers."
}
}
},
Expand Down
11 changes: 11 additions & 0 deletions extensions/ql-vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,14 @@ export const CODESPACES_TEMPLATE = new Setting(
export function isCodespacesTemplate() {
return !!CODESPACES_TEMPLATE.getValue<boolean>();
}

const DATABASE_DOWNLOAD_SETTING = new Setting("databaseDownload", ROOT_SETTING);

export const ALLOW_HTTP_SETTING = new Setting(
"allowHttp",
DATABASE_DOWNLOAD_SETTING,
);

export function allowHttp(): boolean {
return ALLOW_HTTP_SETTING.getValue<boolean>() || false;
}
7 changes: 4 additions & 3 deletions extensions/ql-vscode/src/databaseFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "./common/github-url-identifier-helper";
import { Credentials } from "./common/authentication";
import { AppCommandManager } from "./common/commands";
import { ALLOW_HTTP_SETTING } from "./config";

/**
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
Expand All @@ -49,7 +50,7 @@ export async function promptImportInternetDatabase(
return;
}

validateHttpsUrl(databaseUrl);
validateUrl(databaseUrl);

const item = await databaseArchiveFetcher(
databaseUrl,
Expand Down Expand Up @@ -356,15 +357,15 @@ async function getStorageFolder(storagePath: string, urlStr: string) {
return folderName;
}

function validateHttpsUrl(databaseUrl: string) {
function validateUrl(databaseUrl: string) {
let uri;
try {
uri = Uri.parse(databaseUrl, true);
} catch (e) {
throw new Error(`Invalid url: ${databaseUrl}`);
}

if (uri.scheme !== "https") {
if (!ALLOW_HTTP_SETTING.getValue() && uri.scheme !== "https") {
throw new Error("Must use https for downloading a database.");
}
}
Expand Down