feat(proxy): short-circuit configured blocked hosts locally#1376
Open
maybeknott wants to merge 1 commit into
Open
feat(proxy): short-circuit configured blocked hosts locally#1376maybeknott wants to merge 1 commit into
maybeknott wants to merge 1 commit into
Conversation
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.
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.
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_hostsTOML 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 asexample.commatches only that host while.example.commatches 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.