Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored and astrobot-houston committed Dec 2, 2024
1 parent 315c5f3 commit 10c6b8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions 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') {
return next();
}
const sameOrigin =
Expand All @@ -34,8 +34,8 @@ export function createOriginCheckMiddleware(): MiddlewareHandler {
request.method === 'PATCH' ||
request.method === 'DELETE') &&
request.headers.get('origin') === url.origin;
const hasContentType = request.headers.has('content-type')

const hasContentType = request.headers.has('content-type');
if (hasContentType) {
const formLikeHeader = hasFormLikeHeader(request.headers.get('content-type'));
if (formLikeHeader && !sameOrigin) {
Expand All @@ -51,7 +51,7 @@ export function createOriginCheckMiddleware(): MiddlewareHandler {
}
}

return next()
return next();
});
}

Expand Down
9 changes: 6 additions & 3 deletions packages/astro/test/csrf-protection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ describe('CSRF origin check', () => {
assert.equal(response.status, 403);

request = new Request('http://example.com/api/', {
headers: { origin: 'http://loreum.com', 'content-type': 'application/x-www-form-urlencoded; some-other-value' },
headers: {
origin: 'http://loreum.com',
'content-type': 'application/x-www-form-urlencoded; some-other-value',
},
method: 'POST',
});
response = await app.render(request);
assert.equal(response.status, 403);

request = new Request('http://example.com/api/', {
headers: { origin: 'http://loreum.com', },
headers: { origin: 'http://loreum.com' },
method: 'POST',
credentials: 'include',
body: new Blob(["a=b"],{})
body: new Blob(['a=b'], {}),
});
response = await app.render(request);
assert.equal(response.status, 403);
Expand Down

0 comments on commit 10c6b8d

Please sign in to comment.