Repository navigation
Description
Summary
world-postgres delivers every Workflow SDK message over an HTTP loopback: the Graphile worker that locks a job POSTs it to the app's own POST /.well-known/workflow/v1/flow. That route is mounted like any other app route, so it is reachable from outside. In #5179, world-postgres declares queueAuth: 'skip' (unchecked, as on main), so the route accepts any well-formed request. Anyone who can reach it can start a run, fail a running one by claiming a high x-vqs-message-attempt, re-trigger a step, or replay a delivery.
Skip is no worse than today, but it needs fixing soon. The plan: deliver in-process, then refuse the flow route outright. There is then no key to manage and no cross-process or cluster-mode edge cases.
Why the loopback exists today
deliverMessage in packages/world-postgres/src/queue.ts has two paths:
worker locks job → deliverMessage()
├─ directHandlers.get(prefix)? only if someone called world.registerHandler()
└─ else POST http://localhost:PORT (or WORKFLOW_LOCAL_BASE_URL)/.well-known/workflow/v1/flow
@workflow/core never registers the SDK's own flow handler in-process. Only the vitest plugin does, by importing the compiled bundle directly (world.registerHandler('__wkf_workflow_', createLazyHandler('combined.mjs'))). In a framework app, the compiled flow handler is a framework route module: in Next.js it sits in the app-route module graph and loads lazily on first request. The worker, started from instrumentation or a plugin, has no portable way to import it, so it reaches the handler over HTTP.
The loopback is also behind the edge cases that rule out a per-process key on Postgres. Postgres is pull-based, so the worker that delivers a job may run in a different process from the route it posts to:
- a script or cron job calling
start()also starts a worker; - cluster mode (PM2
-i N,node:cluster, Nitronode-cluster) round-robins the loopback to a sibling process; - a separate worker tier posts to a different host.
Plan
- Register the compiled flow handler in-process at boot. Each framework integration (next, nitro/nuxt, sveltekit, vite, astro, express/hono/fastify/nest via nitro, …) loads the compiled flow bundle when the app starts and registers it with the World. This generalizes what
@workflow/vitestalready does. Details to settle:- running the handler outside the framework's request pipeline (request-scoped context,
waitUntil, env); - the dev-server reload path.
- running the handler outside the framework's request pipeline (request-scoped context,
- world-postgres delivers only in-process. A worker runs only in a process that has the handler registered. This also fixes the "script starts a worker and takes the app's jobs" problem by construction. Drop the HTTP branch of
deliverMessagefor the SDK prefix. - Deny the flow route. Add a mode that refuses every request reaching the flow route over HTTP (name TBD, e.g.
'deny'). In-process deliveries still pass throughworkflowEntrypoint, so define precisely what an in-process delivery has to present: e.g. it is accepted only via the registered-handler path, or it carries the process key. world-postgres switches from'skip'to it. - world-postgres owns its queue handler. Today it builds a whole world-local World (
createWorld({ dataDir: undefined, port })) only to callcreateQueueHandler: a second queue, plus storage and streamer objects pointed at world-local's default data directory, and world-local's maximum-visibility clamp applied to Postgres. Replace it with a Postgres-owned handler and drop the@workflow/world-localdependency. Keep the per-run lock: it serializes one run's orchestrator deliveries in the receiving process, matching how Postgres serializes a run through Graphile. - Drop the VQS wire shape for self-hosted Worlds. world-local, world-postgres and world-sim pass delivery metadata as
x-vqs-queue-name/-message-id/-message-attempt/-message-delivery-count/-message-created-atheaders, copied from Vercel Queues. world-vercel doesn't use these headers, and the public World docs only describe the handler'smeta(messageId,attempt,deliveryCount,createdAt), not the wire format.- Once deliveries are in-process, each World can pass
metato the handler directly, or use whatever private shape it prefers. - The delivery count then can't be forged through a request header at all.
- world-local keeps its loopback (it is authenticated by the loopback key from Authenticate flow-route queue deliveries on the Local World (Stage 1: shared key file) #5179) and can choose its own shape too.
- Once deliveries are in-process, each World can pass
Done when
- world-postgres delivers SDK messages without HTTP in every supported framework, and its flow route refuses external requests.
- The Postgres docs' Security section describes the route as closed rather than "protect it at the network edge".
- world-postgres no longer depends on
@workflow/world-local. - The x-vqs header shape is gone from world-local, world-postgres and world-sim (or kept only where a World still needs a wire format, under its own names).
- Tests:
- a forged request to the Postgres flow route is refused;
- a script calling
start()doesn't start a worker that delivers; - cluster mode delivers every message.
Context: discussed in the review of #5179 (Stage 1, the Local World loopback key).
Activity
Describe the shared queue auth key in docs, comments and changesets
Authenticate flow-route queue deliveries on the Local World (Stage 1:…
MickL commentedon Nov 12, 2026
Workflow seems so cool but this is SO annoying: My Nitro Node/Bun app is running and then calls itself through http instead of just calling the function directly... also a possible security risk to have an open http handler that can execute functions...
Happy to see a PR already :)