Introducing a new way to review your PRs.

Read the announcement

imputnet / helium

Private, fast, and honest web browser

View on GitHub

17 documents · Updated Nov 23, 2026

docs / domain-substitution-and-network-policy

Domain substitution and network policy

Domain substitution is a source preparation step that replaces selected upstream service names with altered, blockable names before Helium is built. It limits direct ties to upstream endpoints while preserving approved exceptions and keeping the source tree reversible and consistent with the checked-in file lists.

Policy model

The policy has two separate inputs. domain_regex.list defines what names are changed and their replacement text. domain_substitution.list defines where the changes may occur. Together they prevent a broad text replacement from changing unrelated source, legal text, security data, or Helium-owned components.

The current rules target service families associated with Google and other upstream services. They also include boundary checks and explicit exceptions. For example, general Google matches do not rewrite support.google.com, and Chrome matches preserve selected developer and status hosts. These exceptions protect source links that must remain usable for development or documentation.

The policy is therefore a constrained rewrite rather than a network filter at run time. A matching endpoint is changed in the built source; a path outside the allowed file set or an excluded path is left as it is.

References: domain_regex.list• L1-21 devutils/update_lists.py• L123-155 utils/…/test_domain_substitution.py• L39-78

Source file selection

The file list is derived from the source tree so it can follow changes in the upstream checkout. devutils/update_lists.py first limits candidates to text-like source formats, skips contingent files that may not exist in every source package, and avoids binary content. It then adds a file only when the combined domain search expression finds a target name.

This process separates domain policy from source-tree shape. The checked-in domain_substitution.list is the expected result for the supported source revision, while CI regenerates a comparison list from the actual unpacked tree. A change in Chromium source, the regex rules, or the selection rules can therefore surface as a list mismatch before a build uses stale coverage.

The current list records matching paths across the browser, component, content, third-party, and build-tool areas of the source tree. It is a generated coverage record rather than a hand-maintained catalog of network services.

The selection rules give path exclusions precedence over inclusions. They omit areas such as transport-security data, licenses, test content, selected upstream metadata, third-party uBlock content, and Helium-owned content. This keeps domain rewriting from changing data whose meaning depends on exact host names or whose handling belongs to another policy.

References: devutils/update_lists.py• L38-80 devutils/update_lists.py• L123-155 devutils/update_lists.py• L238-281 devutils/update_lists.py• L322-364 .github/…/ci.yml• L104-139 domain_substitution.list• L1-17506

Rewrite lifecycle

The substitution lifecycle transforms an upstream source tree and records enough state to restore it. The Python utility reads each selected file with one of the supported text encodings, applies the ordered regex pairs, and writes only files with at least one replacement.

The process follows this sequence:

  1. Load the regex pairs and selected relative paths.
  2. Skip missing paths and paths that became symlinks.
  3. Rewrite matching text in each selected file.
  4. Record the original file and a checksum of the rewritten file in an optional cache.
  5. Build or validate the source using the rewritten tree.
  6. Restore the original files only after the rewritten contents still match the cache checksums.

The cache makes reversal safe across build steps. It stores original files under an orig area and keeps an index of rewritten paths and CRC32 values. Reversal stops when the source tree has changed since substitution, because replacing a changed file could erase later work.

This diagram shows how policy inputs become a reversible source-tree change.

flowchart LR
    R[Domain regex rules] --> S[Source file selection]
    F[Domain substitution list] --> S
    S --> T[Selected source files]
    T --> W[Ordered endpoint rewrites]
    W --> C[Rewritten source tree]
    T --> B[Original-content cache]
    C --> H[Checksum index]
    C --> V[Build and validation]
    B --> X[Validated restoration]
    H --> X
    X --> O[Original source tree]

References: utils/domain_substitution.py• L43-77 utils/domain_substitution.py• L82-124 utils/domain_substitution.py• L186-247 utils/domain_substitution.py• L250-317

Generated substitution script

The standalone script generator provides the same policy for workflows that need a shell script instead of the Python cache workflow. utils/make_domsub_script.py converts the Python-style replacement references into Perl form, embeds the selected file paths and rules, and can create a Quilt backup, a tar backup, or no backup.

The generated script checks that it runs inside a Chromium source tree. It then backs up the selected files when requested and applies the rules to their full contents. This path is useful for source workflows that already manage changes through shell tools, but it does not replace the checksum-based restoration guarantees of the Python utility.

References: utils/make_domsub_script.py• L17-94 utils/make_domsub_script.py• L102-129

Policy boundaries

Domain substitution works with related source hygiene rules but does not perform all network or privacy work. Binary pruning removes selected non-text data, while upstream and Helium patches change browser behavior and service use. The substitution layer only changes matching names in its approved source paths.

The boundary matters because a rewritten name can affect endpoint reachability without proving that every network path is removed. Engineers should use the privacy and upstream patch page for behavior changes and the build configuration page for source acquisition and build inputs. See Privacy and upstream patch sources and Build configuration and downloads.

References: devutils/update_lists.py• L210-235 utils/prune_binaries.py• L18-45 utils/domain_substitution.py• L186-209

Change checklist

When these files or sections are changed, remember to consider these:

  • Update domain_substitution.list when the generated source-tree result changes. CI compares the checked-in list with a fresh result.
  • Review regex ordering and exception boundaries together. A later rule can see text produced by an earlier rule.
  • Keep path exclusions aligned with any patch or feature that requires an exact upstream host name.
  • Preserve the replacement-group syntax in domain_regex.list when changing both the Python utility and the generated Perl script path.
  • Treat cache format or checksum changes as a source restoration contract change. Apply and revert workflows must remain compatible.

Important failure modes

TriggerConsequenceGuard
A regex matches an endpoint that an exception should preserveDocumentation, support, or development links can stop workingUse host-boundary exceptions and preserve-host tests in domain_regex.list and utils/…/test_domain_substitution.py
A selected source file changes after substitutionReversion refuses to restore it and avoids overwriting newer contentValidate the rewritten-file checksum from the cache index before restoration
The generated file list differs from domain_substitution.listCI rejects the source-policy change before build work proceedsRegenerate the list from the target source tree and review the diff
A required path is excluded from selectionAn upstream endpoint remains in the built sourceReview include and exclude precedence in devutils/update_lists.py
A source file uses an unsupported encodingSubstitution aborts for that file or runKeep candidate files within the supported text encodings and handle decode failures before release

Key files

FileWhy to read it
domain_regex.listDefines the endpoint patterns, replacement names, and preserved host boundaries.
domain_substitution.listDefines the source paths covered by the current policy.
utils/domain_substitution.pyDescribes application, caching, checksum validation, and restoration.
devutils/update_lists.pyExplains how the source tree becomes the checked-in path list and how exclusions are enforced.
utils/make_domsub_script.pyShows the alternate standalone-script form of the policy.
utils/…/test_domain_substitution.pyShows the guarantees for preserved hosts, changed hosts, and unchanged files.
.github/…/ci.ymlShows where generated lists are compared with the checked-in policy during CI.