References:
Connection Allowlist restricts network connections in Chromium using a URLPattern allowlist returned by the server. The high-level flow is:
network_restrictions_id is assigned to that context, which is used to identify requests that originate from itThis document outlines the architectural design and the checks performed across different Chromium layers (network service, browser, renderer).
All security and resource restrictions (CSP, Connection Allowlists, etc.) are applied restrictively and additively. A request must satisfy all applicable security policies to proceed; if any policy blocks the request, the request is blocked.
The network service is the primary layer where network requests are handled and dispatched. The majority of Connection Allowlist enforcement occurs here.
network_restrictions_id).network_restrictions_id) is highly extensible. Other future security features or JS-based network restriction APIs (similar to the dynamic window.fence.disableUntrustedNetwork() design previously used for Fenced Frames, see CL 7709872) can leverage this same plumbing to dynamically register and enforce rules in the Network Service.network_restrictions_id)To map network requests back to the corresponding context (document or worker) and its connection allowlists, each context is associated with a unique token, the network_restrictions_id (a base::UnguessableToken).
network_restrictions_id is created on the NavigationRequest in NetworkRestrictionsNavigationThrottle.base::RefCountedData<base::UnguessableToken>) and stored in the document's DocumentAssociatedData (or worker hosts like DedicatedWorkerHost and SharedWorkerHost).network_restrictions_id (e.g., initial empty documents inheriting their creator's ID).StoragePartitionImpl::RestrictNetworkForIdsInNetworkContext.NetworkContext in the Network Service using RestrictNetworkForIds().WillProcessResponse / WillCommitWithoutUrlLoader) until the Network Service confirms the restrictions have been registered, ensuring restrictions are applied before resource loading begins.StoragePartitionImpl stores a copy of the restrictions in network_restrictions_ids_. In case of a Network Service crash, this map is used to restore the network restrictions on the new NetworkContext.DocumentAssociatedData or worker is destroyed, if it holds the last reference to the ref-counted network_restrictions_id, it schedules a cleanup of the restriction mapping from the Network Service and StoragePartitionImpl using StoragePartitionImpl::ClearNetworkRestrictionsAfterDelay.network_restrictions_id, it should use:network_restrictions_id.network::GetNoOpNetworkRestrictionsId(): When no network restrictions should be applied, bypassing restrictions entirely. This should be used carefully as it bypasses the Connection Allowlist (e.g., for browser-initiated requests that do not have an associated frame/context).network::GetTestNetworkRestrictionsId(): In tests that require a valid network restrictions ID but do not test Connection Allowlist behavior.The browser process coordinates navigation checks and handles security policies.
PolicyContainerHost associated with each document.NavigationRequest::IsAllowedByConnectionAllowlist function. This function enforces allowlist policies during key phases of navigation (such as initial request start and handling redirects).Blink is the rendering engine running in the renderer process.
fetch() when they will be intercepted by a Service Worker. This is done in blink because the renderer directly talks to the Service Worker URLLoaderFactory in these cases, not giving the document's URLLoaderFactory checks a chance to run, unless the SW decides to fallback on the original fetch. This applies when the initiating context is either a document, dedicated worker or shared worker.Service Workers act as network proxies in the renderer process, intercepting requests before they reach the network.
GetLoaderFactoryForMainScriptFetch passing the creator_network_restrictions_id_.ServiceWorkerRegisterJob::UpdateAndContinue), the loader factory is created via GetLoaderFactoryForUpdateCheck passing the creator_network_restrictions_id_.ServiceWorkerGlobalScope) itself (via fetch()) are governed by the policies stored in its own PolicyContainerHost. Those are mapped to the Service Worker's own network_restrictions_id in the Network Service via the NetworkRestrictionsWorkerThrottle. This throttle also does the same for dedicated and shared worker contexts.event.respondWith(fetch(request))) are initiated using the Service Worker‘s URLLoaderFactory and subjected to the **Service Worker’s** Connection Allowlists (associated with the Service Worker‘s own network_restrictions_id), regardless of the client document’s policies. Consequently, redirects of these fetches are checked against the Service Worker‘s connection allowlist’s redirect flag, not the document's.URLLoaderFactory (which is associated with the Service Worker‘s network_restrictions_id), thereby enforcing the Service Worker’s policies.