Skip to content

fix(agentop): refuse non-loopback pprof addresses before binding - #2156

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
michaljacovi:pprof-loopback
Nov 28, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
michaljacovi:pprof-loopback

Conversation

@michaljacovi

@michaljacovi michaljacovi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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, and localhost:0 keeps working.

Tests

  • TestStartPprofRefusesANonLoopbackBind swaps 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 covers 0.0.0.0:0, :0, :47603, [::]:0, [::%1]:0, [::ffff:0.0.0.0]:0, 192.0.2.1:0 and [2001:db8::1]:0.
  • TestStartPprofAcceptsLoopbackLiterals checks that 127.0.0.1:0 and [::1]:0 still bind and serve. [::1] is skipped when the machine has no IPv6 loopback.
  • The existing tests for host names and the guarded mux are unchanged and pass.

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 test run, because each run builds agentop.test.exe in 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

  • Bug Fixes
    • The profiling endpoint now refuses to bind to wildcard or non-loopback addresses, including when the host is omitted.
    • Loopback IPv4 and IPv6 addresses remain supported, with the selected port resolved during binding.

@michaljacovi
michaljacovi requested a review from a team as a code owner November 26, 2026 20:09
@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 797656f5-8dbe-406d-9f1d-a251e2e49df2
Commits

Reviewing files that changed from the base of the PR and between 9edc282 and f58e633.

Files selected for processing: 2

  • cmd/agentop/pprof.go
  • cmd/agentop/pprof_test.go

No actionable comments were generated in the recent review.

Walkthrough

startPprof now resolves the requested TCP address and rejects non-loopback addresses before binding. Tests cover rejected addresses and successful IPv4 and IPv6 loopback binds.

Changes: Pprof loopback binding

Layer / File(s) Summary
Pre-bind validation and listener tests
cmd/agentop/pprof.go, cmd/agentop/pprof_test.go
startPprof resolves the address and rejects non-loopback IPs before calling pprofListen. The listener binds the resolved TCP address, and the post-bind loopback check remains. Tests check rejection before binding and verify IPv4 and IPv6 loopback binds.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • rossoctl/cortex#1611: Adds the post-bind loopback check and assigned-port reporting for the same pprof listener path.

Suggested reviewers: huang195, clawgenti

Merge Risk: Minimal · previous review 9edc2

The change makes the opt-in pprof listener refuse non-loopback addresses before binding a socket, and tests cover the main cases. No actionable merge-blocking risk was found in the changed code. The PR title needs a conventional prefix to pass the title check.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title names the primary change: agentop's pprof listener now refuses non-loopback addresses before binding. The raw summary confirms startPprof resolves the TCP address and rejects non-loopback IP…
Full details: Title check

Explanation

The title names the primary change: agentop's pprof listener now refuses non-loopback addresses before binding. The raw summary confirms startPprof resolves the TCP address and rejects non-loopback IPs before binding, with tests covering wildcard and non-loopback literals. The title is specific, concise, and uses a conventional commit prefix, so it fully matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 85216f62-17cb-4aba-8ccf-6392cb9a3f6a
Commits

Reviewing files that changed from the base of the PR and between 2cb6e04 and 9edc282.

Files selected for processing: 2

  • cmd/agentop/pprof.go
  • cmd/agentop/pprof_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/agentop pprof tests pass, and so do go vet, GOOS=windows go vet and gofmt.
  • I probed startPprof with a recording pprofListen under both GODEBUG=netdns=go and netdns=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], and 0:47603. With cgo, 0:47603 resolves 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.1 and 2130706433 also work.
  • For host names, ResolveTCPAddr and net.Listen both 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_RefusesABrokenConfig fails in my sandbox, but it fails the same way on main (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.

Comment thread cmd/agentop/pprof.go
// 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a CGO_ENABLED=0 build), 0:47603 fails with lookup 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.

Comment thread cmd/agentop/pprof_test.go
@@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmd/agentop/pprof_test.go
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@michaljacovi michaljacovi changed the title agentop: refuse non-loopback pprof addresses before binding fix(agentop): refuse non-loopback pprof addresses before binding Nov 26, 2026
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]>

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/agentop passes.
  • 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 f58e633 has no change to these two files since 9edc282, 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]

Comment thread cmd/agentop/pprof_test.go
"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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@huang195
huang195 merged commit 7715238 into rossoctl:main Nov 28, 2026
61 of 62 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 28, 2026
huang195 pushed a commit that referenced this pull request Nov 29, 2026
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]>
huang195 added a commit that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants