Proposal: first-class native plugin HTTP, asset, and CSP contracts #2337
connorblack
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Proposal: first-class native plugin HTTP, asset, and CSP contracts
Problem
Native plugins can own server behavior and page fragments, but several missing
contracts force production integrations back into site-specific code:
outside
RouteContext;native plugin must preserve a standard protocol response;
URL, so sites copy bundles into
public/themselves; andAn editor-only browser assistant is one concrete consumer, but these gaps also
affect webhooks, protocol adapters, widgets, and other native plugins that pair a
server route with a browser bundle.
Proposed contracts
Authenticated route actor
Add
RouteContext.actoras a minimal principal:Private routes receive the authenticated actor after core authorization. Public
routes receive
null. The value excludes profile, email, session, credential,and secret data. The serialized sandbox request gains an optional additive actor
field so older transports remain compatible.
Explicit raw responses
Allow trusted native routes to declare
response: "raw"and return aResponsewithout EmDash's JSON success envelope. Core still enforces authentication,
permission, and CSRF before dispatch. Route code still owns method and input
validation.
Caching stays conservative: private responses, public errors, and public methods
other than successful
GET/HEADuseCache-Control: private, no-store. Only apublic 2xx
GET/HEADmay use its declaredcacheControlvalue. Sandboxedplugins cannot opt into raw mode.
Native browser assets
Allow a native
PluginDescriptorto declare owned Vite entrypoints:EmDash builds the entrypoint and exposes a lookup-only same-origin alias:
The versioned alias redirects to Vite's generated asset and can be cached for one
year as immutable. Validation rejects absolute/traversal-like paths, query/hash
suffixes, duplicate logical keys, cross-descriptor collisions, unsafe redirect
targets, and non-native descriptors. The route never loads auth, sessions, the
database, or the plugin runtime.
Trusted fragment CSP hashes
When Astro CSP is enabled, EmDash computes SHA-256 sources from the exact inline
script bodies it renders in
head,body:start, andbody:end. Hashing sharesthe renderer's existing
</escape and leaves rendered bytes unchanged. CSPaccess stays lazy when the host disables CSP. External script hosts remain the
site operator's
script-srcresponsibility.Compatibility and scope
These changes add fields and modes without changing existing JSON routes,
descriptors, or sandbox wire payloads. Existing native plugins continue to work
unchanged. The proposal does not add generic filesystem serving, expose secrets,
weaken CSRF, add
unsafe-inline, or make public page fragments depend on a usersession.
The implementation includes focused Node, Cloudflare, and workerd transport
tests; raw response and cache tests; asset validation/generation/routing tests;
and a real Astro static-build CSP regression.
Would maintainers approve this direction for a minor
emdashrelease?All reactions