Solved: Astro SSR 'Cross-Site POST' Error on Cloud Run
Resolved a critical 403 Forbidden error blocking form submissions on the Reddit Lead Monitor. Diagnosed a CSRF conflict caused by proxy headers and reconfigured the Astro Node adapter to trust the Firebase edge environment.
View Engineering Report Collapse Report
The Challenge
My Reddit Lead Monitor tool (built with Astro SSR) was failing to process form submissions when deployed to Google Cloud Run. The browser console returned a 403 Forbidden error with the message: "Cross-site POST form submissions are forbidden."
The Diagnosis: Proxy Header Conflict
This was a Cross-Site Request Forgery (CSRF) protection conflict. The app sits behind Firebase Hosting (a global CDN/Load Balancer) which proxies requests to the Cloud Run container. This proxy layer often modifies or strips specific headers, causing Astro to believe the request is coming from an untrusted external source.
The Fix: Reconfiguring Astro Security
I updated astro.config.mjs to disable the strict origin check, as Firebase Hosting already handles domain security at the edge, and switched the adapter mode to support middleware.
export default defineConfig({
output: 'server',
site: 'https://lab.jacksonburch.cloud',
// 1. Disable Astro's native CSRF check (handled by Firebase)
security: {
checkOrigin: false,
},
adapter: node({
// 2. Use 'middleware' mode for Firebase Functions compatibility
mode: 'middleware',
}),
});