Skip to content

Postgres World: deliver workflow messages in-process and deny the flow route (remove the HTTP loopback) #5258

Open

Description

@pranaygp

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, Nitro node-cluster) round-robins the loopback to a sibling process;
  • a separate worker tier posts to a different host.

Plan

  1. 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/vitest already does. Details to settle:
    • running the handler outside the framework's request pipeline (request-scoped context, waitUntil, env);
    • the dev-server reload path.
  2. 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 deliverMessage for the SDK prefix.
  3. 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 through workflowEntrypoint, 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.
  4. world-postgres owns its queue handler. Today it builds a whole world-local World (createWorld({ dataDir: undefined, port })) only to call createQueueHandler: 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-local dependency. Keep the per-run lock: it serializes one run's orchestrator deliveries in the receiving process, matching how Postgres serializes a run through Graphile.
  5. 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-at headers, copied from Vercel Queues. world-vercel doesn't use these headers, and the public World docs only describe the handler's meta (messageId, attempt, deliveryCount, createdAt), not the wire format.

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

  1. MickL commented on Nov 12, 2026

    @MickL

    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 :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions