Skip to content

Commit 10b4e08

Browse files
committed
Validate user input for "owner/repo"
1 parent b1f4266 commit 10b4e08

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,13 @@ export function isCanary() {
292292
*/
293293
export const NO_CACHE_AST_VIEWER = new Setting('disableCache', AST_VIEWER_SETTING);
294294

295-
/*
295+
/**
296296
* Lists of GitHub repositories that you want to query remotely via the "Run Remote query" command.
297297
* Note: This command is only available for internal users.
298298
*
299299
* This setting should be a JSON object where each key is a user-specified name (string),
300300
* and the value is an array of GitHub repositories (of the form `<owner>/<repo>`).
301301
*/
302-
303302
const REMOTE_REPO_LISTS = new Setting('remoteRepositoryLists', ROOT_SETTING);
304303

305304
export function getRemoteRepositoryLists(): Record<string, string[]> | undefined {

extensions/ql-vscode/src/run-remote-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function getRepositories(): Promise<string[] | undefined> {
6969
placeHolder: 'Select a repository list. You can define repository lists in the `codeQL.remoteRepositoryLists` setting.',
7070
ignoreFocusOut: true,
7171
});
72-
if (quickpick && quickpick.repoList.length > 0) {
72+
if (quickpick?.repoList.length) {
7373
void logger.log(`Selected repositories: ${quickpick.repoList}`);
7474
return quickpick.repoList;
7575
} else {
@@ -78,6 +78,7 @@ async function getRepositories(): Promise<string[] | undefined> {
7878
}
7979
} else {
8080
void logger.log('No repository lists defined. Displaying text input box.');
81+
const repoRegex = /^(?:[a-zA-Z0-9]+-?)*[a-zA-Z0-9]\/[a-zA-Z0-9-_]+$/;
8182
const remoteRepo = await window.showInputBox({
8283
title: 'Enter a GitHub repository in the format <owner>/<repo> (e.g. github/codeql)',
8384
placeHolder: '<owner>/<repo>',
@@ -87,6 +88,9 @@ async function getRepositories(): Promise<string[] | undefined> {
8788
if (!remoteRepo) {
8889
void showAndLogErrorMessage('No repositories entered.');
8990
return;
91+
} else if (!repoRegex.test(remoteRepo)) { // Check if user entered invalid input
92+
void showAndLogErrorMessage('Invalid repository format. Must be in the format <owner>/<repo> (e.g. github/codeql)');
93+
return;
9094
}
9195
void logger.log(`Entered repository: ${remoteRepo}`);
9296
return [remoteRepo];

0 commit comments

Comments
 (0)