Skip to content

Conversation

asaharan
Copy link
Contributor

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.

What is it?

  • Bug

Description

fix behaviour of checkOrigin: "lax-proto" in createQwikCity

Checklist

Copy link

changeset-bot bot commented Aug 25, 2025

🦋 Changeset detected

Latest commit: cc7a14c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik-city Patch
eslint-plugin-qwik Patch
@builder.io/qwik Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@asaharan asaharan changed the title Remove standard CSRF middleware for lax-proto and use csrfLaxProtoCheckMiddleware Replace standard CSRF middleware with csrfLaxProtoCheckMiddleware for checkOrigin: lax-proto Aug 25, 2025
Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help @asaharan
Is there a specific issue with the actual code?
why are we changing it?

@asaharan
Copy link
Contributor Author

Yes @gioboa , even when I set checkOrigin to lax-proto, I get CSRF error.
ORIGIN=https://saharan.dev
Request is coming from https://saharan.dev
but there is a load balancer(say AWS ALB) in between, so it forwards x-forwarded-proto: https but still I get the CSRF error saying saying request domain https://saharan.dev doesn't match origin http://saharan.dev

lax-proto is supposed to handle this case, hence this change.

Copy link
Contributor

github-actions bot commented Aug 26, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 7529a70

wmertens
wmertens previously approved these changes Aug 26, 2025
Copy link
Member

@wmertens wmertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🌉

Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test the package generated by this PR and let us know if it's working as expected on your scenario. Thanks.

Copy link

pkg-pr-new bot commented Aug 26, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@builder.io/qwik@7865
npm i https://pkg.pr.new/@builder.io/qwik-city@7865
npm i https://pkg.pr.new/eslint-plugin-qwik@7865
npm i https://pkg.pr.new/create-qwik@7865

commit: cc7a14c

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.
@asaharan
Copy link
Contributor Author

asaharan commented Sep 1, 2025

@gioboa as csrf is being checked at the very beginning, origin contains http and not https. So, I have compare origin with inputOrigin after removing the protocol(http/https).
Have tested this on my production environment by directly modifying files inside node_modules and it's working fine over there.

Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, Thanks 👍

@gioboa gioboa marked this pull request as ready for review September 1, 2025 16:34
@gioboa gioboa requested a review from a team as a code owner September 1, 2025 16:34
Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help @asaharan

@gioboa gioboa enabled auto-merge (squash) September 1, 2025 16:40
@gioboa gioboa disabled auto-merge September 1, 2025 16:41
@gioboa gioboa changed the title Replace standard CSRF middleware with csrfLaxProtoCheckMiddleware for checkOrigin: lax-proto fix: compare URLs without protocols with checkOrigin: lax-proto Sep 1, 2025
@gioboa gioboa enabled auto-merge (squash) September 1, 2025 16:44
@gioboa gioboa merged commit faecc33 into QwikDev:main Sep 1, 2025
17 checks passed
@github-actions github-actions bot mentioned this pull request Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants