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

StaticFileHandler doesn't work on Windows #660

Open
konovod opened this issue Jul 31, 2023 · 1 comment
Open

StaticFileHandler doesn't work on Windows #660

konovod opened this issue Jul 31, 2023 · 1 comment
Labels

Comments

@konovod
Copy link

konovod commented Jul 31, 2023

Description

StaticFileHandler doesn't work on Windows due to expand_path adding drive letter in Windows.

Steps to Reproduce

  1. Take hello world project (use Kemal.run(trap_signal: false) due to A simple hello world kemal app run on windows failed. (but compilation on github action successful) #658 )
  2. Add public dir with some files
  3. Run and try to access any file.

Expected behavior: In Windows, as in Linux, browser should show a file.

Actual behavior: Browser shows error (status 302 with pretty misleading message in case of Firefox)

Reproduces how often: Always

Versions

Crystal 1.9.2, Kemal 1.4.0

Additional Information

The problem is in a line

expanded_path = File.expand_path(request_path, "/")

That expands file.html to d:\file.html in Windows (adds a drive letter), that is later is concatenated with public dir, giving final path ...\public\d:\file.html.
If this line is replaced with expanded_path = request_path, problem is gone and file is shown, but this is (perhaps) unacceptable as a fix - if I understand correctly, this line is to avoid a way to escape from public dir.
I'm not sure how correct fix should work - expand a path from a public dir then check that result is inside public dir? Or maybe expand_path in stdlib should be fixed to do not add a drive letter?

@konovod
Copy link
Author

konovod commented Jul 31, 2023

Looks like this is a already mentioned in of #657 (comment)

@sdogruyol sdogruyol added the bug label Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants