Skip to content

feat(plugins): allow private network hosts for paca.fetch - #693

Merged
pikann merged 4 commits into
Paca-AI:masterfrom
gorlix:feat/plugin-fetch-private-hosts
Nov 3, 2026
Merged

pikann merged 4 commits into
Paca-AI:masterfrom
gorlix:feat/plugin-fetch-private-hosts

Conversation

@gorlix

@gorlix gorlix commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Note: the dial-time manifest check described below was pushed after this PR was merged. It is in #696.

Refs #656 (item 2).

paca.fetch rejects every private address, so a plugin can't reach a self-hosted GitLab on the same LAN or VPN as Paca, even when the host is in the manifest. This adds PLUGIN_FETCH_PRIVATE_HOSTS, the operator opt-in discussed in the issue. It's empty by default, and an empty list behaves as before.

Behaviour

A request may reach a private address only if all of these hold:

  • The hostname is in PLUGIN_FETCH_PRIVATE_HOSTS (exact, case-insensitive, compared in the IDNA form that is dialed).
  • The plugin's manifest names the host in allowedOutboundDomains.
  • The URL is https.
  • The address is in 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 or fc00::/7.

The dial stays pinned to the checked IP, so the rebinding protection from GHSA-cj3q-c44j-q8p9 still applies. Only the paca.fetch client gets the exception: SafeDialContext, NewSafeHTTPClient and NewSafeHTTPTransport are unchanged, so marketplace, installer, email, Jev and automation clients behave as before.

Decisions to review

  • "*" does not count as naming a host. Plugins using "*" call user-supplied URLs, so it could otherwise let any project user aim a webhook-style plugin at an internal host.
  • The manifest condition is enforced at dial time too. The paca.fetch client is shared by all plugins, so paca.fetch puts the hosts the manifest names into the request context (netguard.WithAllowedPrivateHosts), and the dialer grants the exception only to hosts in both that set and the operator's. A request without it gets no exception. Without this, a "*" plugin was kept off a listed host by the pre-check alone, which a DNS answer changing before the dial could bypass.
  • Redirects to listed hosts are checked. The URL check sees only the first URL. A redirect to a listed host must meet the same conditions (manifest, https); the dialer enforces the manifest part as well, the redirect check adds https and a clearer error. Redirects to other hosts follow the existing policy: public targets are allowed, even outside the manifest and over http.
  • Hostnames are normalized with IDNA (idna.Lookup, the profile net/http uses before dialing) everywhere they are compared, so gitlab.internal can't slip past a check on gitlab.internal. Names with no ASCII form are refused.
  • CGNAT (100.64.0.0/10) stays blocked. Some cloud metadata endpoints live there, as netguard already notes. This means Tailscale addresses aren't reachable; tracked in Plugin fetch: allow CGNAT addresses (Tailscale) for listed private hosts? #688.
  • IPv6 transition addresses never qualify, even when they carry an RFC 1918 address. Only ::ffff: mapped addresses are treated as their IPv4 form.
  • Invalid entries are skipped with a startup warning (IP literals, wildcards, URLs, host:port, leading or trailing dot, non-ASCII: list IDNs in punycode). The API still starts. A warning also lists the active hosts.
  • The operator has to edit the installed plugin's manifest to add the host (the GitLab plugin ships with gitlab.com only, and there is no override). That edit is lost when the plugin is updated.
  • parseCORSOrigins is renamed to parseCommaList, since it now has a second use.

Testing

  • go vet ./..., go test ./... (3356 tests in 59 packages) and golangci-lint v2.15 (0 issues) pass. New unit tests cover the IP rules, including embedded IPv4 forms, the pinned dial, DNS changing between dials, manifest matching (also at dial time), redirects, IDN spellings (fullwidth, soft hyphen; https and http, also through the real net/http transport) and the empty list.
  • Tested against a real GitLab CE on a private Docker network (10.77.0.0/24), behind Caddy with an internal CA, using com.paca.gitlab with the host added to a temporary copy of its manifest:
Env list Manifest gitlab.internal resolves to Result
empty names host 10.77.0.20 connection refused (503)
listed names host 10.77.0.20 connection, repository link and file read all work
listed gitlab.com only 10.77.0.20 refused (503)
listed "*" 10.77.0.20 refused (503)
listed names host 127.0.0.1 refused (503)
listed names host 169.254.169.254 refused (503)

The Helm chart renders with helm template (the variable is empty unless fetchPrivateHosts is set). Redirects, rebinding and the IDN fix are covered by unit tests only, not against the real GitLab.

Docs and deploy

Adds the variable to docker-compose.prod.yml and the Helm chart (api.plugins.fetchPrivateHosts), both of which list API variables explicitly. Documented in docs/plugins/backend-plugin-system.md, including the security implications, plus deploy/README.md and the env examples.

Possible follow-ups (pre-existing, not changed here)

  • With HTTPS_PROXY set, the dialer checks the proxy, not the destination.
  • Custom headers such as PRIVATE-TOKEN are forwarded on cross-host redirects.
  • The dial error returned to the plugin includes the resolved private IP.

🤖 Generated with Claude Code

gorlix and others added 4 commits November 2, 2026 10:40
Self-hosted services on the same LAN or VPN as Paca can't be used by
plugins, because paca.fetch rejects every private address. Add
PLUGIN_FETCH_PRIVATE_HOSTS, an operator opt-in listing exact hostnames.

A private address is reachable only if the host is listed, the plugin's
manifest names it ("*" does not count), the URL is https, and the address
is RFC 1918 or fc00::/7. Loopback, link-local, metadata, CGNAT and IPv6
transition addresses stay blocked. The dial stays pinned to the checked
IP, and only the paca.fetch client gets the exception.

