Skip to content

feat(proxy): short-circuit configured blocked hosts locally#1376

Open
maybeknott wants to merge 1 commit into
therealaleph:mainfrom
maybeknott:feat/local-block-hosts
Open

feat(proxy): short-circuit configured blocked hosts locally#1376
maybeknott wants to merge 1 commit into
therealaleph:mainfrom
maybeknott:feat/local-block-hosts

Conversation

@maybeknott
Copy link
Copy Markdown

Local filtering should happen before a request consumes relay capacity. Tracker, ad, telemetry, and other operator-defined blocked hosts do not need an Apps Script execution, a tunnel session, or an outbound dial attempt when the proxy can make a local decision from the destination hostname.

Add a block_hosts TOML setting that accepts exact hostnames and leading-dot suffix rules. The matcher normalizes hostnames consistently and applies the same rule set across the local proxy ingress paths, so an entry such as example.com matches only that host while .example.com matches subdomains below it.

HTTP proxy requests and CONNECT requests to blocked hosts are short-circuited locally with 204 No Content. SOCKS5 CONNECT requests receive a ruleset failure before any remote connection is attempted. SOCKS5 UDP datagrams for blocked hosts are dropped before a tunnel session is allocated. Non-matching requests continue through the existing proxy, Apps Script, tunnel, or direct fallback paths unchanged.

The desktop UI preserves hand-edited TOML block-host entries when saving other settings, so users can manage the list in configuration files without the UI erasing it. TOML examples and the English/Persian guides document the setting, exact-match behavior, suffix-match behavior, and the quota-preservation reason for local filtering.

Focused tests cover exact host matching, suffix host matching, non-matching hosts, HTTP short-circuit behavior, CONNECT short-circuit behavior, SOCKS5 rejection behavior, and TOML parsing for the new setting.

Add a config-backed block_hosts list for destinations that should be answered by the local proxy before any relay, tunnel, SNI rewrite, or upstream SOCKS5 dispatch is attempted. The matcher intentionally reuses the existing passthrough host semantics: exact entries match only that hostname, while leading-dot entries match the bare suffix and its subdomains with case-insensitive trailing-dot normalization.

HTTP proxy requests now check the parsed target host at ingress. Blocked plain HTTP requests and blocked CONNECT authorities receive a local 204 No Content response with Connection: close and Content-Length: 0, so the browser gets a deterministic terminal response without opening an outbound socket or consuming Apps Script quota.

SOCKS5 CONNECT requests now check the resolved request target before the success reply is sent. Blocked targets receive a ruleset-failure response and no outbound connection is opened. SOCKS5 UDP ASSOCIATE datagrams also check each parsed datagram target and drop blocked destinations before creating or reusing a tunnel-mux UDP session.

The shared tunnel dispatcher keeps a defensive block_hosts guard as well, so future ingress paths cannot accidentally bypass the local policy and reach raw TCP passthrough, Full Tunnel, Apps Script relay, or SNI rewrite. This keeps the policy local to the client and avoids any changes to Code.gs, CodeFull.gs, or tunnel-node.

Wire block_hosts through the flat Config, the TOML [network] section, JSON-to-TOML migration serialization, and the desktop UI form state. The UI does not expose an editor for the list yet, but it now preserves hand-edited TOML entries on Save instead of dropping them.

Document the TOML shape in the guide, add block_hosts to the checked-in TOML examples, and cover both TOML round-trip/migration behavior and host matching semantics with focused unit tests.
@github-actions github-actions Bot added the type: feature feat: PR — auto-applied by release-drafter label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature feat: PR — auto-applied by release-drafter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant