Skip to content

Commit

Permalink
chore: add casing check
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Apr 8, 2024
1 parent 90c4284 commit f5bfa5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ export class App {
return defineMiddleware((context, next) => {
const { request, url } = context;
const contentType = request.headers.get('content-type');
console.log(contentType);
if (contentType) {
if (this.#formContentTypes.includes(contentType)) {
if (this.#formContentTypes.includes(contentType.toLowerCase())) {
const forbidden =
(request.method === 'POST' ||
request.method === 'PUT' ||
Expand Down
8 changes: 8 additions & 0 deletions packages/astro/test/csrf-protection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ describe('CSRF origin check', () => {
response = await app.render(request);
assert.equal(response.status, 403);

// case where content-type has different casing
request = new Request('http://example.com/api/', {
headers: { origin: 'http://loreum.com', 'content-type': 'MULTIPART/FORM-DATA' },
method: 'POST',
});
response = await app.render(request);
assert.equal(response.status, 403);

request = new Request('http://example.com/api/', {
headers: { origin: 'http://loreum.com', 'content-type': 'application/x-www-form-urlencoded' },
method: 'POST',
Expand Down

0 comments on commit f5bfa5b

Please sign in to comment.