cloudflare / cloudflare/workers-sdk

🐛 BUG: In some cases, urls with double slashes don't invoke Pages Functions _middleware

Open
#3,677 1 comment 0 reactions 4 assignees Claimed by @stritt View on GitHub
package:pages-functions package:wrangler product:pages
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

### Which Cloudflare product(s) does this pertain to?

Pages

### What version(s) of the tool(s) are you using?

latest

### What version of Node are you using?

20.1.0

### What operating system are you using?

Mac

### Describe the Bug

I am using middleware in `/functions` to secure some pages. But when the url has double slashes `//`, wrangler doesn't run the middleware for the url.

I have replicated the issue in a [minimal repo here](https://github.com/Shivam010/cloudflare-double-slashes-issue)

---

There's a middleware in `/functions/secure` directory to be applied on all routes of `/secure`.

And the `/out/secure` directory contains a file `one.html` which should be served at `/secure/one` (but first the middleware needs to be invoked)

Now, the **Problem**...

The middleware is properly invoked on `/secure/one` route but not on the `//secure/one`, whenever someone uses a double slash before the middleware directory, wrangler doesn't run the middleware and instead directly serve the pages.

## Links

- [Github Repo: https://github.com/Shivam010/cloudflare-double-slashes-issue](https://github.com/Shivam010/cloudflare-double-slashes-issue)
- [Hosted on: https://double-slashes-issue.pages.dev](https://double-slashes-issue.pages.dev/)
- [`/secure/one` route](https://double-slashes-issue.pages.dev/secure/one)
- [`//secure/one` route](https://double-slashes-issue.pages.dev//secure/one)
- [`/secure/one?allow` route](https://double-slashes-issue.pages.dev/secure/one?allow) _that's actually allowed by middleware_

---

Am I missing something here? or is this an actual issue?

### Please provide a link to a minimal reproduction

https://github.com/Shivam010/cloudflare-double-slashes-issue

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.