Skip to content

feat(plugins): add bounded raw sandbox routes - #3190

Merged
ascorbic merged 10 commits into
feat/sandbox-binary-httpfrom
feat/plugin-raw-routes
Sep 20, 2026
Merged

ascorbic merged 10 commits into
feat/sandbox-binary-httpfrom
feat/plugin-raw-routes

Conversation

@ascorbic

@ascorbic ascorbic commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds bounded, declared request and raw response contracts for plugin routes across in-process execution, Cloudflare Worker Loader, and Node/workerd.

  • Preserves the existing method-agnostic JSON/query envelope when declarations are absent.
  • Adds host-enforced methods with 405 and Allow before plugin invocation.
  • Adds bounded none, json, text, bytes, and form-data request modes, including multipart total, part, count, and filename limits.
  • Exposes only declared safe request headers and strips credentials, cookies, every CF-Access-* header, and EmDash CSRF headers in every sandbox mode.
  • Adds explicit pluginResponse() raw text/byte responses with an 8 MiB limit, a strict response-header allowlist, host-owned caching/security headers, and active same-origin content rejection.
  • Carries route declarations through shared types, manifests, CLI probes, generated descriptors, registry artifacts, both transports, and @emdash-cms/plugin-test.
  • Requires fresh install and update consent for the exact public-route names, including no-checksum marketplace TOCTOU protection.
  • Documents the API in the public docs, canonical skill, generated skill, plugin-test README, and changeset.

This is Stack D PR 2 and is stacked on #3180. It selectively incorporates the useful schema/test seams and use cases from #3073, #2162, and #1983 without cherry-picking their stale dispatch or implicit Response/rawBody contracts. Contributor credit is retained in the commit trailers.

Related: #3073, #2162, #1983.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (no catalog files included)
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: maintainer approval and the Stack D implementation plan were supplied directly; there is no public Discussion URL.
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI Codex (GPT-5.6)

Screenshots / test output

The existing install consent dialog now displays the exact public route names verified from the downloaded plugin bundle:

Plugin install consent showing the unauthenticated webhook route

Validation:

  • pnpm build
  • pnpm typecheck
  • pnpm lint:quick and type-aware pnpm lint:json — 0 diagnostics
  • Core full suite — 6,949 passed, 10 skipped; final security/consent focus — 154 passed
  • Node/workerd — 169 passed
  • @emdash-cms/plugin-test production Worker Loader host — 15 passed
  • Plugin CLI — 485 passed
  • Plugin manifest types — 76 passed
  • Admin consent client/components — 97 passed; final exact-route update focus — 81 passed
  • Forms compatibility — 22 passed
  • Docs build — 85 pages
  • Independent adversarial review of feat/sandbox-binary-http...917e08e0 — passed after four security findings and the marketplace route-consent TOCTOU were fixed and re-reviewed

@changeset-bot

changeset-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ee83156

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
emdash Minor
@emdash-cms/admin Minor
@emdash-cms/plugin-types Minor
@emdash-cms/plugin-cli Minor
@emdash-cms/plugin-test Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Minor
@emdash-cms/registry-verification Patch
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
create-emdash Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs ee83156 Sep 20 2026, 02:58 PM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 3,052 lines across 77 files. Large PRs are harder to review and more likely to be closed without review.
This PR spans 5 different areas (area/core, area/admin, area/plugins, area/docs, area/cloudflare). Consider breaking it into smaller, focused PRs.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@pkg-pr-new

pkg-pr-new Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/admin@3190

@emdash-cms/auth

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth@3190

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth-atproto@3190

@emdash-cms/blocks

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/blocks@3190

@emdash-cms/cloudflare

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/cloudflare@3190

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/contentful-to-portable-text@3190

emdash

npm i https://pkg.pr.new/emdash-cms/emdash@3190

create-emdash

npm i https://pkg.pr.new/emdash-cms/emdash/create-emdash@3190

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/gutenberg-to-portable-text@3190

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-cli@3190

@emdash-cms/plugin-test

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-test@3190

@emdash-cms/plugin-types

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-types@3190

@emdash-cms/registry-client

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-client@3190

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-lexicons@3190

@emdash-cms/registry-loader

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-loader@3190

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-moderation@3190

@emdash-cms/registry-verification

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-verification@3190

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/sandbox-workerd@3190

@emdash-cms/x402

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/x402@3190

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-ai-moderation@3190

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-atproto@3190

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-audit-log@3190

@emdash-cms/plugin-color

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-color@3190

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-embeds@3190

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-field-kit@3190

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-forms@3190

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-webhook-notifier@3190

commit: ee83156

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-plugin-raw-routes.try.emdashcms.com, https://feat-plugin-raw-routes-emdash-playground.emdash-cms.workers.dev (commit ee83156)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://92644ccb.try.emdashcms.com, https://92644ccb-emdash-playground.emdash-cms.workers.dev ee83156 2026-09-20T14:58:50.172Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://e19097c4.try.emdashcms.com, https://e19097c4-emdash-playground.emdash-cms.workers.dev 007a997 2026-09-20T14:42:07.033Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://64bd9b52.try.emdashcms.com, https://64bd9b52-emdash-playground.emdash-cms.workers.dev 5950af8 2026-09-20T14:28:02.416Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a7f193c0.try.emdashcms.com, https://a7f193c0-emdash-playground.emdash-cms.workers.dev af9a22e 2026-09-20T12:49:07.340Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://cb48ea86.try.emdashcms.com, https://cb48ea86-emdash-playground.emdash-cms.workers.dev 54caae6 2026-09-20T12:10:37.216Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://b6d52432.try.emdashcms.com, https://b6d52432-emdash-playground.emdash-cms.workers.dev 95226bc 2026-09-20T11:51:00.396Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4ff46414.try.emdashcms.com, https://4ff46414-emdash-playground.emdash-cms.workers.dev 0d76aea 2026-09-20T10:52:14.472Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://34a2d2e2.try.emdashcms.com, https://34a2d2e2-emdash-playground.emdash-cms.workers.dev 6e5a120 2026-09-20T08:29:17.421Z Visit the dashboard ↗
  • Build: In progress 🔵

View logs ↗
991394f 2026-09-20T08:22:24.702Z View logs ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a5a19db8.try.emdashcms.com, https://a5a19db8-emdash-playground.emdash-cms.workers.dev c2f5afb 2026-09-20T07:45:37.638Z Visit the dashboard ↗

View all previews: View all previews ↗

@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@ascorbic
ascorbic force-pushed the feat/plugin-raw-routes branch from 917e08e to 565c7fd Compare September 18, 2026 08:59
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 18, 2026

@emdashbot emdashbot 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.

I reviewed the full diff (~4,960 lines across 78 files) for the raw plugin-routes feature, concentrating on areas where a cross-cutting change could introduce regressions: request contract enforcement and body limits, raw-response header allowlisting / active-content rejection, auth/CSRF ordering and public-route gating, transport fidelity across the native, Node/workerd and Cloudflare runtimes, admin consent for public routes and declared-access drift, CLI manifest extraction, type/exports from emdash/plugin, and docs/changeset consistency.

Overall the implementation is careful and internally consistent:

  • Raw responses are bounded to PLUGIN_ROUTE_MAX_BODY_BYTES (8 MiB), rewritten through a strict header allowlist, and rejected when they would serve active same-origin content types (text/html, text/javascript, SVG, WASM, etc.).
  • pluginResponse() is correctly recognized by isPluginResponse() on the host side, including after the workerd JSON-RPC round-trip where __emdashPluginResponse survives as a plain boolean.
  • Public routes are gated by routeMeta.public, require CSRF / admin auth, require explicit admin acknowledgement, and the registry/marketplace install/update handlers compare the acknowledged public-route set against the manifest-derived set before proceeding.
  • Request bodies are parsed in a bounded, declared mode (json, text, bytes, form-data, none) with size and multipart-part limits; the sandbox receives only whitelisted headers and the route-declared body bytes, not the raw stream.
  • Exports from emdash/plugin (packages/core/src/plugin-types.ts) expose both pluginRoute() and pluginResponse() and type-tests confirm the inferred input shapes.
  • The changeset covers the right packages and the docs route explains public routes, body modes, and raw responses.

