Skip to content

Commit 9e37f46

Browse files
authored
Adds support for proper localhost loopback on RFC 6761 (microsoft#256617)
* fix: enhance localhost authority checks - πŸ” Added TLD matching for localhost variations - βœ… Updated tests to cover new localhost cases * Merged tld back into overal rLocalhost regex
1 parent 9a998a4 commit 9e37f46

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

β€Žsrc/vs/workbench/contrib/url/common/trustedDomains.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function normalizeURL(url: string | URI): string {
5050
}
5151
} catch { return url.toString(); }
5252
}
53-
const rLocalhost = /^localhost(:\d+)?$/i;
53+
const rLocalhost = /^(.+\.)?localhost(:\d+)?$/i;
5454
const r127 = /^127.0.0.1(:\d+)?$/;
5555

5656
export function isLocalhostAuthority(authority: string) {

β€Žsrc/vs/workbench/contrib/url/test/browser/trustedDomains.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ suite('Link protection domain matching', () => {
3737
linkAllowedByRules('https://127.0.0.1:3000', []);
3838
linkAllowedByRules('https://localhost', []);
3939
linkAllowedByRules('https://localhost:3000', []);
40+
linkAllowedByRules('https://dev.localhost', []);
41+
linkAllowedByRules('https://dev.localhost:3000', []);
42+
linkAllowedByRules('https://app.localhost', []);
43+
linkAllowedByRules('https://api.localhost:8080', []);
44+
linkAllowedByRules('https://myapp.dev.localhost:8080', []);
4045
});
4146

4247
test('* star', () => {

0 commit comments

Comments
Β (0)