fix: better handler malformed paths#7612
Conversation
🦋 Changeset detectedLatest commit: 672c33b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
277b462 to
48fdec6
Compare
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-wrangler-7612You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7612/npm-package-wrangler-7612Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-wrangler-7612 dev path/to/script.jsAdditional artifacts:wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-workers-bindings-extension-7612 -O ./cloudflare-workers-bindings-extension.0.0.0-v7d18629c4.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v7d18629c4.vsixnpx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-create-cloudflare-7612 --no-auto-updatenpm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-kv-asset-handler-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-miniflare-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-pages-shared-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-unenv-preset-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-vitest-pool-workers-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-workers-editor-shared-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-workers-shared-7612npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12521566264/npm-package-cloudflare-workflows-shared-7612Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
petebacondarwin
left a comment
There was a problem hiding this comment.
I am not sure how this can happen in practice - i.e. whether it is possible to access a real asset via a malformed URL segment.
But I feel like we should just be passing through these invalid segments rather than 404ing.
So instead of this fix we just change decodePath() so that it is resilient there: catching the error for each segment and just returning the original string instead of the decoded one.
If there is no such asset, then it would still 404 but at least we are not potentially hiding a real asset.
|
Good call, that makes sense, thanks Pete. I've updated the changes and tests to account for this more gracefully. |
| .map((x) => { | ||
| let encoded; | ||
| try { | ||
| encoded = encodeURIComponent(x); |
There was a problem hiding this comment.
Can encodeURIComponent actually throw?
There was a problem hiding this comment.
If given something like a lone surrogate, yes:
encodeURIComponent("\uD800")
How likely/possible this is to happen in a URL? Probably not, but I felt like it couldn't hurt to wrap both.
91f2dca to
672c33b
Compare
|
Congratulations @Cherry, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cm5dcrmmj96750cmncd0hnuht This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
* fix: better handler malformed paths * chore: changeset * fix: pass-through malformed paths better
Fixes #7611
This more gracefully handles malformed URLs and simply throws a 404 on them instead of the entire Worker throwing an exception.