Skip to content

pkg/profiling has no importer and serves unauthenticated mutating endpoints: delete it, or make it safe to enable #245

Closed

Description

@scttfrdmn

pkg/profiling has no importer, and the two settings that looked like they enabled it — global.enable_pprof and global.profile_port — were removed in v0.11.0 rather than wired (#202/#211/#212). This issue is where the package's fate gets decided.

What is actually there

pkg/profiling builds an HTTP server and registers the standard net/http/pprof handlers, plus its own /memory/gc and /memory/free. Nothing imports it: no cmd/, no internal/adapter, no test outside the package.

Three problems, in order of seriousness:

  1. /memory/gc and /memory/free are mutating handlers with no authentication. A GET from anything that can reach the port forces a garbage collection or returns memory to the OS. That is a remote latency knob on a filesystem.
  2. It binds fmt.Sprintf(":%d", port) — every interface. The same defect as metrics and health listeners bind all interfaces, and the address is not configurable #211, in a second server. A pprof endpoint publishes goroutine stacks, heap contents and command line to whoever asks.
  3. The bind is on a goroutine that logs and returns, so a mount that asked for profiling and did not get it looks identical to one that did.

global.profile_port defaulted to 6060 and global.enable_pprof defaulted to false, and neither reached this package or any other. Wiring them inside the change that stopped binding two unauthenticated listeners would have been the wrong trade on the strength of a boolean nothing read.

The decision

Either:

(a) Delete pkg/profiling. net/http/pprof is four lines against a mux an operator already controls, and the package's only additions over the standard handlers are the two mutating endpoints that should not exist. A profiling story that reads "import net/http/pprof in a debug build" is honest and costs nothing to maintain.

(b) Keep it, and make it safe to enable. Then it needs, as one change: an addr setting inside a block with its own enabled flag (matching monitoring.metrics), defaulting to loopback; a synchronous bind whose error propagates; the mutating handlers deleted or moved behind an explicit second flag; a Shutdown the adapter calls; and a test that asserts the bound address rather than that something is listening.

(a) is the recommendation. The audit found no caller, no test, and no documentation that describes profiling as working.

Either way

  • SECURITY.md currently states plainly that no pprof listener is started at any address, and links here. If (b) lands, that paragraph changes.
  • internal/config/config.go's GlobalConfig doc comment explains why the two keys were removed rather than wired, and links here.

Activity

  1. added
    type: technical-debt
    type: security
    priority: medium
    area: config
    on Aug 3, 2026
  2. scttfrdmn commented on Aug 5, 2026

    @scttfrdmn
    OwnerAuthor

    Three measurements before the decision this issue asks for, one of which changes what option (a) means.

    pkg/profiling is mostly not the pprof server

    The issue describes the package as "builds an HTTP server and registers the standard net/http/pprof handlers, plus its own /memory/gc and /memory/free". That is one function out of thirty-three. pkg/profiling/memory.go is 592 lines and its actual surface is a memory monitor:

    • MemoryMonitor with a sampling loop, a concurrent GC monitor, and a ring of MemorySamples
    • AlertThresholds / Alert / AlertLevel / AlertCallback — a threshold-alerting system with registered callbacks
    • GetMemoryStats, GetSamples, GetSamplesSince, GetGoroutineCount, takeBaseline
    • startPprofServer and four handlers — the part this issue is about

    So "delete pkg/profiling" as written deletes a monitor to remove a listener. That may still be the right call, but it should be made knowing that is what it is, and the issue's stated justification — "net/http/pprof is four lines against a mux an operator already controls" — only covers the last item on that list.

    There are two memory monitors, and the documented one is the other one

    pkg/memmon also exists: 595 lines in monitor.go plus 321 in profiler.go, and it declares a type also called MemoryMonitor with a NewMemoryMonitor constructor, a monitorLoop, takeSample, and analyzeMemory. It has no importer either — verified for the module path across the tree, same as pkg/profiling.

    The two are not documented equally. docs/memory-monitoring.md is a 253-line guide, and every line of it is about pkg/memmon — "The pkg/memmon package provides: real-time memory monitoring, automatic leak detection, object tracking, memory profiling, alert system", with a Quick Start that imports pkg/memmon and calls memmon.DefaultMonitorConfig(). pkg/profiling appears in no user-facing document at all; its only mention anywhere outside itself is the pointer in internal/config/config.go:155 that this issue's predecessor added.

    pkg/memmon does not bind a listener — no ListenAndServe, no http.Server, no handler registration. So the security half of this issue is specific to pkg/profiling, while the documented-feature half belongs to pkg/memmon.

    That makes the real question larger than this issue's framing: the repo has two unimported implementations of the same concept, one documented and one not, and the one carrying the unauthenticated listener is the undocumented one. Deleting pkg/profiling alone removes the security exposure and leaves a documented-but-dead pkg/memmon behind — which is the shape of defect the audit was about, just relocated.

    Both have tests, and they pass

    pkg/profiling is at 75.4% coverage, pkg/memmon at 51.9%, and go test -race is green for both. Worth stating because it affects how deletion reads in the coverage numbers, and because a package with 682 lines of passing tests does not look dead from any automated angle — which is presumably part of why both survived this long.

    Effect on the recommendation

    The issue recommends (a), delete. I still think a variant of (a) is right, but it should be one decision over both packages rather than one over half of one:

    1. Delete pkg/profiling outright. It is undocumented, has no importer, and carries the two unauthenticated mutating handlers plus the every-interface bind. Nothing is lost that pkg/memmon does not already claim to do.
    2. Then decide pkg/memmon separately: either wire it to something (it is what docs/memory-monitoring.md promises, so the honest options are "make the doc true" or "delete the doc with the package"), or delete both and say plainly that memory monitoring is not a feature.

    Doing 1 without 2 leaves docs/memory-monitoring.md describing a package no code path reaches, which is exactly the pattern in the ~190 documentation overclaims tracked elsewhere.

    I have not touched either package; this is just the measurement. Happy to implement whichever shape is wanted, but "delete pkg/profiling" and "delete the memory-monitoring story" are different decisions and the second one is not mine to make.

    Either way

    The two follow-ups this issue already lists still hold — SECURITY.md's paragraph stating no pprof listener is started, and internal/config/config.go's GlobalConfig comment explaining why enable_pprof/profile_port were removed rather than wired. Both link here, so both need touching by whatever lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: configpriority: mediumtype: securitytype: technical-debt

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions