Repository navigation
feat(mitm): auto-discover model domains from client configs (no hardcoding) - #125
Merged
Merged
Conversation
This was referenced Aug 12, 2026
Merged
Merged
cskwork
pushed a commit
to cskwork/billion-context
that referenced
this pull request
Oct 21, 2026
… stop Per user direction (改成复用): the launcher's spawned proxy now persists after the client exits, so subsequent 'bili <client>' invocations reuse it instead of spawning a new one. This makes reuse robust across terminals (the detached proxy survives terminal close — it was already detached:true, but runLaunch killed it on client exit, defeating reuse). - ensureProxyRunning writes a PID file (~/.local/share/billion-context/ launcher-proxy-<port>.pid) after a successful spawn. - runLaunch no longer kills the spawned proxy on client exit; logs 'proxy left running at ORIGIN for reuse (run bili stop to terminate)'. - runTestPi (bili test pi smoke) KEEPS kill-on-exit (one-off, clean up). - New 'bili stop' command reads all launcher-proxy-*.pid files, kills the processes, removes the files. stopLauncherProxy() exported for cli.ts. - HELP updated. Discovery (ranxianglei#125, merged) ensures the standing/spawned proxy covers ALL client domains at runtime (isMitmHost → discoverMitmDomains), so reuse always finds a domain-matching proxy. 343/343 tests, typecheck clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace the hardcoded MITM domain whitelist with auto-discovery: bili reads each coding client's config file and extracts all model-provider HTTPS hostnames at runtime. Official / third-party / future domains are covered without hardcoding anything (except the 3 endpoints truly baked into client binaries with no config).
Why
DEFAULT_MITM_DOMAINSwas a hardcoded list (open.bigmodel.cn,api.anthropic.com, …). It only covered ZCode'sopen.bigmodel.cnprovider —zcode.z.aiandapi.z.ai(also official ZCode) were missing, and any third-party relay was invisible. Domains change; hardcoding them is brittle.bili is a client-agnostic proxy: it doesn't (and shouldn't) know which app sent a given CONNECT. So discovery targets domains, not clients — it builds one global whitelist from the union of all client configs, then MITM-decrypts any CONNECT whose host is in that set and blind-tunnels the rest.
How
src/client-config.ts— the existing claude/codex/pi config readers moved here out oflauncher.ts(avoids a circular import:launcher.tsalready importsDEFAULT_MITM_DOMAINSfrommitm.ts). Plus a new ZCode reader (~/.zcode/v2/config.json→provider.*.options.baseURL).launcher.tsre-exports everything for back-compat.src/discover.ts—discoverMitmDomains()reads all client configs, extracts HTTPS hosts (unwrapping/bili/-prefixed URLs), dedupes, lowercases. Cached by config-file mtime + 2s TTL: at most onestatevery 2 s, full re-scan only when a config file actually changes. Pure, side-effect-free except the cache.src/mitm.ts—isMitmHostnow folds indiscoverMitmDomains(): the candidate set isDEFAULT + user mitm.domains + discovered.DEFAULT_MITM_DOMAINSreduced to only the 3 endpoints hardcoded in client binaries with no config to discover from:api.anthropic.com(Claude),api.openai.com+chatgpt.com(codex-login / ChatGPT).open.bigmodel.cnremoved (now discovered from zcode/pi configs). The security-boundary comment is updated to reflect that the list is now minimal + that discovery is the primary source.Verification
Diff: +564/-154 across 7 files (
client-config.ts+194,discover.ts+108,launcher.ts−154 net,mitm.ts±20, 2 test files).Test plan
bili start --debugon a machine with ZCode + codex + pi installed → log shows the discovered domains in the MITM whitelist (banner).open.bigmodel.cn).~/.codex/config.tomlwhile bili runs → within 2 s it's auto-MITM'd (no restart).example.com) through bili → blind-tunneled, not decrypted.Follow-up (separate PRs): the
bili zcodelauncher (Electron--proxy-server+--ignore-certificate-errors-spki-listinjection) +.desktopoverride so the desktop-icon launch is covered.