Skip to content

Commit 51d697c

Browse files
committed
💄
1 parent 5f3e207 commit 51d697c

5 files changed

Lines changed: 26 additions & 33 deletions

File tree

‎src/vs/platform/extensionManagement/common/configRemotes.ts‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const SecondLevelDomainMatcher = /([^@:.]+\.[^@:.]+)(:\d+)?$/;
1313
const RemoteMatcher = /^\s*url\s*=\s*(.+\S)\s*$/mg;
1414
const AnyButDot = /[^.]/g;
1515

16-
export const SecondLevelDomainWhitelist = [
16+
export const AllowedSecondLevelDomains = [
1717
'github.com',
1818
'bitbucket.org',
1919
'visualstudio.com',
@@ -54,7 +54,7 @@ function extractDomain(url: string): string | null {
5454
return null;
5555
}
5656

57-
export function getDomainsOfRemotes(text: string, whitelist: string[]): string[] {
57+
export function getDomainsOfRemotes(text: string, allowedDomains: readonly string[]): string[] {
5858
const domains = new Set<string>();
5959
let match: RegExpExecArray | null;
6060
while (match = RemoteMatcher.exec(text)) {
@@ -64,16 +64,9 @@ export function getDomainsOfRemotes(text: string, whitelist: string[]): string[]
6464
}
6565
}
6666

67-
const whitemap = whitelist.reduce((map, key) => {
68-
map[key] = true;
69-
return map;
70-
}, Object.create(null));
71-
72-
const elements: string[] = [];
73-
domains.forEach(e => elements.push(e));
74-
75-
return elements
76-
.map(key => whitemap[key] ? key : key.replace(AnyButDot, 'a'));
67+
const allowedDomainsSet = new Set(allowedDomains);
68+
return Array.from(domains)
69+
.map(key => allowedDomainsSet.has(key) ? key : key.replace(AnyButDot, 'a'));
7770
}
7871

7972
function stripPort(authority: string): string | null {

‎src/vs/platform/extensionManagement/test/common/configRemotes.test.ts‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getDomainsOfRemotes, getRemotes } from 'vs/platform/extensionManagement
88

99
suite('Config Remotes', () => {
1010

11-
const whitelist = [
11+
const allowedDomains = [
1212
'github.com',
1313
'github2.com',
1414
'github3.com',
@@ -20,37 +20,37 @@ suite('Config Remotes', () => {
2020
];
2121

2222
test('HTTPS remotes', function () {
23-
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://github.com/Microsoft/vscode.git'), whitelist), ['github.com']);
24-
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://git.example.com/gitproject.git'), whitelist), ['example.com']);
25-
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username@github2.com/username/repository.git'), whitelist), ['github2.com']);
26-
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username:password@github3.com/username/repository.git'), whitelist), ['github3.com']);
27-
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username:password@example2.com:1234/username/repository.git'), whitelist), ['example2.com']);
28-
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://example3.com:1234/username/repository.git'), whitelist), ['example3.com']);
23+
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://github.com/Microsoft/vscode.git'), allowedDomains), ['github.com']);
24+
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://git.example.com/gitproject.git'), allowedDomains), ['example.com']);
25+
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username@github2.com/username/repository.git'), allowedDomains), ['github2.com']);
26+
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username:password@github3.com/username/repository.git'), allowedDomains), ['github3.com']);
27+
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username:password@example2.com:1234/username/repository.git'), allowedDomains), ['example2.com']);
28+
assert.deepStrictEqual(getDomainsOfRemotes(remote('https://example3.com:1234/username/repository.git'), allowedDomains), ['example3.com']);
2929
});
3030

3131
test('SSH remotes', function () {
32-
assert.deepStrictEqual(getDomainsOfRemotes(remote('ssh://user@git.server.org/project.git'), whitelist), ['server.org']);
32+
assert.deepStrictEqual(getDomainsOfRemotes(remote('ssh://user@git.server.org/project.git'), allowedDomains), ['server.org']);
3333
});
3434

3535
test('SCP-like remotes', function () {
36-
assert.deepStrictEqual(getDomainsOfRemotes(remote('git@github.com:Microsoft/vscode.git'), whitelist), ['github.com']);
37-
assert.deepStrictEqual(getDomainsOfRemotes(remote('user@git.server.org:project.git'), whitelist), ['server.org']);
38-
assert.deepStrictEqual(getDomainsOfRemotes(remote('git.server2.org:project.git'), whitelist), ['server2.org']);
36+
assert.deepStrictEqual(getDomainsOfRemotes(remote('git@github.com:Microsoft/vscode.git'), allowedDomains), ['github.com']);
37+
assert.deepStrictEqual(getDomainsOfRemotes(remote('user@git.server.org:project.git'), allowedDomains), ['server.org']);
38+
assert.deepStrictEqual(getDomainsOfRemotes(remote('git.server2.org:project.git'), allowedDomains), ['server2.org']);
3939
});
4040

4141
test('Local remotes', function () {
42-
assert.deepStrictEqual(getDomainsOfRemotes(remote('/opt/git/project.git'), whitelist), []);
43-
assert.deepStrictEqual(getDomainsOfRemotes(remote('file:///opt/git/project.git'), whitelist), []);
42+
assert.deepStrictEqual(getDomainsOfRemotes(remote('/opt/git/project.git'), allowedDomains), []);
43+
assert.deepStrictEqual(getDomainsOfRemotes(remote('file:///opt/git/project.git'), allowedDomains), []);
4444
});
4545

4646
test('Multiple remotes', function () {
4747
const config = ['https://github.com/Microsoft/vscode.git', 'https://git.example.com/gitproject.git'].map(remote).join('');
48-
assert.deepStrictEqual(getDomainsOfRemotes(config, whitelist).sort(), ['example.com', 'github.com']);
48+
assert.deepStrictEqual(getDomainsOfRemotes(config, allowedDomains).sort(), ['example.com', 'github.com']);
4949
});
5050

51-
test('Whitelisting', () => {
51+
test('Non allowed domains are anonymized', () => {
5252
const config = ['https://github.com/Microsoft/vscode.git', 'https://git.foobar.com/gitproject.git'].map(remote).join('');
53-
assert.deepStrictEqual(getDomainsOfRemotes(config, whitelist).sort(), ['aaaaaa.aaa', 'github.com']);
53+
assert.deepStrictEqual(getDomainsOfRemotes(config, allowedDomains).sort(), ['aaaaaa.aaa', 'github.com']);
5454
});
5555

5656
test('HTTPS remotes to be hashed', function () {

‎src/vs/platform/telemetry/common/telemetryUtils.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ export function cleanRemoteAuthority(remoteAuthority?: string): string {
156156
}
157157

158158
let ret = 'other';
159-
// Whitelisted remote authorities
160-
['ssh-remote', 'dev-container', 'attached-container', 'wsl'].forEach((res: string) => {
159+
const allowedAuthorities = ['ssh-remote', 'dev-container', 'attached-container', 'wsl'];
160+
allowedAuthorities.forEach((res: string) => {
161161
if (remoteAuthority!.indexOf(`${res}+`) === 0) {
162162
ret = res;
163163
}

‎src/vs/workbench/contrib/extensions/browser/extensionEditor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ export class ExtensionEditor extends BaseEditor {
617617
if (!link) {
618618
return;
619619
}
620-
// Whitelist supported schemes for links
620+
// Only allow links with specific schemes
621621
if (matchesScheme(link, Schemas.http) || matchesScheme(link, Schemas.https) || matchesScheme(link, Schemas.mailto)
622622
|| (matchesScheme(link, Schemas.command) && URI.parse(link).path === ShowCurrentReleaseNotesActionId)
623623
) {

‎src/vs/workbench/contrib/tags/electron-browser/workspaceTags.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { IWorkspaceTagsService, Tags } from 'vs/workbench/contrib/tags/common/wo
1616
import { IWorkspaceInformation } from 'vs/platform/diagnostics/common/diagnostics';
1717
import { IRequestService } from 'vs/platform/request/common/request';
1818
import { isWindows } from 'vs/base/common/platform';
19-
import { getRemotes, SecondLevelDomainWhitelist, getDomainsOfRemotes } from 'vs/platform/extensionManagement/common/configRemotes';
19+
import { getRemotes, AllowedSecondLevelDomains, getDomainsOfRemotes } from 'vs/platform/extensionManagement/common/configRemotes';
2020

2121
export function getHashedRemotesFromConfig(text: string, stripEndingDotGit: boolean = false): string[] {
2222
return getRemotes(text, stripEndingDotGit).map(r => {
@@ -111,7 +111,7 @@ export class WorkspaceTags implements IWorkbenchContribution {
111111
return [];
112112
}
113113
return this.textFileService.read(uri, { acceptTextOnly: true }).then(
114-
content => getDomainsOfRemotes(content.value, SecondLevelDomainWhitelist),
114+
content => getDomainsOfRemotes(content.value, AllowedSecondLevelDomains),
115115
err => [] // ignore missing or binary file
116116
);
117117
});

0 commit comments

Comments
 (0)