Skip to content

tidy-guard: why DialControl strips its own address, with a test - #286

Merged
dinstein merged 1 commit into
mainfrom
tidy-guard
Aug 9, 2026
Merged

tidy-guard: why DialControl strips its own address, with a test#286
dinstein merged 1 commit into
mainfrom
tidy-guard

Conversation

@dinstein

@dinstein dinstein commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Nightly tidy pass over internal/guard/netguard (2026-08-10 05:17 round).
The slice produced no refactor, and that is the result.

netguard.go holds two implementations of "get the bare host out of this":
canonicalHost, and the inline strip inside DialControl. On a sweep for
duplicated logic — the shape that has landed three commits already tonight —
they look like one function written twice.

I differential-tested them before merging. They are not equivalent, and the
difference runs the wrong way:

input DialControl today via canonicalHost
" 8.8.8.8:53 " unparsable → blocked public address → dialled

canonicalHost trims surrounding whitespace, so it parses inputs DialControl
refuses. Every other input tried reaches the same verdict through both — bare
and bracketed v6, v4-mapped, portless, empty, ":8080", malformed — so that
is the whole of the difference.

No such address can arrive: net.Dialer hands Control the resolved
host:port it built itself. But a fail-closed predicate at the SSRF boundary
is the wrong place to widen what is accepted on the strength of an argument
about what cannot happen — and "the two look identical" is precisely how that
widening would arrive. It is the reasoning gateway.fsSafe already writes
down for itself against proclog's rule, which is what stopped me merging that
pair two rounds ago.

  • Pass C — a comment on DialControl saying why the two stay apart.
  • " 8.8.8.8:53 " joins TestDialControl's block list, so the comment is
    enforced rather than asserted. Mutation-checked: rewriting
    DialControl to call canonicalHost fails that case and nothing else.

No behaviour change. Verification: make ci green.

netguard.go holds two implementations of "get the bare host out of this":
canonicalHost, and the inline strip in DialControl. On a sweep for duplicated
logic they look like one function written twice.

They are not, and the difference runs the wrong way to merge. canonicalHost
trims surrounding whitespace, so it parses inputs DialControl refuses:
" 8.8.8.8:53 " is unparsable in DialControl and a public address through
canonicalHost, which turns a rejection into a dial. Every other input tried —
bare and bracketed v6, v4-mapped, portless, empty, ":8080", malformed — reaches
the same verdict through both, so this is the whole of the difference.

No such address can arrive: net.Dialer hands Control the resolved host:port it
built itself. But a fail-closed predicate at the SSRF boundary is the wrong
place to widen what is accepted on the strength of an argument about what
cannot happen, and "the two look identical" is exactly how that widening would
arrive — the reasoning gateway.fsSafe already writes down for itself against
proclog's rule.

So: a comment saying why they stay apart, and " 8.8.8.8:53 " joins
TestDialControl's block list to enforce it. Mutation-checked — rewriting
DialControl to call canonicalHost fails that case and nothing else.

No behaviour change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dinstein
dinstein merged commit 245e61f into main Aug 9, 2026
3 checks passed
@dinstein
dinstein deleted the tidy-guard branch August 9, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant