Skip to content

Commit f5bfa5b

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

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ export class App {
163163
return defineMiddleware((context, next) => {
164164
const { request, url } = context;
165165
const contentType = request.headers.get('content-type');
166+
console.log(contentType);
166167
if (contentType) {
167-
if (this.#formContentTypes.includes(contentType)) {
168+
if (this.#formContentTypes.includes(contentType.toLowerCase())) {
168169
const forbidden =
169170
(request.method === 'POST' ||
170171
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)