domainMatcher.ts ×5

Frontier kind: Code frontier

unlabeled · c_adcfb492503c

534 tests · 3457 LOC · 19 files · introduces 0 tests · 79 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
5 ranges79 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
485 ranges3457 lines · 19 files · Browse complete extent
All tests (intent)
534 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 79 introduced LOC across 5 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/networkFilter/common/domainMatcher.ts 79 introduced LOC · 5 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- domainMatcher.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { URI } from '../../../base/common/uri.js';
7 >
8 > /**
9 > * Common file extensions that are unlikely to be network domains.
10 > * Used to filter false positives when extracting domains from freeform text.
11 > */
12 > const fileExtensionSuffixes = new Set([
13 > '7z', 'bz2', 'cjs', 'class', 'cpp', 'cs', 'css', 'csv', 'dll', 'exe', 'gif', 'gz', 'ico', 'jar',
14 > 'env', 'java', 'jpeg', 'jpg', 'js', 'json', 'jsx', 'lock', 'log', 'md', 'mjs', 'pdf', 'php', 'png',
15 > 'py', 'rar', 'rs', 'so', 'sql', 'svg', 'tar', 'tgz', 'toml', 'ts', 'tsx', 'txt', 'wasm', 'webp',
16 > 'xml', 'yaml', 'yml', 'zip'
17 > ]);
18 >
19 > /**
20 > * Bare host detection is a heuristic used only to prompt before running commands that appear to access the network.
21 > * Keep this list intentionally conservative and focused on TLDs commonly used for coding-related hosts and services.
22 > */
23 > const wellKnownDomainSuffixes = new Set([
24 > 'ai', 'cloud', 'com', 'dev', 'io', 'me', 'net', 'org', 'tech'
25 > ]);
26 >
27 > /**
28 > * Normalizes and validates a domain string.
29 > *
30 > * Strips user info, port, trailing dots, and trailing punctuation.
31 > * Accepts bare wildcards (`*`) and wildcard prefixes (`*.example.com`).
32 > *
33 > * @param value The raw domain string to normalize.
34 > * @param fromUrl Whether the value was extracted from a URL context (skips file-extension filtering).
35 > * @returns The normalized domain string, or `undefined` if the input is invalid.
36 > */
37 > export function normalizeDomain(value: string | undefined, fromUrl: boolean = false): string | undefined {
38 if (!value) {
39 return undefined;
91 return hasWildcardPrefix ? `*.${host}` : host;
92 }
94 > /**
95 > * Extracts the domain portion from a pattern string.
96 > * If the pattern contains `://`, it is parsed as a URI and the authority is returned.
97 > * Otherwise, the trimmed pattern is returned as-is.
98 > */
99 > export function extractDomainPattern(pattern: string): string {
100 const trimmed = pattern.trim();
101 if (trimmed === '*') {
111 }
112 }
114 > /**
115 > * Checks whether a normalized domain matches a given allow/deny pattern.
116 > * Supports exact matches, bare wildcards (`*`), and wildcard prefixes (`*.example.com`).
117 > *
118 > * @param domain A normalized domain (output of {@link normalizeDomain}).
119 > * @param pattern An allow/deny pattern (may be a bare domain, URL, or wildcard).
120 > * @returns `true` if the domain matches the pattern.
121 > */
122 > export function matchesDomainPattern(domain: string, pattern: string): boolean {
123 const normalizedPattern = normalizeDomain(extractDomainPattern(pattern), pattern.includes('://'));
124 if (!normalizedPattern) {
134 return domain === normalizedPattern;
135 }
137 > /**
138 > * Extracts and normalizes a domain from a URI.
139 > * Strips port numbers and trailing dots.
140 > *
141 > * @param uri The URI to extract the domain from.
142 > * @returns The normalized domain, or `undefined` if no valid domain could be extracted.
143 > */
144 > export function extractDomainFromUri(uri: URI): string | undefined {
145 return normalizeDomain(uri.authority, true);
146 }
148 > /**
149 > * Determines whether a domain is allowed based on allow and deny lists.
150 > *
151 > * Rules:
152 > * - If both lists are empty, the domain is denied (restrictive default).
153 > * - Denied patterns take precedence: if the domain matches any denied pattern, it is blocked.
154 > * - If only denied patterns are configured (allowed is empty), any non-denied domain is allowed.
155 > * - If allowed patterns are configured, the domain must match at least one to be allowed.
156 > *
157 > * @param domain A normalized domain string.
158 > * @param allowedPatterns Array of allowed domain patterns.
159 > * @param deniedPatterns Array of denied domain patterns.
160 > * @returns `true` if the domain is allowed, `false` if it is blocked.
161 > */
162 > export function isDomainAllowed(domain: string, allowedPatterns: string[], deniedPatterns: string[]): boolean {
163 // Restrictive default: deny all when both lists are empty.
164 if (allowedPatterns.length === 0 && deniedPatterns.length === 0) {