Redirects are held to the same conditions, since neither the URL check
nor the dialer would otherwise see them.

Refs Paca-AI#656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
net/http maps a non-ASCII host through IDNA before dialing, so a redirect
to "gitlab.internal" (fullwidth) or "git­lab.internal" (soft
hyphen) dials "gitlab.internal". The redirect guard compared the raw name,
so a public server could send a wildcard plugin to a listed private host,
over http as well.

Add netguard.CanonicalHost, which applies the same idna.Lookup profile as
the transport and lowercases. PrivateHosts.Contains, the manifest match,
the direct request check and the redirect guard all use it, and a name
with no ASCII form is refused.

PLUGIN_FETCH_PRIVATE_HOSTS now also rejects, with the startup warning,
entries with a leading or trailing dot and non-ASCII entries, which could
never match. International names must be listed in punycode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Redirects to hosts outside the private host list follow the existing
policy: they need not be in the manifest and may use http, and only the
dial-time address check applies. Also list the entry forms that
PLUGIN_FETCH_PRIVATE_HOSTS ignores and the IDNA comparison.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
It still said origins from when the function only parsed CORS origins.

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.

ℹ️ No critical issues — the security design holds up. One defense-in-depth note inline.

Reviewed changes

  • PLUGIN_FETCH_PRIVATE_HOSTS opt-in: netguard.PrivateHosts gets NewPrivateHosts/CanonicalHost/Contains/Blocks, gating private addresses to exact listed hostnames that are also named in the manifest and served over https.
  • Dial pinning preserved: guardedDialer unifies SafeDialContext and the new NewSafeHTTPClientWithPrivateHosts; only the paca.fetch client receives the set, so marketplace/installer/email/Jev/automation keep the strict guard.
  • Redirect guard: withPrivateHostRedirectGuard re-applies the https + manifest conditions to redirects into listed hosts, since CheckRedirect is the only per-request hook the shared transport offers.
  • Config + deploy: Plugins.FetchPrivateHosts via the renamed parseCommaList, wired in bootstrap/app.go with startup warnings; Compose, Helm, docs and env examples updated; golang.org/x/net promoted for idna.
  • IDNA normalization: CanonicalHost mirrors net/http's idnaASCII (ASCII short-circuit, then idna.Lookup.ToASCII), so IDN spellings of a listed name cannot slip past the check.

I also verified the vectors the exception must not open: IP-literal/wildcard/host:port entries are refused by NewPrivateHosts; loopback, link-local/cloud metadata, CGNAT, unspecified, multicast and IPv6 transition literals stay blocked because Blocks requires ip.IsPrivate(); the Host header is already stripped from allowed fetch headers; and the Blocks decision is applied at both the URL check and the pinned dial. go test ./internal/platform/netguard/... ./internal/platform/plugin/... ./internal/config/... passes.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

return false
}
if !namedInManifest {
privateHosts = nil

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.

The manifest-naming condition is enforced only here. The transport dialer is built from the full operator set and has no plugin context, so this line is the sole gate for a "*"-manifest plugin — and it only holds if the pre-check's DNS answer matches the dial's. If the lookup here returns a public address while guardedDialer.dialContext re-resolves to a private one (TTL-0 rebinding), a wildcard plugin reaches the listed private host that privateHosts = nil was meant to deny. This is the same class the redirect guard closes for redirects, left open for the initial dial; it requires control of the listed name's DNS, which the docs already warn against trusting, so the practical impact is low.

Technical details
# Manifest-naming condition not enforced at dial time

## Affected sites
- `services/api/internal/platform/plugin/runtime.go:2322-2324` — `privateHosts = nil` grants the exception only for this pre-check; the dialer retains the full set.
- `services/api/internal/platform/netguard/netguard.go:199-203` — the transport dialer is constructed from the full operator set and cannot see `allowedOutboundDomains`.
- `services/api/internal/platform/plugin/runtime.go:2326` — pre-check resolves via `fetchLookupIPAddr`; the dial resolves again via `net.Resolver`, so the two answers can differ.

## Required outcome
- A request from a `"*"`-manifest plugin must not reach a listed private host unless the dial-time decision also reflects that the manifest does not name the host.

## Suggested approach (optional)
- The transport is shared across plugins, so this needs per-request plumbing (e.g. a per-plugin client/transport, or a dialer that consults a request-scoped allow decision) rather than a change in `Blocks`. If threading this through is out of scope, documenting it as a known limitation alongside the proxy/header follow-ups is reasonable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a931328: paca.fetch now passes the hosts the manifest names in the request context, and the shared dialer grants the exception only to hosts in both that set and the operator list (no context, no exception). Covered by TestGuardedDial_RequiresPerRequestAllowance and TestManifestPrivateHosts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correction: a931328 was pushed after this PR was merged, so it is not in master. It is in #696.

@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 06e79a7 into Paca-AI:master Nov 3, 2026
11 checks passed
pikann added a commit that referenced this pull request Nov 3, 2026
…r-plugin

Resolves the add/add conflict in
services/api/internal/platform/plugin/runtime_fetch_test.go: master's file
(private-network host and redirect guard tests, #693) is kept as is, and the
chunked-fetch tests move to runtime_fetch_chunk_test.go.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
pikann added a commit that referenced this pull request Nov 3, 2026
…r-plugin

Resolves the add/add conflict in
services/api/internal/platform/plugin/runtime_fetch_test.go: master's file
(private-network host and redirect guard tests, #693) is kept as is, and the
chunked-fetch tests move to runtime_fetch_chunk_test.go.
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