pluginsdk/docs/adr/0007-plugin-routes-declare-their-access.md
Alex Dunmow 754a713b0e Add the route package: plugin routes declare their access
Routes under /api/plugins/<name> take Public, Visitor or Admin. Visitor and
Admin routes check the host-verified identity; a public POST goes through
Form, which requires the host-verified captcha and a per-instance submission
limit. CaptchaWidget returns the CMS widget markup for Go-rendered forms.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 05:52:55 +08:00

49 lines
2.6 KiB
Markdown

# Plugin routes declare their access
Website factory plugins are written by a model and reach customer sites with
automatic checks as the only gate (orchestrator ADR 0064, ADR 0085). In the
WO-088 live runs a generated plugin served stored quote requests (names,
emails, phones, addresses) from a plain `http.ServeMux` route with no
authentication, and its public form accepted any POST with no captcha. The
SDK gave a plugin no way to say who a route is for, so check-safety had
nothing to require.
Decision: the new `route` package serves a plugin's HTTP routes under
`/api/plugins/<name>` with an access level on every route.
- `route.New(pluginName)` returns an `http.Handler` for `Registration.HTTPHandler`.
- `Handle(method, path, access, h)` takes `route.Public`, `route.Visitor` or
`route.Admin`. Visitor and Admin routes rebuild the caller from the host's
trusted identity headers and answer 401 or 403 before the handler runs;
Admin needs the `admin` or `superadmin` role. A Public route may only be
GET or HEAD; any other public method panics at registration.
- `Form(path, h)` is the one way to serve a public POST. It answers 403 unless
the host verified the request's captcha (`auth.CaptchaVerified`), 429 past
`FormBurst` submissions at once and `FormsPerMinute` after that per plugin
instance, and caps the body at `MaxFormBytes`.
- `CaptchaWidget()` returns the CMS captcha widget markup, so a Go-rendered
block can put it inside its form.
check-safety requires this package for factory-generated plugins and warns on
hand-built routers in first-party plugins.
Rejected: a host-side access declaration in the manifest. It would need an ABI
change and a CMS release for every route shape, and the guest still has to
check identity because context does not cross the ABI. The submission limit
lives in the guest because the host has no per-route limiter for plugin
routes; it counts per wasm instance, so the real ceiling is the pool size times
the limit. A per-client limit needs a host-verified client address and is
recorded as a remaining gap in orchestrator ADR 0085.
Consequences:
- Released in v0.3.12. The plugin builder image, its module cache and the
factory prompt bundle move to v0.3.12 together.
- Generated plugins get a 401, 403, 405 or 429 from the router itself, which
the runtime acceptance harness checks route by route.
Keywords: route, route.New, route.Handle, route.Form, route.Public,
route.Visitor, route.Admin, CaptchaWidget, FormsPerMinute, FormBurst,
MaxFormBytes, access level, plugin HTTP routes, captcha, rate limit, public
form, WO-097, website factory, generated plugin