I found one non-blocking consistency issue: two near-identical bundle-utility modules declare a different MAX_SCREENSHOTS cap. The two files look copy-pasted otherwise, so the values should be reconciled or the constant should be shared so CLI acceptance and runtime acceptance agree.


Findings

  • [suggestion] packages/core/src/cli/commands/bundle-utils.ts:37

    MAX_SCREENSHOTS is 5 here, but the near-identical packages/plugin-cli/src/bundle/utils.ts sets it to 8. If these caps are meant to agree (the files otherwise mirror each other), one value is stale and can let the CLI accept a bundle that the runtime later rejects — or vice versa. Reconcile the two constants, or move the screenshot caps into a shared package so they stay in sync.

  • [suggestion] packages/plugin-cli/src/bundle/utils.ts:37

    MAX_SCREENSHOTS is 8 here while packages/core/src/cli/commands/bundle-utils.ts uses 5. If the CLI and runtime are meant to apply the same manifest screenshot limit, align this with packages/core or extract the constant into @emdash-cms/plugin-types so the two bundles cannot drift.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 18, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond review/needs-rereview New commits since the last review and removed review/needs-review No maintainer or bot review yet review/awaiting-author Reviewed; waiting on the author to respond labels Sep 18, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 18, 2026
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 18, 2026
@ascorbic ascorbic added bot:review Trigger an emdashbot code review on this PR and removed bot:review Trigger an emdashbot code review on this PR labels Sep 18, 2026
@ascorbic
ascorbic force-pushed the feat/plugin-raw-routes branch from 6e5a120 to 0d76aea Compare September 20, 2026 10:48
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Sep 20, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 20, 2026
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 20, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 20, 2026

@emdashbot emdashbot 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.

Re-review of PR #3190: bounded raw sandbox routes.

The previous blocking finding is not fixed in the current head. packages/core/src/plugins/adapt-sandbox-entry.ts still derives the runtime capability set with only six implication rules, while the canonical native path in packages/core/src/plugins/define-plugin.ts has eight. A standard-format/sandboxed plugin that declares only taxonomies:write or redirects:write will silently lose the corresponding read capability, despite manifest-schema.ts promising symmetry. This contradicts the documented capability semantics and leaves sandboxed plugins with less access than an equivalent native plugin for those two capabilities.

The rest of the PR remains solid on a static read: route declarations are carried consistently through manifests, transports, and the admin consent UI; request bodies are bounded and parsed safely; raw responses enforce the 8 MiB limit, header allowlist, active-content-type block, and same-origin redirect gating; and install/update consent is checked before the bundle is stored. I did not spot any new regressions in those areas.

Please add the two missing implication rules to adaptSandboxEntry() and cover them with regression tests. Ideally extract the implication list into a single shared helper used by both definePlugin and adaptSandboxEntry so the two paths cannot drift again.


Findings

  • [needs fixing] packages/core/src/plugins/adapt-sandbox-entry.ts:301-323

    adaptSandboxEntry() derives the runtime capability set from the descriptor with six implication rules, while the native source of truth in definePlugin() has eight. The sandboxed/in-process adapter is still missing both taxonomies:write → taxonomies:read and redirects:write → redirects:read. A standard-format plugin that declares only one of those write capabilities therefore does not receive the implied read capability, contradicting the documented semantics and the symmetry promised by the manifest schema.

    Add the missing rules and regression tests; better yet, extract the implication logic into a shared helper used by both definePlugin and adaptSandboxEntry so they cannot drift again.

    	// Capability implications: broader capabilities imply narrower ones
    	// (mirrors the normalization in define-plugin.ts for native format).
    	// Operates on canonical names only.
    	if (capabilities.includes("content:write") && !capabilities.includes("content:read")) {
    		capabilities.push("content:read");
    	}
    	if (capabilities.includes("content:revisions:read") && !capabilities.includes("content:read")) {
    		capabilities.push("content:read");
    	}
    	if (capabilities.includes("taxonomies:write") && !capabilities.includes("taxonomies:read")) {
    		capabilities.push("taxonomies:read");
    	}
    	if (capabilities.includes("content:publish") && !capabilities.includes("content:read")) {
    		capabilities.push("content:read");
    	}
    	if (capabilities.includes("media:write") && !capabilities.includes("media:read")) {
    		capabilities.push("media:read");
    	}
    	if (capabilities.includes("comments:moderate") && !capabilities.includes("comments:read")) {
    		capabilities.push("comments:read");
    	}
    	if (capabilities.includes("redirects:write") && !capabilities.includes("redirects:read")) {
    		capabilities.push("redirects:read");
    	}
    	if (
    		capabilities.includes("network:request:unrestricted") &&
    		!capabilities.includes("network:request")
    	) {
    		capabilities.push("network:request");
    	}
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 20, 2026
@github-actions github-actions Bot added the review/awaiting-author Reviewed; waiting on the author to respond label Sep 20, 2026

