Repository navigation
fix(plugins): enforce the manifest condition for private hosts at dial time - #696
Conversation
…l time The paca.fetch client is shared by every plugin, so its dialer only knew the operator's list. A plugin with "*" was kept off listed private hosts by the pre-check alone, which a DNS answer changing before the dial could bypass. paca.fetch now puts the hosts the manifest names into the request context, and the dialer grants the exception only to hosts in both sets. A request without that context gets no exception. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Important
The dial-time fix is sound and well-tested, but the new per-request allowance is consulted only inside DialContext, so a pooled keep-alive connection can bypass it. Details below.
Reviewed changes
netguard.go— addsWithAllowedPrivateHosts(unexported context key) and makesguardedDialer.dialContextdrop the operator exception unless the dial's context set alsoContains(host); a missing value fails closed.runtime.go—paca.fetchattachesmanifestPrivateHosts(allowed)to the request context; new helper canonicalizes entries, where"*"and IP literals name nothing. Redirect-guard comment updated.- Tests —
TestGuardedDial_RequiresPerRequestAllowance,TestGuardedDial_AllowanceDoesNotWidenOperatorSet,TestManifestPrivateHosts; existing dial tests passallowCtx.go test ./internal/platform/netguard/... ./internal/platform/plugin/...passes locally. - Docs —
backend-plugin-system.mdnotes the dial-time check.
⚠️ The per-request allowance is bypassed by keep-alive connection reuse
The guard added at netguard.go:162-165 is only reached from DialContext. Go's http.Transport serves an idle pooled connection without dialing, keyed solely on scheme|host:port and independent of the request context. Since a single paca.fetch client serves every plugin, a "*" plugin can target an operator-listed private host and ride a keep-alive connection that a manifest-named plugin already established to it — the dial-time check never runs.
Technical details
# Per-request allowance bypassed on pooled connection reuse
## Affected sites
- `services/api/internal/platform/netguard/netguard.go:162-165` — the allowance check, reachable only via `DialContext`.
- `services/api/internal/platform/plugin/runtime.go:2299-2302` — the request context set, moot when the connection is reused.
- `services/api/internal/bootstrap/app.go:426` — one shared client/transport for all plugins.
## Required outcome
- A `"*"` plugin must not reach an operator-listed private host even when a manifest-named plugin has a warm connection to that `scheme|host:port` in the shared transport pool.
## Mechanics
- `Transport.getConn` tries `queueForIdleConn` before `queueForDial`; on a hit it returns the pooled `persistConn` and `DialContext` is never invoked (`net/http/transport.go`, `connectMethodKey = {proxy, scheme, addr, onlyH1}`). `DefaultMaxIdleConnsPerHost=2`, `IdleConnTimeout=90s`.
- The `"*"` plugin's own `isAllowedFetchDomain` pre-check still passes under DNS rebinding (it sets `privateHosts = nil` when the manifest does not name the host, so it only blocks on the resolution it sees), which is the same window this PR closes for fresh dials.
## Suggested approach (pick one)
- Disable keep-alives for the `paca.fetch` transport (`DisableKeepAlives = true`), or
- Give each plugin its own transport/client so pools are not shared, or
- Add a request-time check (e.g. a `RoundTripper` wrapper, not just `CheckRedirect`) that rejects a target host that is operator-listed but not named in the manifest — deterministic, independent of DNS.
## Open questions for the human
- Is closing the pooled-reuse path in scope here, or a deliberate follow-up? The change is still a strict improvement over #693's behavior.deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…e it The dial-time check is skipped when the transport reuses a pooled connection, so a "*" plugin could ride a connection another plugin opened to a listed host. The pre-check now refuses a listed host the manifest does not name, whatever it resolves to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Good catch on pooled connections, fixed in 28812cd: the pre-check now refuses a listed private host that the manifest does not name, whatever it resolves to, so a |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Refused operator-listed hosts not named in the manifest —
isAllowedFetchDomain(services/api/internal/platform/plugin/runtime.go:2429) now returnsfalsewhen a URL host is inPLUGIN_FETCH_PRIVATE_HOSTSbut absent from the plugin's manifest, whatever it resolves to now. This closes the prior review's finding: a"*"plugin can no longer ride a pooled keep-alive connection a manifest-named plugin established to a listed host, because the request is refused beforehttp.Client.Doand before the transport can reuse a connection. - Per-request manifest set — added
manifestPrivateHosts, which canonicalizes the manifest's named hosts into the set the dialer checks viaWithAllowedPrivateHosts;"*"and IP literals name nothing. - Tests —
TestGuardedDial_RequiresPerRequestAllowance,TestGuardedDial_AllowanceDoesNotWidenOperatorSet, a wildcard pre-check case inTestIsAllowedFetchDomain_PrivateHosts, andTestManifestPrivateHosts; theallowCtxhelper threads the request allowance through the existing dial tests. - Docs and comments —
backend-plugin-system.mddocuments the pre-check and dial-time behavior, and the redirect-guard/dialer comments were updated to reflect the new layering.
The design is now defense-in-depth with the request-level check (pre-check + redirect guard) complementing the transport-level dialer check, and I independently traced the dialer, redirect guard, redirect context inheritance, HTTP/2 multiplexing, and IDN canonicalization without finding a remaining path to a listed host.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Follow-up to #693, addressing pullfrog's note there: #693 was merged before this commit landed.
The rule "the plugin's manifest names the host" was only checked before the request, while the shared dialer used the whole operator list. With DNS rebinding between the two lookups, a
"*"plugin could reach a listed private host.paca.fetchputs the private hosts its manifest names in the request context (netguard.WithAllowedPrivateHosts)."*"and IP literals name nothing."*"plugin can no longer reach a listed host, even one that resolves public.netguardclients are unchanged.Tests: a wildcard case in
TestIsAllowedFetchDomain_PrivateHosts(fails without the pre-check change),TestGuardedDial_RequiresPerRequestAllowance,TestGuardedDial_AllowanceDoesNotWidenOperatorSet,TestManifestPrivateHosts; removing the context check or widening the manifest set makes them fail.go vet,go test ./...and golangci-lint (0 issues) pass. Docs inbackend-plugin-system.mdupdated.🤖 Generated with Claude Code