Skip to content

Commit faecc33

Browse files
asaharangioboa
andauthored
fix: compare URLs without protocols with checkOrigin: lax-proto (#7865)
* Remove standard CSRF middleware for lax-proto Previously, two CSRF middlewares were added for lax-proto requests: one at the beginning and one at the end. This change replaces them with a single middleware placed at the beginning. Non-lax-proto cases remain unchanged. * Fix CSRF check for lax-proto match origin and inputOrigin after removing protocol when checkOrigin is lax-proto * fix: replace http(s) only at the beginning * Update .changeset/curvy-glasses-wash.md Co-authored-by: Giorgio Boa <35845425+gioboa@users.noreply.github.com> --------- Co-authored-by: Giorgio Boa <35845425+gioboa@users.noreply.github.com>
1 parent ea22cc2 commit faecc33

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

.changeset/curvy-glasses-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik-city': patch
3+
---
4+
5+
FIX: fix behaviour of checkOrigin: "lax-proto" in createQwikCity

packages/qwik-city/src/middleware/request-handler/resolve-request-handlers.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export const resolveRequestHandlers = (
6666
checkOrigin &&
6767
(method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE')
6868
) {
69-
requestHandlers.unshift(csrfCheckMiddleware);
70-
7169
if (checkOrigin === 'lax-proto') {
72-
requestHandlers.push(csrfLaxProtoCheckMiddleware);
70+
requestHandlers.unshift(csrfLaxProtoCheckMiddleware);
71+
} else {
72+
requestHandlers.unshift(csrfCheckMiddleware);
7373
}
7474
}
7575
if (isPageRoute) {
@@ -450,8 +450,7 @@ function checkCSRF(requestEv: RequestEvent, laxProto?: 'lax-proto') {
450450
if (
451451
forbidden &&
452452
laxProto &&
453-
origin.startsWith('https://') &&
454-
inputOrigin?.slice(4) === origin.slice(5)
453+
inputOrigin?.replace(/^http(s)?/g, '') === origin.replace(/^http(s)?/g, '')
455454
) {
456455
forbidden = false;
457456
}

0 commit comments

Comments
 (0)