@emdashbot emdashbot 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.

I re-reviewed PR #3190 after the prior blocking finding on packages/core/src/plugins/adapt-sandbox-entry.ts. That issue is resolved: adaptSandboxEntry now uses the canonical normalizePluginCapabilities from packages/core/src/plugins/types.ts, and the regression tests cover taxonomies:write and redirects:write implication expansion.

The remaining problem is that the rest of the codebase still performs partial, hard-coded capability implication expansion instead of using the canonical normalizePluginCapabilities helper. The canonical implication table (PLUGIN_CAPABILITY_IMPLICATIONS in packages/core/src/plugins/types.ts) includes:

  • content:write → content:read
  • content:revisions:read → content:read
  • taxonomies:write → taxonomies:read
  • content:publish → content:read
  • media:write → media:read
  • comments:moderate → comments:read
  • redirects:write → redirects:read
  • network:request:unrestricted → network:request

But:

  1. packages/core/src/emdash-runtime.ts (loadSandboxedPlugins, line ~2505) still calls normalizeCapabilities (alias-only) and then manually re-implements a subset of implications, omitting taxonomies:write, redirects:write, and content:revisions:read.
  2. Both sandbox wrappers (packages/cloudflare/src/sandbox/wrapper.ts and packages/workerd/src/sandbox/wrapper.ts) still call normalizeCapabilities and only add the comments:moderate → comments:read implication. Because the Cloudflare/workerd wrappers gate the entire redirects context on hasRedirectRead, declaring only redirects:write produces redirects: undefined in the generated wrapper — effectively stripping write access that the admin consented to.
  3. The canonical helper is not exported from packages/core/src/plugins/index.ts or packages/core/src/index.ts, so the wrappers cannot currently import it via the emdash package alias.
  4. Test coverage only exercises the deprecation/alias layer (CAPABILITY_RENAMES) in packages/core/tests/unit/plugins/capability-normalization.test.ts; the implication rules have no unit tests.

Other notes:

  • packages/core/src/api/handlers/marketplace.ts intentionally uses alias-only normalizeCapabilities to compare declared capability additions/removals after manifest renames. That is correct for escalation diffing and is not flagged.
  • The admin CapabilityConsentDialog, route-visibility acknowledgement, registry install/update, and plugin API dispatch all look reasonable on inspection.

I recommend fixing the capability normalization inconsistency before merging: migrate the runtime and both wrappers to normalizePluginCapabilities, re-export it from the public entrypoints, and add unit tests for the implication table.


