Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows head requests to return 200 instead of 403 #13100

Closed
wants to merge 5 commits into from

Conversation

joshmkennedy
Copy link

Changes

  • What does this change?

fixes this issue #13079 by checking if the request method is "HEAD" it allows it to continue with the middleware and not return a 403

I don't believe the docs should need to be updated

Copy link

changeset-bot bot commented Jan 30, 2025

🦋 Changeset detected

Latest commit: 6e926f5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 30, 2025
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Please create a test and a changeset

Copy link

codspeed-hq bot commented Jan 30, 2025

CodSpeed Performance Report

Merging #13100 will not alter performance

Comparing joshmkennedy:fix-head-method-403 (6e926f5) with main (23e631c)

Summary

✅ 6 untouched benchmarks

@@ -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

@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
Author

Choose a reason for hiding this comment

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

👍

@github-actions github-actions bot added the semver: major Change triggers a `major` release label Jan 31, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

@joshmkennedy
Copy link
Author

I believe may @corneliusroemer may have a better solution here #13101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) semver: major Change triggers a `major` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants