Skip to content

Commit d052811

Browse files
committed
chore: add casing check
1 parent 90c4284 commit d052811

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/astro/src/core/app/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class App {
164164
const { request, url } = context;
165165
const contentType = request.headers.get('content-type');
166166
if (contentType) {
167-
if (this.#formContentTypes.includes(contentType)) {
167+
if (this.#formContentTypes.includes(contentType.toLowerCase())) {
168168
const forbidden =
169169
(request.method === 'POST' ||
170170
request.method === 'PUT' ||

packages/astro/test/csrf-protection.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ describe('CSRF origin check', () => {
2525
response = await app.render(request);
2626
assert.equal(response.status, 403);
2727

28+
// case where content-type has different casing
29+
request = new Request('http://example.com/api/', {
30+
headers: { origin: 'http://loreum.com', 'content-type': 'MULTIPART/FORM-DATA' },
31+
method: 'POST',
32+
});
33+
response = await app.render(request);
34+
assert.equal(response.status, 403);
35+
2836
request = new Request('http://example.com/api/', {
2937
headers: { origin: 'http://loreum.com', 'content-type': 'application/x-www-form-urlencoded' },
3038
method: 'POST',

0 commit comments

Comments
 (0)