networkFilterService.ts ×5

Frontier kind: Code frontier

unlabeled · c_d105342768a7

10 tests · 6857 LOC · 38 files · introduces 0 tests · 88 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
5 ranges88 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
980 ranges6857 lines · 38 files · Browse complete extent
All tests (intent)
10 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: 88 introduced LOC across 5 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/networkFilter/common/networkFilterService.ts 88 introduced LOC · 5 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- networkFilterService.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 { Emitter, Event } from '../../../base/common/event.js';
7 > import { Disposable } from '../../../base/common/lifecycle.js';
8 > import { LRUCache } from '../../../base/common/map.js';
9 > import { URI } from '../../../base/common/uri.js';
10 > import { localize } from '../../../nls.js';
11 > import { IConfigurationService } from '../../configuration/common/configuration.js';
12 > import { createDecorator } from '../../instantiation/common/instantiation.js';
13 > import { extractDomainFromUri, isDomainAllowed } from './domainMatcher.js';
14 > import { AgentNetworkDomainSettingId } from './settings.js';
15 >
16 > export const IAgentNetworkFilterService = createDecorator<IAgentNetworkFilterService>('agentNetworkFilterService');
17 >
18 > /**
19 > * Service that filters network requests made by agent tools (fetch tool,
20 > * integrated browser) based on the configured allowed/denied domain lists.
21 > *
22 > * Filtering is active for all callers when the `chat.agent.networkFilter` setting
23 > * is enabled.
24 > * When both domain lists are empty, all domains are denied.
25 > * When a domain appears on the denied list it is always blocked, even if it
26 > * also matches an entry on the allowed list.
27 > */
28 > export interface IAgentNetworkFilterService {
29 > readonly _serviceBrand: undefined;
30 >
31 > /**
32 > * Extracts the domain from a URI and checks it against the configured
33 > * allowed/denied domain filter.
34 > * File URIs and URIs without an authority always pass.
35 > * @returns `true` if the URI's domain is allowed, `false` if blocked.
36 > */
37 > isUriAllowed(uri: URI): boolean;
38 >
39 > /**
40 > * Formats an error message for a blocked URI based on the current filter configuration.
41 > * @param uri The URI that was blocked.
42 > * @returns A localized error message explaining that access to the URI is blocked by policy.
43 > */
44 > formatError(uri: URI): string;
45 >
46 > /**
47 > * Fires when the filter configuration changes.
48 > */
49 > readonly onDidChange: Event<void>;
50 > }
51 >
52 > export class AgentNetworkFilterService extends Disposable implements IAgentNetworkFilterService {
53 > readonly _serviceBrand: undefined;
54 >
55 > private networkFilterEnabled = false;
56 > private allowedPatterns: string[] = [];
57 > private deniedPatterns: string[] = [];
58 > private readonly domainCache = new LRUCache<string, boolean>(100);
59 >
60 > private readonly onDidChangeEmitter = this._register(new Emitter<void>());
61 > readonly onDidChange = this.onDidChangeEmitter.event;
62 >
63 > constructor(
64 > @IConfigurationService private readonly configurationService: IConfigurationService,
65 > ) {
66 > super();
67 > this.readConfiguration();
68 >
69 > this._register(this.configurationService.onDidChangeConfiguration(e => {
70 if (
71 e.affectsConfiguration(AgentNetworkDomainSettingId.NetworkFilter) ||
76 this.onDidChangeEmitter.fire();
77 }
79 > }
80 >
81 > private readConfiguration(): void {
82 > const networkFilterEnabled = this.configurationService.getValue<boolean>(AgentNetworkDomainSettingId.NetworkFilter) ?? false;
83 >
84 > this.networkFilterEnabled = networkFilterEnabled;
85 > this.allowedPatterns = this.configurationService.getValue<string[]>(AgentNetworkDomainSettingId.AllowedNetworkDomains) ?? [];
86 > this.deniedPatterns = this.configurationService.getValue<string[]>(AgentNetworkDomainSettingId.DeniedNetworkDomains) ?? [];
87 > this.domainCache.clear();
88 > }
89 >
90 > isUriAllowed(uri: URI): boolean {
91 // When domain filtering is inactive, allow all requests.
92 if (!this.shouldFilter()) {
112 return result;
113 }
114 > // Determines whether network filtering should be applied for a given request networkFilterService.ts
115 > // based on the global network filter setting.
116 > private shouldFilter(): boolean {
117 return this.networkFilterEnabled;
118 }
120 > formatError(uri: URI): string {
121 const domain = extractDomainFromUri(uri);
122 return localize(