Findings

  • [needs fixing] packages/core/src/emdash-runtime.ts:2505-2520

    loadSandboxedPlugins uses alias-only normalizeCapabilities and then re-implements a partial, hard-coded implication list. It adds content:write/publish → content:read, media:write → media:read, and network:request:unrestricted → network:request, but it omits the canonical implications for taxonomies:write, redirects:write, and content:revisions:read.

    This means sandboxed plugins that declare only taxonomies:write, redirects:write, or content:revisions:read will not receive the implied read capability at runtime, even though packages/core/src/plugins/types.ts says they should.

    				const capabilities = normalizePluginCapabilities(entry.capabilities ?? []);
    

    Remove the subsequent capabilities.push(...) blocks entirely and rely on normalizePluginCapabilities from ../plugins/types.js.

  • [needs fixing] packages/cloudflare/src/sandbox/wrapper.ts:44-47

    The generated wrapper uses alias-only normalizeCapabilities and then hard-codes a single implication (comments:moderate → comments:read). It misses the canonical implications, which directly breaks redirects:write: later in the same template the redirects context object is only emitted when hasRedirectRead is true. If a manifest declares only redirects:write, redirects becomes undefined in the sandbox despite the admin consenting to write access.

    	const capabilities = normalizePluginCapabilities(manifest.capabilities ?? []);
    

    Remove the manual comments:moderate push. normalizePluginCapabilities can be imported from emdash once it is re-exported from packages/core/src/plugins/index.ts.

  • [needs fixing] packages/workerd/src/sandbox/wrapper.ts:83-86

    Same issue as the Cloudflare wrapper: the workerd wrapper uses alias-only normalizeCapabilities and only adds the comments:moderate → comments:read implication. It also gates the generated redirects context on hasRedirectRead, so declaring only redirects:write yields no redirect API in the sandbox.

    	const capabilities = normalizePluginCapabilities(manifest.capabilities ?? []);
    

    Drop the manual implication push and import the canonical helper from emdash once it is exported.

  • [suggestion] packages/core/src/plugins/index.ts:318

    The public plugin index exports alias normalization helpers (CAPABILITY_RENAMES, isDeprecatedCapability, normalizeCapability, normalizeCapabilities) but does not export normalizePluginCapabilities. The sandbox wrappers in @emdash-cms/cloudflare and @emdash-cms/workerd need that helper to apply canonical implications.

    export {
    	CAPABILITY_RENAMES,
    	isDeprecatedCapability,
    	normalizeCapability,
    	normalizeCapabilities,
    	normalizePluginCapabilities,
    } from "./types.js";
    
  • [suggestion] packages/core/src/index.ts:455

    The top-level emdash package re-export only exposes the alias normalization layer. Once the helper is added to packages/core/src/plugins/index.ts, it should also be re-exported here so platform adapters can import normalizePluginCapabilities from the public emdash surface.

  • [suggestion] packages/core/tests/unit/plugins/capability-normalization.test.ts:16-21

    The test file imports and exercises only the deprecation alias map (CAPABILITY_RENAMES, normalizeCapability, normalizeCapabilities). There are no tests for the canonical implication rules in PLUGIN_CAPABILITY_IMPLICATIONS / normalizePluginCapabilities.

    Add a describe("normalizePluginCapabilities") block that asserts, for example:

    • content:revisions:read implies content:read
    • taxonomies:write implies taxonomies:read
    • redirects:write implies redirects:read
    • comments:moderate implies comments:read
    • network:request:unrestricted implies network:request

    This would prevent future drift between the canonical table and the runtime/wrapper implementations.

@emdashbot emdashbot 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.

Re-reviewed PR #3190 after the prior emdashbot[bot] blocking findings. All of the originally-flagged capability-normalization gaps are resolved: adaptSandboxEntry, loadSandboxedPlugins, the Cloudflare and workerd sandbox wrappers, and the public emdash re-exports now route through the canonical normalizePluginCapabilities helper, and new tests cover alias→canonical expansion plus capability implication expansion.

The raw-routes feature itself is solid:

  • Route contracts, request parsing (none/json/text/bytes/form-data), response wire serialization, method enforcement, same-origin redirect gating, active-content-type rejection, and CSP-framing defaults are all in place.
  • HTTP dispatch, the Astro catch-all, marketplace/registry install/update consent, the admin consent UI, and the test helpers (rawBody, acknowledged public-route fixtures) look coherent and well covered.

