Skip to content
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

Wrong redirect edge case #3208

Closed
lydell opened this issue Jul 2, 2023 · 0 comments
Closed

Wrong redirect edge case #3208

lydell opened this issue Jul 2, 2023 · 0 comments

Comments

@lydell
Copy link

lydell commented Jul 2, 2023

esbuild’s server redirects to add a trailing slash for directories. I found an edge case there. If the path starts with 2 or more slashes, the redirect does not work – because it becomes a protocol relative URL. So esbuild effectively tries to redirect to http://name_of_folder/.

To reproduce, make a new folder and run:

❯ npm init -y >/dev/null

❯ npm i esbuild

added 2 packages, and audited 3 packages in 2s

found 0 vulnerabilities

❯ npx esbuild --version
0.18.11

❯ npx esbuild --serve --servedir=.

 > Local:   http://127.0.0.1:8000/

And in another tab:

❯ curl -IL http://127.0.0.1:8000//node_modules
HTTP/1.1 302 Found
Access-Control-Allow-Origin: *
Location: //node_modules/
Date: Sun, 02 Jul 2023 19:40:04 GMT

curl: (6) Could not resolve host: node_modules

Here’s a fun extra thing you can do:

❯ mkdir google.com

❯ curl -IL http://127.0.0.1:8000//google.com
HTTP/1.1 302 Found
Access-Control-Allow-Origin: *
Location: //google.com/
Date: Sun, 02 Jul 2023 19:42:15 GMT

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
...
@evanw evanw closed this as completed in 838f90d Jul 10, 2023
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

No branches or pull requests

1 participant