-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(backend): Sanitize slashes in URL paths #3982
Conversation
🦋 Changeset detectedLatest commit: 6418a29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
839049c
to
0b8b0ed
Compare
Please note that I'm unsure whether that's the right way to fix the issue. At least, it's been working great for my Astro site. It may be better to handle the duplicate slashes at the middleware layer. |
@mlafeldt Hello, and thanks for your contribution! |
The double slash is part of the curl request I'm sending to Astro (see the HEAD example above). Anyone could be sending such a request to CF. IIRC, I first used multiple slashes by accident when I noticed the crashing middleware. |
I haven't checked CF's implementation of Deno:
Node
|
Trying to replicate this issue on my end. I have an app deployed to CF pages as well - https://astro-clerk-template.pages.dev I tried to tail it and sent a request via curl: It's not throwing any errors on my end. Might be missing something. Deployed a fresh Astro app without Astro also made an attempt to handle duplicate slashes but reverted it |
@wobsoriano I created a quick example that reproduces the problem: https://github.com/mlafeldt/fumbling-fusion This works:
This does not:
And the reported backtrace again:
Happy to provide more info. |
Two small comments on this example:
Relevant: nodejs/node#30776 |
b5fa2dc
to
ac30531
Compare
@wobsoriano @anagstef I think I found a good solution to address the issue without messing with the URL at all. Please take a look at my latest commit: ac30531 |
@mlafeldt I'm curious, does this issue affect your project? Are you using URLs with double slashes in your app? |
Nope, routing on double slashes is not a good practice IMO, but I really prefer my app to not crash in case someone sends such a request (which I can't control). 😄 Hence the PR. |
In general, the handling of multiple slashes in URL paths doesn't seem to be standardized. For example, |
So there's a repro of the crash, a minimal non-invasive fix, and a test for that fix. What else do you need to move this forward? Happy to assist. 🙏 |
Hi @mlafeldt, sorry for the late reply. The fix is minimal and non-invasive as you said, so I just approved the workflow to run the e2e tests and we can proceed after that. Edit: Okay did some more tests. Without the Clerk integration and doing multiple slashes leads to a 404 on CF. Vercel normalizes it. |
@mlafeldt updated the changeset message, hope you don't mind ✌🏼 |
@wobsoriano Thanks! Re Cloudflare: With a custom domain, I had to enable "Normalize URLs to origin" for multiple slashes to be collapsed. However, when using the pages.dev domain, you can't configure normalization AFAIK. As for the number of slashes, it's actually a bit more complicated. 😃 But I still think the fix makes sense in any case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @mlafeldt. Based on our convo and the info provided, I'm going to approve this one 👍🏼
Appreciate the patience!
@wobsoriano Awesome! Looking forward to the next release. 🚀 |
Description
Fixes the following worker crash in Cloudflare Pages when accessing an API endpoint where the URL path starts with more than one slash:
Triggered by:
Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change