I did find two remaining partial-normalization boundaries that should still be brought in line with the canonical helper: packages/cloudflare/src/sandbox/runner.ts and packages/workerd/src/sandbox/bridge-handler.ts still use the alias-only normalizeCapabilities plus a hard-coded comments:moderate → comments:read fallback. They miss every other implication rule (redirects:write→redirects:read, taxonomies:write→taxonomies:read, etc.). Because the manifest is normalized upstream by core this is mostly masked today, but it is a live correctness/convention gap if the runner/bridge is ever given a non-canonical capability list, and it undermines the normalization cleanup the previous review round required.


Findings

  • [needs fixing] packages/cloudflare/src/sandbox/runner.ts:353-356

    This site only aliases legacy names and then hard-codes the comments:moderate → comments:read implication. It ignores every other capability implication (redirects:write→redirects:read, taxonomies:write→taxonomies:read, content:publish/write→content:read, etc.) that normalizePluginCapabilities now centralizes. It also duplicates the exact pattern the previous review round was asked to eliminate.

    Switch to the canonical helper so the Cloudflare bridge receives the same capability set as every other boundary:

    import {
    	...
    	normalizePluginCapabilities,
    	...
    } from "emdash";
    
    		const capabilities = normalizePluginCapabilities(this.manifest.capabilities || []);
    
  • [needs fixing] packages/workerd/src/sandbox/bridge-handler.ts:232-235

    Same issue as the Cloudflare runner: the bridge handler only aliases legacy names and manually injects comments:read when comments:moderate is present. It should use normalizePluginCapabilities so capability implication is performed once, consistently, for all sandbox backends.

    import {
    	...
    	normalizePluginCapabilities,
    	...
    } from "emdash";
    
    	const capabilities = normalizePluginCapabilities(opts.capabilities);
    

    After fixing, consider adding a small unit test for each backend that passes a manifest containing only the implying capabilities (e.g. redirects:write, taxonomies:write) and confirms the bridge/context exposes the implied read access.

@emdashbot emdashbot 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.

I re-reviewed the whole PR after the two earlier normalizeCapabilities fixes were applied. The functional/security changes for raw plugin routes are sound: both packages/cloudflare/src/sandbox/runner.ts and packages/workerd/src/sandbox/bridge-handler.ts now import normalizePluginCapabilities from emdash, raw request parsing and response serialization in route-wire.ts correctly enforce body modes, header allow/block lists, byte limits, CSP/nosniff/referrer headers, same-origin redirects, and HEAD/null-body handling; dispatch flow in http-route-dispatch.ts, the Astro plugin API route, and emdash-runtime.ts is coherent; and the consent/marketplace path uses the alias-only normalizeCapabilities in a way that does not create false escalations.

