Skip to content

fix(plugins): enforce the manifest condition for private hosts at dial time - #696

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
gorlix:fix/private-hosts-dial-guard
Nov 3, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
gorlix:fix/private-hosts-dial-guard

Conversation

@gorlix

@gorlix gorlix commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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.fetch puts the private hosts its manifest names in the request context (netguard.WithAllowedPrivateHosts). "*" and IP literals name nothing.
  • The dialer allows a private address only for hosts in both the operator list and that set. No set in the context means no exception (fail closed), and net/http dials redirects with the same context.
  • Pooled connections skip the dialer, so the pre-check now refuses outright a listed host the manifest does not name, whatever it resolves to (pullfrog's second note). A "*" plugin can no longer reach a listed host, even one that resolves public.
  • Other netguard clients 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 in backend-plugin-system.md updated.

🤖 Generated with Claude Code

…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]>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 — adds WithAllowedPrivateHosts (unexported context key) and makes guardedDialer.dialContext drop the operator exception unless the dial's context set also Contains(host); a missing value fails closed.
  • runtime.go — paca.fetch attaches manifestPrivateHosts(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 pass allowCtx. go test ./internal/platform/netguard/... ./internal/platform/plugin/... passes locally.
  • Docs — backend-plugin-system.md notes 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.

Pullfrog  | Fix it ➔ | View workflow run | Using 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]>
@gorlix

gorlix commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

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 "*" plugin never sends the request and cannot reuse another plugin's connection. The redirect guard already did this for redirects.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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 returns false when a URL host is in PLUGIN_FETCH_PRIVATE_HOSTS but 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 before http.Client.Do and 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 via WithAllowedPrivateHosts; "*" and IP literals name nothing.
  • Tests — TestGuardedDial_RequiresPerRequestAllowance, TestGuardedDial_AllowanceDoesNotWidenOperatorSet, a wildcard pre-check case in TestIsAllowedFetchDomain_PrivateHosts, and TestManifestPrivateHosts; the allowCtx helper threads the request allowance through the existing dial tests.
  • Docs and comments — backend-plugin-system.md documents 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit a5ffb9d into Paca-AI:master Nov 3, 2026
6 checks passed
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.

2 participants