Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow HTTP connections to fetch database #2332

Merged
merged 5 commits into from
Apr 18, 2023
Merged

Allow HTTP connections to fetch database #2332

merged 5 commits into from
Apr 18, 2023

Conversation

jrozner
Copy link
Contributor

@jrozner jrozner commented Apr 15, 2023

Introduce a new config option to allow requests over HTTP when fetching a database from a URL.

Closes #2324

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@jrozner jrozner requested a review from a team as a code owner April 15, 2023 22:42
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. This looks reasonable to me. I have a few suggestions.

"codeQL.allowHttp": {
"type": "boolean",
"default": false,
"description": "Allow databases to be downloaded via HTTP"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "Allow databases to be downloaded via HTTP"
"description": "Allow databases to be downloaded via HTTP. Warning: enabling this option will allow downloading from insecure servers."

@@ -293,6 +293,11 @@
"scope": "window",
"minimum": 0,
"description": "Report a warning for any join order whose metric exceeds this value."
},
"codeQL.allowHttp": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it clear that this is related to database downloads only.

Suggested change
"codeQL.allowHttp": {
"codeQL.databaseDownload.allowHttp": {

Comment on lines 612 to 617
export const ALLOW_HTTP = new Setting(
"allowHttp",
ROOT_SETTING,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const ALLOW_HTTP = new Setting(
"allowHttp",
ROOT_SETTING,
);
const DATABASE_DOWNLOAD_SETTING = new Setting("databaseDownload", ROOT_SETTING);
export const ALLOW_HTTP_SETTING = new Setting(
"allowHttp",
DATABASE_DOWNLOAD_SETTING,
);

@@ -27,6 +27,7 @@ import {
} from "./common/github-url-identifier-helper";
import { Credentials } from "./common/authentication";
import { AppCommandManager } from "./common/commands";
import { ALLOW_HTTP } from "./config";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { ALLOW_HTTP } from "./config";
import { ALLOW_HTTP_SETTING } from "./config";

@@ -49,7 +50,9 @@ export async function promptImportInternetDatabase(
return;
}

validateHttpsUrl(databaseUrl);
if (!ALLOW_HTTP.getValue()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!ALLOW_HTTP.getValue()) {
if (!ALLOW_HTTP_SETTING.getValue()) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on a deeper thought, can you push this check into the validateHttpsUrl method? Rename the method to validateUrl? This method parses the URL as well as check for https. It's probably better to continue to check that the URL parses regardless of whether or not it is https.

Something like this maybe:

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

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

@jrozner
Copy link
Contributor Author

jrozner commented Apr 17, 2023

All changes made and fixed the linting issue from before. Ready for review

jrozner added 2 commits April 17, 2023 12:40
Introduce a new config option to allow requests over HTTP when fetching
a database from a URL.
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround. Typo found.

extensions/ql-vscode/package.json Outdated Show resolved Hide resolved
@aeisenberg
Copy link
Contributor

I pushed a few minor changes to your branch: changelog note, typo fix in config description, and invalid variable reference fix.

@jrozner
Copy link
Contributor Author

jrozner commented Apr 17, 2023

Awesome. Changes look good. Anything else you need from me?

@aeisenberg
Copy link
Contributor

Nope. Let's wait for the checks to pass...

@aeisenberg aeisenberg enabled auto-merge April 18, 2023 00:16
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for your contribution! I hope this is what you need.

@aeisenberg aeisenberg merged commit 02f1482 into github:main Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow databases to be downloaded via http
2 participants