Repository navigation
fix(agentop): refuse non-loopback pprof addresses before binding - #2156
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The fix does what it claims. startPprof now resolves the address, refuses anything that is not loopback, and binds the resolved *net.TCPAddr, so nothing binds before the refusal and nothing can change between the check and the bind. I found no must-fix issues. There are two small doc nits inline and one title nit below.
What I verified (head 9edc282, go1.26.10, linux):
- The
cmd/agentoppprof tests pass, and so dogo vet,GOOS=windows go vetandgofmt. - I probed
startPprofwith a recordingpprofListenunder bothGODEBUG=netdns=goandnetdns=cgo. Every non-loopback form was refused without a bind attempt:"",:0,0.0.0.0,[::],[0:0:0:0:0:0:0:0],[::ffff:0:0],[fe80::1%lo], and0:47603. With cgo,0:47603resolves to 0.0.0.0 and gets the loopback refusal. With pure Go, it fails at lookup. - Loopback forms still bind on loopback:
localhost,ip6-localhost,[::ffff:127.0.0.1](binds 127.0.0.1),[::1%lo],127.255.255.254,127.0.0.1:. Under cgo,127.1and2130706433also work. - For host names,
ResolveTCPAddrandnet.Listenboth pick the first address with IPv4 preferred, so a name that resolved to loopback before still lands on the same address. I found no regression. TestServiceInstall_RefusesABrokenConfigfails in my sandbox, but it fails the same way onmain(2cb6e04), so it is environmental and unrelated.
Nit (PR title): verify-pr-title fails because the title has no conventional prefix. Something like Fix: agentop: refuse non-loopback pprof addresses before binding would satisfy it. This is advisory only.
Author: @michaljacovi (CONTRIBUTOR association, repo admin permission — maintainer)
Areas reviewed: Go (cmd/agentop/pprof.go, pprof_test.go), security (bind surface)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: Go jobs pass, including authbridge agentop and the Windows build. All of their steps succeeded. Python Tests (sparc-service) fails, and it fails on main too (run 45882260489), so it is unrelated. verify-pr-title fails (see the nit above). macOS peerproc and README demo were still pending when I reviewed.
| // uses the resolved address, never the string: a bind on every interface, even | ||
| // one closed at once, is open to the network for that moment. Resolving first | ||
| // catches every spelling of the wildcard: an empty host, "0.0.0.0", "::", a | ||
| // zoned "[::%1]", the shorthand "0", or a name a hosts file maps to 0.0.0.0. |
There was a problem hiding this comment.
nit: Two small wording points in this doc comment:
- The paragraph above (line 25) still says "Loopback only, checked on the bound address rather than the string". The main check is now on the resolved address before the bind, and the bound-address check is the backstop. Consider rewording that sentence so the two paragraphs agree.
- Only the cgo/libc resolver turns
"0"into 0.0.0.0. With the pure-Go resolver (GODEBUG=netdns=go, or aCGO_ENABLED=0build),0:47603fails withlookup 0: no such host. It is refused before any bind either way, so the safety claim holds. "Catches" just reads as if it always gets the loopback refusal.
| @@ -38,9 +39,44 @@ func TestPprofMuxMountsTheGuardedSurface(t *testing.T) { | |||
| // (":47603", "0.0.0.0:47603") would hand the heap — the session content the | |||
| // viewer is displaying — to anyone on the network. Checked on the bound | |||
There was a problem hiding this comment.
nit: "Checked on the bound address, not the string" is now slightly out of date: the refusal happens on the resolved address before any bind (which is the point of this test). Line 83 says the same thing. Consider "checked on the resolved address, not the string".
clawgenti
left a comment
There was a problem hiding this comment.
Clawgenti Code Review — COMMENT (follow-up)
This is a follow-up to review 6080151135, which was posted at this same head 9edc282 a few minutes ago and already covers the fix and its probes; I reached the same conclusion (the refusal now happens on the resolved address before any bind, and nothing binds early). This review does not repeat its points — the cgo-vs-pure-Go "0" nuance, the two doc-comment wordings, or the title nit.
It carries one distinct nit, on the test's IPv6 skip, and the <!-- reviewed --> marker the earlier review lacks, so the scanner stops re-queueing this PR every cycle.
Author: @michaljacovi (CONTRIBUTOR association; collaborator permission admin — maintainer)
Areas reviewed: Go (cmd/agentop/pprof.go, pprof_test.go), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1, signed-off: yes
CI status: Python Tests (sparc-service) and verify-pr-title fail (both covered above); the Go legs pass on this head.
Not checked:
- Windows behaviour — no Windows host here.
Go CI (core peerproc, macOS)on this head was still failing at review time; it does not touch this PR's files.
Generated by repoman github-pr-review@af425c8.
| for _, addr := range []string{"127.0.0.1:0", "[::1]:0"} { | ||
| bound, stop, err := startPprof(addr) | ||
| if err != nil { | ||
| if addr == "[::1]:0" && !strings.Contains(err.Error(), "loopback") { // no IPv6 here: a socket or bind error |
There was a problem hiding this comment.
nit: The skip predicate is broader than its comment says. Any error from startPprof("[::1]:0") that does not contain "loopback" is read as "no IPv6 here" and skips — including a bind failure that has nothing to do with IPv6 (EACCES on a hardened runner, a listener cap, a reworded error). The test then stays green while the assertion it exists for — that ::1 is not refused — silently stops running.
Suggested fix: name the condition you mean, errors.Is(err, syscall.EADDRNOTAVAIL) (or strings.Contains(err.Error(), "cannot assign requested address")), which is what a machine with no IPv6 loopback actually returns.
startPprof bound AGENTOP_PPROF_ADDR first and checked for loopback after,
so an address on every interface (":47603", "0.0.0.0:47603", "[::]:...")
or a LAN IP was open to the network for a moment before it was refused.
Resolve the address first (no socket), refuse it unless it is loopback,
and bind the resolved address rather than the string. Resolving catches
every spelling of the wildcard, including a zoned "[::%1]" and names a
hosts file maps to 0.0.0.0, and leaves no gap between check and bind. The
check after the bind stays as a backstop.
The refusal test swaps the listen call for one that fails the test, so it
never opens a socket; a new test pins that 127.0.0.1:0 and [::1]:0 still
bind and serve.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Michal Jacovi <[email protected]>
9edc282 to
f58e633
Compare
huang195
left a comment
There was a problem hiding this comment.
Summary
The fix is correct. startPprof resolves the address, refuses it if it is not loopback, and then binds the resolved address. Nothing binds before the refusal. I found no must-fix issues. I have one suggestion on the refusal test (inline). The earlier review already covers the doc-comment wording and the IPv6 skip, so I do not repeat them here.
What I checked (head f58e633, macOS, go1.26.10):
go test -run Pprof ./cmd/agentoppasses.- Mutation: I removed the resolve-and-check block and bound the string with
net.Listen, as the old code did. The refusal test still passed for the 6 wildcard cases. It failed only for the 2 addresses that the machine does not own. See the inline comment. - Head
f58e633has no change to these two files since9edc282, the head of the earlier reviews.
Author: michaljacovi (MEMBER — maintainer)
Areas reviewed: Go (cmd/agentop/pprof.go, pprof_test.go), security (bind surface)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: all checks pass
Assisted-By: Claude (Anthropic AI) [email protected]
| "192.0.2.1:0", "[2001:db8::1]:0", | ||
| } { | ||
| if _, _, err := startPprof(addr); err == nil || !strings.Contains(err.Error(), "loopback") { | ||
| t.Errorf("startPprof on %s = %v, want a refusal naming loopback", addr, err) |
There was a problem hiding this comment.
suggestion: For the wildcard cases, this assertion does not prove what the test name says. The backstop error after the bind ("did not land on a loopback address") also contains "loopback".
I tested this mutation: remove the resolve-and-check block and bind the string with net.Listen("tcp", addr), as the old code did. 6 of the 8 cases still pass: 0.0.0.0:0, :0, :47603, [::]:0, [::%1]:0 and [::ffff:0.0.0.0]:0. Only 192.0.2.1:0 and [2001:db8::1]:0 fail, because the bind fails on an address the machine does not own. The listen seam does not catch the mutation, because the mutated code does not call the seam.
Match the text that only the pre-bind check returns:
if _, _, err := startPprof(addr); err == nil || !strings.Contains(err.Error(), "is not a loopback address") {With this change, the tests pass on this head, and all 8 cases fail under the mutation (macOS, go test -run Pprof).
The wildcard cases asserted only that the error names loopback, and the backstop after a
bind ("did not land on a loopback address") does too. With the resolve-and-check block
removed and the string bound as before, 6 of the 8 cases still passed (from the review of
#2156, pprof_test.go:58). The test now matches "is not a loopback address", which only the
check before the bind returns. Its doc comment says the check is on the resolved address.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Michal Jacovi <[email protected]>
What
startPprof(the viewer's opt-in pprof,AGENTOP_PPROF_ADDR) bound the address first and checked for loopback after. So an address on every interface (:47603,0.0.0.0:47603,[::]:47603) or a LAN IP was open to the network for a moment before agentop refused it.Now the address is resolved first, which opens no socket. agentop refuses it unless it is loopback, then binds the resolved address rather than the string. Resolving catches every spelling of the wildcard: an empty host,
0.0.0.0,::, a zoned[::%1], and a name that a hosts file maps to 0.0.0.0. It also leaves no gap between the check and the bind. The check after the bind stays as a backstop, andlocalhost:0keeps working.Tests
TestStartPprofRefusesANonLoopbackBindswaps the listen call for one that fails the test. That proves the refusal comes before any bind, so the test never opens a socket. It covers0.0.0.0:0,:0,:47603,[::]:0,[::%1]:0,[::ffff:0.0.0.0]:0,192.0.2.1:0and[2001:db8::1]:0.TestStartPprofAcceptsLoopbackLiteralschecks that127.0.0.1:0and[::1]:0still bind and serve.[::1]is skipped when the machine has no IPv6 loopback.On Windows, even that brief bind on every interface pops up a Windows Defender Firewall dialog that blocks the desktop, and the old test hit it on every
go testrun, because each run buildsagentop.test.exein a new temp directory. Refusing before the bind means neither the test nor a user who sets the address gets the dialog.Assisted-By: Claude (Anthropic AI) [email protected]
Summary by CodeRabbit