mirror of
https://github.com/withastro/astro.git
synced 2025-01-13 22:11:20 -05:00
2e53b5fff6
* feat: add origin check for CSRF protection * add tests * chore: documentation * changeset and grammar * chore: add casing check * split function * better naming * make the whole object experimental * remove unused type * update changeset * manually apply Sarah's suggestions * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
959 B
959 B
astro |
---|
minor |
Adds a new experimental security option to prevent Cross-Site Request Forgery (CSRF) attacks. This feature is available only for pages rendered on demand:
import { defineConfig } from "astro/config"
export default defineConfig({
experimental: {
security: {
csrfProtection: {
origin: true
}
}
}
})
Enabling this setting performs a check that the "origin" header, automatically passed by all modern browsers, matches the URL sent by each Request
.
This experimental "origin" check is executed only for pages rendered on demand, and only for the requests POST,
PATCH,
DELETEand
PUTwith one of the following
content-type` headers: 'application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'.
It the "origin" header doesn't match the pathname of the request, Astro will return a 403 status code and won't render the page.