Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createOriginCheckMiddleware(): MiddlewareHandler {
if (isPrerendered) {
return next();
}
if (request.method === 'GET') {
if (request.method === 'GET' || request.method === "HEAD") {
Copy link
Contributor

@corneliusroemer corneliusroemer Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (request.method === 'GET' || request.method === "HEAD") {
if (request.method === 'GET' || request.method === 'HEAD' || request.method === 'OPTIONS' || request.method === 'TRACE') {

There are 2 more safe request methods that should be added as exemptions besides GET and HEAD: OPTIONS and TRACE.

Maybe one should add centralized functions to define safe and unsafe functions/properties on request? So one can do:

if (request.isSafe) { ... }

and reduce scope for making the same mistake in multiple places?

See source for definition of safe methods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods#safe_idempotent_and_cacheable_request_methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return next();
}
const sameOrigin =
Expand Down