Skip to content

fix(auth): accept the deployment's own domain in the CSRF allowlist - #894

Merged
Ardnived merged 1 commit into
mainfrom
claude/fix-preview-csrf
Oct 7, 2026
Merged

Ardnived merged 1 commit into
mainfrom
claude/fix-preview-csrf

Conversation

@Ardnived

@Ardnived Ardnived commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Previews refused every admin write. A Railway PR preview inherits production's SAHAJCLOUD_URL, so Payload's csrf allowlist held only https://cloud.sydevelopers.com.
    • Every request the admin makes from a preview carries the preview's own Origin, so Payload ignored the session cookie.
    • Each write — an upload, a save — then answered 403 "You are not allowed to perform this action." as if the caller were anonymous.
    • Page loads kept working, because they send no Origin.
  • The fix: ownOrigins() adds https://$RAILWAY_PUBLIC_DOMAIN, the domain the deployment is actually served on, beside the server URL.

Evidence

On the PR #874 preview:

  • Railway's HTTP logs show POST /api/event-imports/upload 403 and GET /api/payload-preferences/nav 403 for a signed-in preview admin.
  • The 403 body is requireActiveManager's, which answers that when req.user is null.
  • Payload's extractJWT drops a cookie token whose Origin is not in config.csrf.

Why it is safe

  • The added origin is the deployment's own domain. Railway serves that hostname only for this service, so it adds nobody new to trust.
  • In production the list keeps SAHAJCLOUD_URL. It gains Railway's domain for the same service only if that differs.

Test results

  • pnpm lint on the changed files, pnpm typecheck, pnpm typecheck:tests: pass.
  • pnpm test:unit: 172 files, 2,279 tests pass.
  • New tests/unit/server-url.spec.ts covers a preview's domain being added, a duplicate collapsing, and no Railway domain at all.

🤖 Generated with Claude Code

A Railway PR preview inherits production's SAHAJCLOUD_URL, so Payload's csrf
list held only cloud.sydevelopers.com. Every admin request from the preview
carries the preview's Origin, so the session cookie was ignored and each write
answered 403 as an anonymous caller, while page loads (no Origin) worked.
ownOrigins() adds https://$RAILWAY_PUBLIC_DOMAIN beside the server URL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-894 October 7, 2026 23:19 Destroyed
@railway-app

railway-app Bot commented Oct 7, 2026

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-894 environment in sahajcloud

Service Status Web Updated
SahajCloud 🕒 Building (View Logs) Web Oct 7, 2026 at 11:19 pm UTC
1 service not affected by this PR
  • mailpit

@Ardnived
Ardnived merged commit 9124e02 into main Oct 7, 2026
6 of 7 checks passed
@Ardnived
Ardnived deleted the claude/fix-preview-csrf branch October 7, 2026 23:19

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-894 — b160f8e0 Deployed Oct 7, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant