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
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/four-cougars-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': major
---

Allows HEAD requests to return a 200 response
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" || request.method === "OPTIONS") {
return next();
}
const sameOrigin =
Expand Down
11 changes: 11 additions & 0 deletions packages/astro/test/csrf-protection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,15 @@ describe('CSRF origin check', () => {
something: 'true',
});
});

it('return 200 when calling HEAD', async () => {
let request;
let response;
request = new Request('http://example.com/', {
headers: { origin: 'http://loreum.com', 'content-type': 'multipart/form-data' },
method: 'HEAD',
});
response = await app.render(request);
assert.equal(response.status, 200);
})
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Astro</title>
</head>
<body>
<h1>Astro</h1>
</body>
</html>