Skip to content

SvelteKit is removing csrf.checkOrigin — migrate cairn admin CSRF #44

Description

@glw907

Evidence

csrf.checkOrigin has been concretely removed in SvelteKit 3, currently in pre-release:

cairn's current usage

cairn depends on checkOrigin: false in svelte.config.js as a hard precondition for its admin CSRF subsystem. Key files:

File Line Role
src/lib/sveltekit/csrf.ts 1 Top-level comment: "cairn owns CSRF for the admin once a site disables SvelteKit's global checkOrigin"
src/lib/sveltekit/guard.ts 106 Comment: "they set checkOrigin: false to hand cairn the admin CSRF authority"
src/lib/doctor/checks-local.ts 67, 74, 104, 112 Doctor check that asserts checkOrigin: false is present in svelte.config.js or vite.config.ts
src/tests/unit/doctor-checks-local.test.ts 58, 318, 329 Unit tests for the above doctor check

Current peer/dev range: ^2.70 (stable 2.70.3).

Impact

When consumer sites upgrade to SvelteKit 3, csrf: { checkOrigin: false } will be silently ignored or will fail to compile, breaking all admin POST flows. The doctor check will also fire on a setting that no longer exists.

trustedOrigins cannot replace checkOrigin: false for cairn's case: the !request_origin clause in SvelteKit's CSRF guard forbids missing-Origin POSTs regardless of trustedOrigins, and privacy-hardened browsers routinely omit the Origin header on same-site navigations.

Planned fallback

The planned migration path (documented in ROADMAP.md under "Migrate cairn's CSRF-disable before SvelteKit removes checkOrigin" and docs/cairn-dx-feedback-2026-06-09-907-0.36-retrofit.md) is:

A Cloudflare Transform Rule that injects an Origin header for /admin POSTs at the edge, before SvelteKit's CSRF guard runs. This lets cairn configure trustedOrigins: ['self'] (or the site's own origin) instead of disabling the check globally, and means the guard always sees an Origin it can evaluate.

The higher-leverage path remains getting upstream to provide a hook that runs before the CSRF check (so cairn can short-circuit it for requests it has already validated), but the Transform Rule is the pragmatic zero-new-dependency fallback.

What needs to happen before SvelteKit 3 stable ships

  • Implement the Cloudflare Transform Rule approach and document it for consumer sites
  • Remove the checkOrigin: false doctor check (or convert it to flag the old pattern as deprecated)
  • Update the getting-started scaffold so new sites use trustedOrigins instead of checkOrigin: false
  • Update docs/guides/restrict-admin-access.md and any other docs referencing checkOrigin
  • Close the ROADMAP watch item

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions