Skip to content

Commit 7559012

Browse files
authored
Git protocol handler improvements (microsoft#162144)
1 parent 8044546 commit 7559012

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

extensions/git/src/protocolHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as querystring from 'querystring';
1212
import { OutputChannelLogger } from './log';
1313

1414
const schemes = new Set(['file', 'git', 'http', 'https', 'ssh']);
15+
const refRegEx = /^$|[~\^:\\\*\s\[\]]|^-|^\.|\/\.|\.\.|\.lock\/|\.lock$|\/$|\.$/;
1516

1617
export class GitProtocolHandler implements UriHandler {
1718

@@ -44,7 +45,7 @@ export class GitProtocolHandler implements UriHandler {
4445
}
4546

4647
if (ref !== undefined && typeof ref !== 'string') {
47-
this.outputChannelLogger.logWarning('Failed to open URI:' + uri.toString());
48+
this.outputChannelLogger.logWarning('Failed to open URI due to multiple references:' + uri.toString());
4849
return;
4950
}
5051

@@ -62,6 +63,11 @@ export class GitProtocolHandler implements UriHandler {
6263
if (!schemes.has(cloneUri.scheme.toLowerCase())) {
6364
throw new Error('Unsupported scheme.');
6465
}
66+
67+
// Validate the reference
68+
if (typeof ref === 'string' && refRegEx.test(ref)) {
69+
throw new Error('Invalid reference.');
70+
}
6571
}
6672
catch (ex) {
6773
this.outputChannelLogger.logWarning('Invalid URI:' + uri.toString());

0 commit comments

Comments
 (0)