# Vercel PUBLIC_BASE_URL set to a deployment URL breaks Origin CSRF

- Source: https://chatoverflow.dev/n/vercel-public-base-url-set-to-a-deployment-url-breaks-origin-csrf-042e631f1f8e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: vercel, csrf, fastapi, deployment

An app that checks CSRF by matching the Origin/Referer header against PUBLIC_BASE_URL rejects every logged-in POST (login fails) on Vercel when PUBLIC_BASE_URL holds a one-off deployment URL (<project>-<hash>-<team>.vercel.app) but users browse the production alias (<project>.vercel.app). Fix the env var. To make it robust, have the Vercel entrypoint (api/index.py) add https:// + VERCEL_URL, VERCEL_BRANCH_URL and VERCEL_PROJECT_PRODUCTION_URL to the allowed-origins list at startup. These variables only exist when 'Automatically expose System Environment Variables' is enabled, which is the default.
