Repository navigation
feat(proxy): SOCKS5 relay routes (socks5://) — TCP-only, dials addresses, no outbound resolution - #58
Open
madejackson wants to merge 10 commits into
Open
madejackson wants to merge 10 commits into
madejackson wants to merge 10 commits into
Conversation
A route target scheme that turns Cosmos into an authenticated outbound SOCKS relay: socks5 (client resolves), socks5h (Cosmos resolves), socks5t (adds UDP ASSOCIATE). RFC 1928 + RFC 1929, no TLS, no GSSAPI. Design decisions worth stating: - The relay is a SocketProxy listener, not a forwarder. It joins activeProxies so StopAllProxies drains it on config change and a deleted route releases its ports; Close() also closes live connections, so a rebind does not sit in the registry's 30s timeout. - Credentials are utils.CheckPassword - the same bcrypt check the dashboard login uses. There is no per-route credential field, so there is no second auth system with different semantics. socks_auth_mode=password requires a real account: no anonymous fallback, ever. - Destination policy (allow/deny CIDRs, hosts, *.domain) is checked before dialing and re-checked against the resolved address, so a name that resolves to loopback cannot bypass "deny 127.0.0.0/8". Deny beats allow. Malformed entries fail the bind and the API, because a typo in a deny list is a hole. - UDP ASSOCIATE keys associations by client IP, not by the TCP address. A SOCKS client sends datagrams from a socket it picked itself; keying by the TCP address drops every datagram a real client sends. Replies go only to peers the association sent to, so the relay socket cannot be used as a reflector. - Fragments are dropped, not reassembled (a half datagram read as whole is silent corruption). BIND is refused: reverse-connect turns a relay into a listener on someone else's schedule. - socks5 vs socks5h vs socks5t are capability signals over one implementation. Tests cover wire framing (reply lengths, address types, UDP frame parse), auth (including the RFC 1929 VER byte), the CONNECT tunnel, the UDP round trip from a client socket the server was never told about, policy precedence, and route validation. [skip ci]
Target scheme socks5://, socks5h:// or socks5t:// on a ServApp/Proxy route turns the route into an outbound relay, so the editor gains a "SOCKS relay" section: auth mode, UDP ASSOCIATE, and allow/deny destination filters. - Rule logic lives in client/src/utils/socksRoute.js as a pure module (no JSX, no i18n) so it is executable and reviewable on its own, and the editor stays a renderer of these decisions. It mirrors src/proxy/Socks5Policy.go. - Destination entries are validated as the user types, with the same strictness as net.ParseCIDR (10.0.0.0/33 is rejected, and a dotted-quad is checked as an IPv4 literal, not as a hostname). Cosmos refuses to bind a relay whose filter has a typo; the editor says so before the save rather than after it. - sanitizeSocksFields strips the socks fields from routes that are not relays, so moving a route off a socks target does not leave dead options in the config, and drops empty lists instead of sending "" -- the server derives defaults from the scheme, and an explicit empty string is noise in the config file. - socks_udp and socks_auth_mode are tri-state (auto / explicit) rather than checkboxes, because the scheme sets the default and "off" is a real choice. - The capabilities line states what the selected scheme means: socks5 asks the client to resolve, socks5h/socks5t ask Cosmos, socks5t adds UDP. socks5 vs socks5h are hints over one implementation, and the UI says that. - The section explains the security shape in plain words: authentication uses Cosmos accounts, so the relay is only as private as the accounts allowed to log in. Keys added to en, de and fr; fallbackLng is en, so the rest stay legible. [skip ci]
Caught by regenerating api-docs and reading the schema it produced: ProxyRouteConfig fields marshal under their Go names (LBMode, AdditionalTargets, WhitelistInboundIPs), because most of them carry no json tag. encoding/json matches a key to a field case-insensitively, but it does NOT ignore underscores -- socks_auth_mode decodes into nothing. The first version of the editor sent snake_case keys, so every option would have decoded as empty and the relay would run on scheme defaults while the user believed they had configured it. Silent, and the worst shape of bug for an access-control setting. - Editor now sends SocksAuthMode / SocksUDP / SocksAllowDestinations / SocksDenyDestinations, matching the Go field names. - SocksUDP is emitted as a string, not a JSON boolean: it is a tri-state string on the server precisely so "unset" and "explicitly false" stay distinguishable, and a boolean would fail to unmarshal into a string field and reject the whole save. - New src/utils/socks_route_wire_test.go pins the boundary from the server side: it decodes the exact payload the editor emits, checks the tri-state stays tri-state, rejects a JSON boolean, and asserts unset fields are omitted on the way out. The client's own assertions check the serialised payload, not the JS object. - go-sdk/client.gen.go updated by hand (+15/-1). scripts/generate-api.sh pulls @latest oapi-codegen, which regenerated 1666 lines of unrelated churn (dropped enum consts and Valid() helpers); the surgical edit keeps the diff reviewable. - api-docs picked up the four fields via swag; src/index.go version stamp unchanged. - Info text said the listening port was "below" the section: the socket-proxy Host field renders above it. en/de/fr corrected. - changelog.md gains the feature line; ASERACORP.md gains a ledger row marked as on-branch and not landed, so the "39 commits / 132 files" counters describing the landed fork stay honest. [skip ci]
End-to-end tests drive the production wiring -- a route in the config, InitInternalSocketProxy, the activeProxies registry, startProxy, startSocksProxy -- and speak SOCKS5 to the relay over a socket dialed from outside. No HTTP server, storage or docker: the relay reaches upstream with plain net.Dial, so the whole feature is exercisable without Cosmos's runtime. Nine cases: a route starts a relay and tunnels a real HTTP request; a password route refuses an anonymous client and tunnels for a real account; bad credentials are refused; UDP ASSOCIATE carries a datagram round trip socks5t; UDP is refused socks5h; an open tunnel does not block teardown and the port is free afterwards; a deleted route releases its port; a config change rebinds the same port with the new policy; a deny destination is refused through the route path. The suite immediately caught a conformance bug: readRequest read CMD as the first byte and tolerated any value, so a client sending VER=0x05, as RFC 1928 requires, got its version rejected as a reserved byte -- curl, browsers and socat could never complete a CONNECT. The codec now reads VER, CMD, RESV, ATYP and rejects a non-5 version, which also refuses a SOCKS4 request on a SOCKS5 port. The unit helper that sent the buggy leading 0x00 is fixed to match, plus negative tests for the version and RESV bytes.
socks5t is not a scheme any client speaks. curl has --socks5 and --socks5-hostname, browsers hand SOCKS to the OS, git-lfs/chisel/miniflux and the xray/v2ray ecosystem use socks5/socks5h. GitHub code search for the URL form "socks5t://" returns 0 results across all of GitHub, against 108,544 for "socks5h://". Accepting it meant offering a route target nothing can connect to. (The 673 hits for bare "socks5t" are substring artifacts -- socks5Tcp, socks5tohttp, socks5tcp -- not schemes.) UDP is out for the same reason Cosmos is a reverse proxy: inbound UDP is already served by udp routes, each with its own listener, and a reverse proxy forwards inbound traffic to services -- it does not forward outbound traffic to arbitrary destinations. A SOCKS client punching out to arbitrary UDP destinations is an anonymizer feature, not a reverse-proxy one, and doing it safely needs a UDP socket per association plus client-address tracking. SOCKS UDP is TCP-framed datagrams either way (RFC 1928 carries them over the control connection), so making the relay TCP-only costs nothing in connectivity. - Schemes: socks5, socks5h. UDP ASSOCIATE answers command-not-supported, as BIND already did, so a probing client falls back to CONNECT. - Removes the UDP relay socket, per-association state, the datagram framing/parse path, socksMaxDatagram, socksUDPRelayTTL and the socks_udp tri-state field across the config type, API docs, Go SDK, editor and locales. - ValidateSocksRoute now rejects any socks-prefixed scheme it does not serve. Without that a socks5t route saved cleanly, startProxy logged "Unsupported protocol" in a log nobody reads, and the operator got a route that did nothing. Tests: UDP ASSOCIATE refusal asserted for both schemes, in the relay and through the production wiring -- including that the relay does not squat the UDP half of its port, which a udp route needs, and that CONNECT still works on the same route after a refusal. Scheme acceptance table, socks5t/socks4a rejection cases. go test -race ./src/proxy ./src/utils clean.
madejackson
force-pushed
the
feat/socks5-relay-routes
branch
from
November 15, 2026 00:50
d884908 to
e9319db
Compare
socks5h is a forward-proxy feature: it exists to serve a client that has no DNS of its own, by making the proxy resolve the destination name. Cosmos is a reverse proxy -- routes expose listeners, and every client that reaches one has already resolved the name. Accepting socks5h made Cosmos a recursive resolver for outbound connections and published a capability a reverse proxy has no reason to have. - socks5 is the only relay scheme; socks5h is refused by name with an explanation, not folded into the generic scheme error. - readRequest refuses ATYP=0x03 (domain) and handleTCP answers it with "ATYP not supported", so a client that sends a name gets a clean, permanent answer and resolves it itself. - The relay dials the address in the request. net.LookupHost is gone: no resolver, no "resolved address re-checked against the deny list" step. - Destination lists are IP/CIDR only. A hostname entry cannot be enforced by a relay that does not resolve, and a deny list that silently matches nothing is the dangerous shape of a policy bug, so hostnames are rejected at bind time and in the editor, with the reason. - allowDestination fails closed on a nil address: "allow everything" means every address the client identified, not "dial whatever turns up". - Dead hostname paths removed from the codec (socksRequest.host, socksAddr.host, the ATYP=domain encode branch). - Editor, en/de/fr locales, changelog, api-docs and go-sdk text updated; the SDK/docs description was hand-applied because regenerating with the current swag/oapi-codegen drifted 12 unrelated doc strings and dropped enum Valid() methods from the shipped SDK.
…usal encodeAddr appended net.IPv4zero in its 16-byte form, so a reply carrying ATYP=IPv4 was 22 bytes where a client parsing fixed offsets reads 10 -- that is the reply sent for the "ATYP not supported" answer to a domain request. Truncate to the 4-byte form. Found by running the whole package: TestWriteReplyLengths asserts reply lengths because a long reply desyncs a fixed-offset client, and the -run filter used during the socks5h removal skipped it. Adds an e2e test on the production path: CONNECT with ATYP=0x03 over a socket gets a 10-byte reply with code ATYP-not-supported, not a closed socket. .gitignore: go build src/*.go names its output after the first source file (CRON.go -> CRON), so a build in the repo root drops a ~179 MB binary that `git add -A` will happily commit and the remote will reject.
madejackson
added a commit
that referenced
this pull request
Nov 16, 2026
…[skip ci] The "Full PR census" section was headed "Every PR this fork opened" but was built from one query, /repos/azukaar/Cosmos-Server/pulls. PRs live in two repos: upstream has 51, the fork repo has 58 (42 merged, 14 closed-unmerged, 2 open). The 2 open ones in the fork repo appeared nowhere in the file, and both are real gaps: - #58 SOCKS5 relay routes: 0 "socks5" hits in src on fork and upstream. 10 commits over merge-base 61050b7, +2555/-19, 21 files. merge-tree of origin/unstable x forkpr58 = 0 conflicts (only ASERACORP.md overlaps, auto-merged). Merged the head into the tip in a scratch worktree: go build ./src OK, go vet ./src/proxy OK, SOCKS tests + wire-contract tests ok. Ready to land. - #36 stale deSEC tokens: fix commit 82ac2c3 (+519 lines, certificates.go), cleanupStaleChallengeTokens + desecAPI = 0 hits in the tip. The PR head is a stale branch (7 conflicts incl. build.yml add/add) - take the one commit. - #31 dormant/health: dormant half is in the tree; the completed-vs-exited split is not (14 "completed" hits at 53edd49, 0 at tip; 3fc0ac8 is not an ancestor of it). Also corrects the azukaar#623 row: src/dnsrecords is UPSTREAM code (added in 63e5a24 = unstable021, tree 427d855 byte-identical on both sides, fork net diff on certificates.go = 0 lines) - the earlier text called it fork code. Fork #34 (deSEC autosetup) and the multicast-relay PRs are recorded as deliberate exclusions, verified 0 hits, per the 2026-10-09 instruction. New traps: count PRs per repo, not per "the fork"; only PR-invented function names are admissible signatures (generateCA/DoLetsEncrypt/GetEmail are name collisions); git worktree add takes <path> [<branch>] and a failed add leaves the shell in the main clone, which is how a bogus HEAD got read; go build in a cold worktree blows the 60s sync window (go mod download first); /tmp worktrees die with /tmp, commits survive in the object DB.
madejackson
added a commit
that referenced
this pull request
Nov 16, 2026
…kip ci] Dispatching test.yml returned HTTP 422: Actions has been disabled for this repository. Last run of any kind is #58 Test at 2026-11-14 21:51. Since then: 0 check-runs on PRs #59/#60/#61, 0 check-runs on tip 953b957 (so build.yml published no unstable release for it), and the hourly upstream-sync cron (17 * * * *) last fired 2026-11-14 21:26 - about 39 runs missing. The trap: actions/permissions reports enabled true / allowed_actions all. That is the policy endpoint, not the UI toggle, so Actions enabled read true while nothing ran. A PR whose checks area is empty reads as mergeable when it is really signal-less. Controls that do have check-runs: c3a6857 (1), d043340 (16). No REST endpoint re-enables it - Settings > Actions > General, admin, browser. Until then the gate is local: cp src/update.go src/launcher/update.go then go test -count=1 ./src/... , plus npm run client-build for client changes (test.yml never builds the client). Local gate results for the three open PRs: tmpfs fix - vite client build 26.40s OK, esbuild parse OK. deSEC fix - go build OK, go test ./src/... RC=0, -trimpath build RC=0, vet unchanged from baseline. Both recorded as verified locally, no CI.
madejackson
added a commit
that referenced
this pull request
Nov 16, 2026
* docs: rewrite the unstable ledger with a full PR census [skip ci] The ledger was keyed on fork commits, so PRs without their own fork commit (azukaar#495, azukaar#594, azukaar#615, azukaar#281, azukaar#444, azukaar#537, azukaar#607, azukaar#623) were invisible. New section "Full PR census" accounts for every PR this fork opened, classified against the tree by patch-id + file-set + content grep, with live mergeable_state. Corrections, all re-measured on 2026-11-16 (not adjusted from the old text): - counts: 41 fork commits / 135 files (+12507/-4046), 51 PRs = 7 merged, 28 open, 16 closed-unmerged, 26 clean + 2 dirty. - "azukaar#582 needs azukaar#580" was false. HeadProbeCORS is defined in exactly one place anywhere: fork commit 924f8eb. azukaar#580 (closed) touches only routeTo.go and defines nothing azukaar#582 needs. pr582 head fails to build with httpServer.go:949 undefined: utils.HeadProbeCORS; pr581 head builds OK. - "azukaar#595 -> azukaar#585 ordering" was half true: it is a content dependency on DurationStr, not an ordering constraint. 585,595 and 595,585 both build. - azukaar#592/azukaar#593 (bind-IP parse) are NOT a gap: pr593 is an ancestor of upstream/unstable (2529f20, v0.24.0-unstable006). Do not re-open. - azukaar#495, azukaar#594, azukaar#627 are shipped without a standalone fork commit. - azukaar#607 (newInstall RemoveAll) and azukaar#615 (source-less volume crash) are real gaps the fork carries on both channels. - anchors recomputed with a stated method; the old 87/85/37 column was not reproducible under any counting method. - translation census: fork 2326 keys, upstream 2272, fork-only 54, upstream-only 0; the 8 dropped keys have zero full-key references. * docs: census was upstream-only; the two fork-repo PRs were both gaps [skip ci] The "Full PR census" section was headed "Every PR this fork opened" but was built from one query, /repos/azukaar/Cosmos-Server/pulls. PRs live in two repos: upstream has 51, the fork repo has 58 (42 merged, 14 closed-unmerged, 2 open). The 2 open ones in the fork repo appeared nowhere in the file, and both are real gaps: - #58 SOCKS5 relay routes: 0 "socks5" hits in src on fork and upstream. 10 commits over merge-base 61050b7, +2555/-19, 21 files. merge-tree of origin/unstable x forkpr58 = 0 conflicts (only ASERACORP.md overlaps, auto-merged). Merged the head into the tip in a scratch worktree: go build ./src OK, go vet ./src/proxy OK, SOCKS tests + wire-contract tests ok. Ready to land. - #36 stale deSEC tokens: fix commit 82ac2c3 (+519 lines, certificates.go), cleanupStaleChallengeTokens + desecAPI = 0 hits in the tip. The PR head is a stale branch (7 conflicts incl. build.yml add/add) - take the one commit. - #31 dormant/health: dormant half is in the tree; the completed-vs-exited split is not (14 "completed" hits at 53edd49, 0 at tip; 3fc0ac8 is not an ancestor of it). Also corrects the azukaar#623 row: src/dnsrecords is UPSTREAM code (added in 63e5a24 = unstable021, tree 427d855 byte-identical on both sides, fork net diff on certificates.go = 0 lines) - the earlier text called it fork code. Fork #34 (deSEC autosetup) and the multicast-relay PRs are recorded as deliberate exclusions, verified 0 hits, per the 2026-10-09 instruction. New traps: count PRs per repo, not per "the fork"; only PR-invented function names are admissible signatures (generateCA/DoLetsEncrypt/GetEmail are name collisions); git worktree add takes <path> [<branch>] and a failed add leaves the shell in the main clone, which is how a bogus HEAD got read; go build in a cold worktree blows the 60s sync window (go mod download first); /tmp worktrees die with /tmp, commits survive in the object DB. * docs: GitHub Actions is disabled repo-wide - CI is running nowhere [skip ci] Dispatching test.yml returned HTTP 422: Actions has been disabled for this repository. Last run of any kind is #58 Test at 2026-11-14 21:51. Since then: 0 check-runs on PRs #59/#60/#61, 0 check-runs on tip 953b957 (so build.yml published no unstable release for it), and the hourly upstream-sync cron (17 * * * *) last fired 2026-11-14 21:26 - about 39 runs missing. The trap: actions/permissions reports enabled true / allowed_actions all. That is the policy endpoint, not the UI toggle, so Actions enabled read true while nothing ran. A PR whose checks area is empty reads as mergeable when it is really signal-less. Controls that do have check-runs: c3a6857 (1), d043340 (16). No REST endpoint re-enables it - Settings > Actions > General, admin, browser. Until then the gate is local: cp src/update.go src/launcher/update.go then go test -count=1 ./src/... , plus npm run client-build for client changes (test.yml never builds the client). Local gate results for the three open PRs: tmpfs fix - vite client build 26.40s OK, esbuild parse OK. deSEC fix - go build OK, go test ./src/... RC=0, -trimpath build RC=0, vet unchanged from baseline. Both recorded as verified locally, no CI. --------- Co-authored-by: madejackson <madejackson@users.noreply.github.com>
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
SOCKS5 relay routes for Cosmos: a route whose target is
socks5://starts an authenticated, TCP-only outbound relay on its port. The relay dials the address the client sends. It does not resolve names.The scheme is
socks5— and that is the whole surfacesocks5h(curl's--socks5-hostname) is not supported, deliberately: it asks the proxy to resolve the destination hostname, which exists to serve a client that has no DNS of its own. That is a forward-proxy feature. Cosmos is a reverse proxy — routes expose listeners, and every client that reaches one has already resolved the name. Acceptingsocks5hwould make Cosmos a recursive resolver for outbound connections, publish a capability a reverse proxy has no reason to have, and let clients reach hosts by name through a deployment whose policy model is addresses.Consequences, all enforced rather than documented:
ValidateSocksRouterefusessocks5h://by name with an explanation ("Cosmos is a reverse proxy and does not resolve outbound names"), not folded into a generic scheme error — an operator who wrote it means "resolve for me" and deserves that answer.readRequestrefusesATYP=0x03(domain);handleTCPanswers it withATYP not supported(0x08), a permanent code, so a client that sends a name gets a clean answer and resolves it itself instead of hanging on a closed socket. Proven over a socket byTestE2EDomainDestinationIsAnsweredWithATYPNotSupported.net.LookupHostis gone from the relay. There is no resolution step, so there is no resolved-address-recheck step either.*.domainwildcards went with them.allowDestinationfails closed on a nil address. "Allow everything" means every address the client identified, not "dial whatever turns up".socks5tis absent for a different reason: no client speaks it (see below).Behaviour
A route has no
protocolfield — what a socket route forwards is decided by the target's scheme, so the relay is expressed the same way: scheme, plus optional policy fields on the route.The API's JSON form uses the Go field names (
SocksAuthMode,SocksDenyDestinations, …) —encoding/jsonmatches keys case-insensitively but does not ignore underscores, sosocks_auth_modeover the API decodes into nothing.src/utils/socks_route_wire_test.gopins that boundary.socks_auth_mode:""/none(anonymous, default) orpassword, validated against Cosmos's own user store (utils.CheckPassword— bcrypt, plus the dummy-hash compare that keeps user enumeration timing-flat). Cosmos accounts, not a new credential type, so the UI is a toggle and there is no second auth system with semantics that differ from the rest of the proxy.socks_allow_destinations/socks_deny_destinations: IP addresses and CIDRs. Deny beats allow; an empty allow list means "allow everything" (minus deny). Checked before dialing, on the address in the request. Malformed entries are refused at the API and at bind time — a typo in a deny list is a hole, so failing loudly is the safe direction.command not supported, exactly as BIND does. Rationale below.activeProxieslike the tcp/udp forwarders, soStopAllProxies()drains it on config change and a deleted route releases its port;Close()also closes live tunnels, so a rebind does not sit in the registry's 30 s timeout. The listen path goes throughTCPSmartShieldMiddleware(country block + shield), same as tcp routes.Deliberately outbound-only: CONNECT is the only command handled. BIND is refused — a reverse-connect relay turns an egress proxy into an inbound listener punching through NAT, bypassing the firewall and the shield; BIND is for hole-punching, and Constellation is the Cosmos answer to that.
Why TCP-only, and why
socks5tis goneThe first version of this PR shipped UDP ASSOCIATE (a
socks5tscheme, asocks_udptri-state override, a UDP socket per association, client-address tracking). Commite9319dbbremoves it. Three reasons:socks5tis not a scheme any client speaks. curl has--socks5and--socks5-hostname; browsers hand SOCKS to the OS; git-lfs, chisel, miniflux and the xray/v2ray ecosystem usesocks5/socks5h. GitHub code search for the URL form"socks5t://"returns 0 results across all of GitHub. Shipping it meant offering a route target nothing can connect to.udproutes, each with its own listener. A SOCKS client punching out to arbitrary UDP destinations is an anonymizer capability, not a reverse-proxy one, and doing it safely needs a UDP socket per association plus client-address tracking.command not supportedand falls back to CONNECT.What that removal touched: the UDP relay socket, per-association state, the datagram framing/parse path,
socksMaxDatagram/socksUDPRelayTTL, and thesocks_udpfield across the config type, API docs, Go SDK, route editor and en/de/fr translations.ValidateSocksRouterejects anysocks-prefixed scheme it does not serve. Without that, a leftoversocks5t://route saved cleanly,startProxyloggedUnsupported protocolin a log nobody reads, and the operator got a route that did nothing — the API boundary now says so explicitly.Files
Server:
src/proxy/Socks5.go(relay: greeting / auth / CONNECT + lifecycle),Socks5Codec.go(RFC 1928/1929 framing),Socks5Policy.go(scheme, auth, destination lists, route validation),SocketProxy.go(scheme dispatch, registry),src/utils/types.go(route fields),src/configapi/routes.go+api-docs/+go-sdk/(API surface).UI (same repo,
client/):client/src/utils/socksRoute.js(scheme/auth/destination state, pure module so the rules are executable and reviewable — mirrorsSocks5Policy.go), SOCKS fields inrouteman.jsx, en/de/fr translations. Destination entries are validated as the user types with the same strictness asnet.ParseCIDR(10.0.0.0/33rejected; a dotted-quad checked as an IPv4 literal, not a hostname), so a typo in a deny list is reported before the save rather than at bind time.Commits on this branch
1eb395f2relay ·f05e2de1editor ·b0b2022bwire format ·c3a6857ee2e tests ·e9319dbbTCP-only (socks5tout) ·6835f36a,9e3d30eddocs/ledger ·7f002a3asocks5h+ outbound resolution out ·d202dc72,193c17celedger hash + reply-framing fix.Tests
go test ./src/proxy/ ./src/utils/ -count=1andgo test ./src/proxy/ ./src/utils/ -race -count=1pass (whole packages, no-runfilter);go build src/*.go(the pathbuild.shuses, after itscp src/update.go src/launcher/update.go) is clean;gofmtclean on every file touched.Unit (25) — wire framing (reply lengths, address types, version and RESV refusals), scheme acceptance (
socks5in;socks5h/socks5t/socks4a/socks5sout), the RFC 1929 auth exchange, the CONNECT tunnel, deny-list precedence on the address the client sent, hostname destinations rejected with a message naming hostnames, dialling requires an address, BIND and UDP ASSOCIATE refusal, route validation (bad auth mode,socks5h, unsupported schemes, pool targets, socks options on a non-relay route, malformed deny entry).End-to-end (9) — drive the production wiring: a route in the config,
InitInternalSocketProxy, theactiveProxiesregistry,startProxy,startSocksProxy, speaking SOCKS5 over a socket dialed from outside. No HTTP server, storage or docker: the relay reaches upstream with plainnet.Dial, so the feature is exercisable without Cosmos's runtime stack. Cases: route → relay → real HTTP request; password route refuses an anonymous client and tunnels for a real account; bad credentials refused; UDP ASSOCIATE refused, and the relay does not squat the UDP half of its port (a route that bound a UDP socket it never answers would block audproute from using that number), with CONNECT proven to work on the same route afterwards; a domain request gets a 10-byte reply withATYP not supported, not a closed socket; an open tunnel does not block teardown and the port is free; a deleted route releases its port; a config change rebinds the same port with the new policy; a deny destination is refused through the route path.Wire contract (2) —
src/utils/socks_route_wire_test.godecodes the exact payload the editor emits and asserts unset socks fields are omitted on the way out.Two conformance bugs the tests caught, not the reading:
readRequestread CMD as the first byte and tolerated any value, so a client sendingVER=0x05— as RFC 1928 requires, i.e. every real client — had its version byte rejected as a reserved byte. curl, browsers and socat could never complete a CONNECT; the relay was only reachable by its own test helper, which sent the same buggy leading0x00. The codec now reads VER, CMD, RESV, ATYP and rejects a non-5 version, which also refuses a SOCKS4 request on a SOCKS5 port.encodeAddrappendednet.IPv4zeroin its 16-byte form, so a reply carryingATYP=IPv4was 22 bytes where a fixed-offset client reads 10 — the reply sent for the domain refusal.TestWriteReplyLengthscatches it; it only ran once the-runfilter was dropped, which is why the suite here is run unfiltered.Verified
-raceclean on./src/proxy/and./src/utils/;gofmtcleango build src/*.go(build.sh's path) → exit 0ATYP not supported, not a silent closecurl --socks5against a running CosmosNotes for the reviewer
changelog.mdfor 0.24.0 advertisedsocks5t://+ UDP ASSOCIATE and thensocks5:///socks5h://with hostname destinations; the line is updated in-repo tosocks5://with IP/CIDR filters.api-docs/andgo-sdk/client.gen.gowere hand-patched, not regenerated: runningscripts/generate-api.shwith the current swag/oapi-codegen re-escaped angle brackets and arrows in 12 unrelated doc strings (e.g.fn<name>becamefn\u003cname\u003e) and dropped the enum constants andValid()methods from the shipped SDK. That is generator-version drift and a public-API break, so only the SOCKS description text is in this PR. A follow-up should pin the generator versions..gitignoregainsCRON:go build src/*.gonames its output after the first source file, so building in the repo root drops a ~179 MB binary thatgit add -Acommits and the remote rejects. Repo hygiene, unrelated to the feature.go build ./...fails insrc/launcheronGetLatestVersionat base too:build.shcopiessrc/update.gointosrc/launcher/first, so that package never builds standalone. Not introduced here.src/utils/types.gois not gofmt-clean at base (61050b73) either; left untouched beyond the socks fields (same for the pre-existing gofmt findings inSocketProxy.go,Socketshield.go,UDPShield.go,app_gate.go,avahi.go,botblock.go,buildFromConfig.go,routeTo.go,tunnel_lb.go).Not included
Server-side authz for
:1080and port-conflict pre-flight (needsutilsstorage access);PROXY-mode HTTP routes keep their 60 s read/write deadline, so a long-lived CONNECT tunnel over an HTTP-fronted route is out of scope; hostname-based destination filtering (would need outbound resolution, which is what this PR removes).