However, two repo-convention items remain and must be addressed before merging:

  1. Missing changeset for a changed published package. packages/cloudflare/src/sandbox/runner.ts and packages/cloudflare/src/sandbox/wrapper.ts were modified, but @emdash-cms/cloudflare is absent from .changeset/raw-plugin-routes.md.
  2. AGENTS.md comment-convention violations. Several source files in this PR still contain GitHub issue/PR references (#1293, #1370, #2079, #2146) in comments; AGENTS.md disallows issue references in code comments because they are not useful to future readers.

Once the changeset is updated and the issue-number references are removed or rephrased as plain prose, this PR is good to go from a technical and security standpoint.


Findings

  • [needs fixing] .changeset/raw-plugin-routes.md:7

    @emdash-cms/cloudflare is a published non-private package whose runtime files (packages/cloudflare/src/sandbox/runner.ts and packages/cloudflare/src/sandbox/wrapper.ts) are changed by this PR, but it is missing from this changeset. Add it so the release notes and version bump cover the updated runtime.

    "@emdash-cms/cloudflare": minor
    

    (Insert after the existing @emdash-cms/sandbox-workerd line.)

  • [needs fixing] packages/core/src/plugins/routes.ts:32

    AGENTS.md: comments are for code readers, not issue/PR references. Remove the GitHub issue number and keep the explanation in prose.

     * actionable message that points the caller to `ctx.input` instead.
    
  • [needs fixing] packages/core/src/plugins/routes.ts:125

    GitHub issue reference in a code comment. Rephrase without the number.

     * methods (GET/HEAD/DELETE) have no body, so `request.json()` resolves to
     * undefined and fails schema validation — parse the query string into
    
  • [needs fixing] packages/core/src/plugins/routes.ts:269

    GitHub issue reference in an inline comment. Remove it while keeping the rationale.

    			// body-reading methods so a re-read fails with an actionable message.
    
  • [needs fixing] packages/core/src/plugins/adapt-sandbox-entry.ts:212

    GitHub issue reference in a code comment. Drop the number.

    		// undefined at runtime.
    
  • [needs fixing] packages/core/src/plugins/define-plugin.ts:112

    GitHub issue reference in a comment. Keep the explanation, remove the number.

    	// literals are parsed, so the temporal dead zone cannot occur regardless of
    	// bundle ordering.
    
  • [needs fixing] packages/core/src/plugins/define-plugin.ts:113

    GitHub issue reference in an oxlint disable reason. Use plain prose.

    	// oxlint-disable-next-line e18e/prefer-static-regex -- call-time on purpose (avoid temporal dead zone on Cloudflare Workers)
    
  • [needs fixing] packages/core/src/plugins/define-plugin.ts:115

    Same issue-reference convention violation.

    	// oxlint-disable-next-line e18e/prefer-static-regex -- call-time on purpose (avoid temporal dead zone on Cloudflare Workers)
    
  • [needs fixing] packages/core/src/plugins/define-plugin.ts:117

    Same issue-reference convention violation.

    	// oxlint-disable-next-line e18e/prefer-static-regex -- call-time on purpose (avoid temporal dead zone on Cloudflare Workers)
    
  • [suggestion] packages/core/tests/unit/plugins/capability-normalization.test.ts:11

    The @see Issue: "..." JSDoc line is also issue referencing. In tests this is lower stakes, but converting it to a plain descriptive sentence keeps the file consistent with AGENTS.md.

@emdashbot emdashbot 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.

This is a re-review of #3190 after the author addressed the two repo-convention blockers from the previous pass.

What I checked:

  • Prior blockers resolved: .changeset/raw-plugin-routes.md now includes "@emdash-cms/cloudflare": minor, so the modified Cloudflare runtime files (packages/cloudflare/src/sandbox/runner.ts and wrapper.ts) are covered. I searched all changed authored files for GitHub issue/PR references in comments; the source comments that previously contained #1293, #1370, #2079, and #2146 have been rephrased or removed, and no new issue references are introduced in changed code. The remaining references in pre-existing test titles are unchanged context lines, not new additions.
  • Functional/security sweep: I re-read route-wire.ts, http-route-dispatch.ts, request-meta.ts, routes.ts, define-plugin.ts, adapt-sandbox-entry.ts, the Astro plugin API route, and the admin consent components. The bounded body parsing (none/json/text/bytes/form-data), header allow/block lists, raw-response allowlist, method enforcement with 405/Allow, same-origin redirect guard, and host-owned CSP/nosniff/referrer-policy behavior all line up with the PR description and the security notes in the description.
  • Documentation: The changeset is accurate, user-facing, and lists every affected published package. Admin UI strings remain Lingui-wrapped, and the consent dialog presents the exact public route names as claimed.

No remaining blocking issues. The PR is good to go.

@emdashbot emdashbot 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.

This is the right change for the stated goal: it adds bounded, declared request/raw-response contracts for plugin routes while keeping the legacy JSON/query path intact. The approach threads route metadata through manifests, generated descriptors, both transports, and the admin consent UI, and the security boundaries (method enforcement, header allow/block lists, raw-response allowlist, active-content rejection, exact public-route consent, host-owned cache/security headers) line up with the PR description.

I re-read the prior review context and the current diff. The two previous repo-convention blockers are resolved:

  • .changeset/raw-plugin-routes.md now includes "@emdash-cms/cloudflare": minor.
  • No new source-code comments reference GitHub issues/PRs; the former #1293, #1370, #2079, and #2146 citations have been removed.

I traced the request parser, raw-response wire, dispatch path, method enforcement, header sanitization, install/update consent flow, and both sandbox transports. The implementation is consistent and well-covered by tests. I found one small documentation omission: the @emdash-cms/plugin-cli entry reduces the screenshot cap from 8 to 5 by switching MAX_SCREENSHOTS to the shared PLUGIN_BUNDLE_MAX_SCREENSHOTS constant, but the changeset never mentions the new limit. A changelog-only note will help plugin authors understand the release impact.

Overall this looks ready to merge after that changeset note is added.

Routes with `response: "raw"` return `pluginResponse()` with an unwrapped text or byte body, status,
and allowlisted representation, download, or redirect headers. Raw responses are limited to 8 MiB.
The host removes all other plugin-supplied headers, applies the route's cache and browser security
policy, and rejects active same-origin content types.

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.

[suggestion] The @emdash-cms/plugin-cli entry also changes MAX_SCREENSHOTS from 8 to 5 by switching it to PLUGIN_BUNDLE_MAX_SCREENSHOTS, which affects plugin authors preparing publish bundles. The changeset currently only talks about route contracts, so readers of the plugin-cli CHANGELOG won't realize the screenshot cap is changing.

Suggested change
policy, and rejects active same-origin content types.
+, and `@emdash-cms/plugin-cli` now enforces the shared bundle limit of 5 screenshots per plugin.

@emdashbot emdashbot 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.

This is still the right change for the stated goal: it threads bounded, declared request/raw-response contracts for plugin routes through the runtime, both transports, the CLI, and the admin consent UI, while keeping the legacy JSON/query path intact. I re-checked the two items from the previous review: the changeset now includes "@emdash-cms/cloudflare": minor, and no new source-code comments reference GitHub issues/PRs. The prior screenshot-cap changeset note no longer applies to this branch, because packages/plugin-cli/src/bundle/utils.ts still defines MAX_SCREENSHOTS = 8 and there is no PLUGIN_BUNDLE_MAX_SCREENSHOTS constant in the tree.

I traced the request parser (parseDeclaredPluginRouteInput), raw-response wire (pluginRouteResponseToWire/FromWire), dispatch path, method enforcement, header sanitization, install/update consent flow, and both the Cloudflare Worker Loader and Node/workerd transports. The implementation is consistent across all three runtimes and well-covered by tests. No security boundary gaps jumped out: credentials/CSRF/CF-Access headers are stripped, response headers are allowlisted with host-owned cache/security policies, active same-origin content types are rejected, and public route consent is computed from the downloaded/verified bundle.

One small suggestion: the changeset lists @emdash-cms/plugin-cli as a minor bump, but the prose only describes runtime features. Because plugin-cli now enforces new bundle-time validation (Block Kit admin routes must be private POST-compatible JSON routes, and MCP tools cannot reference public or raw-response routes), plugin authors would benefit from a short note about that.

Comment on lines +23 to +27

`pluginRoute()` infers a sandboxed handler's input from its declared body mode.
`definePluginRoute()` provides the equivalent inference for trusted native routes.
`createPluginRuntimeTestHost()` accepts `rawBody` for testing the production request parser with
text, bytes, URL-encoded data, and multipart form data.

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.

[suggestion] The changeset lists @emdash-cms/plugin-cli as a minor bump, but the prose only covers runtime behavior. Plugin authors using the CLI will hit new bundle-time validation now that extractManifest rejects Block Kit admin routes that are public, raw-response, or non-JSON and rejects MCP tools that reference public or raw routes. Add a short note so the CHANGELOG explains the release impact for that package.

Suggested change
`pluginRoute()` infers a sandboxed handler's input from its declared body mode.
`definePluginRoute()` provides the equivalent inference for trusted native routes.
`createPluginRuntimeTestHost()` accepts `rawBody` for testing the production request parser with
text, bytes, URL-encoded data, and multipart form data.
#### `@emdash-cms/plugin-cli`
`bundle` and `publish` now validate that Block Kit admin routes are private POST-compatible JSON routes and that MCP tools cannot reference public or raw-response routes. Update any plugin whose manifest currently violates these rules before republishing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant