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

serveStatic root is incorrect on Windows + Bun for absolute path (other interpreters probably too) #3475

Open
dmytro-peleshenko opened this issue Oct 1, 2024 · 2 comments
Labels

Comments

@dmytro-peleshenko
Copy link

What version of Hono are you using?

4.6.3

What runtime/platform is your app running on?

Bun

What steps can reproduce the bug?

app.use("/static/*", 
    serveStatic({ 
        root: __dirname,
        onNotFound(path, c) {
            console.log(path)
        }
    }));

What is the expected behavior?

Server serve static file from __dirname +"/static"

What do you see instead?

Windows: Server always returns "resource not found". console.log in the onNotFound handler shows path starting from "./C:/Users/..."

Linux: Working as it should

Additional information

That is probably is the reason of the problem
image

I think serveStatic should always expect absolute path or not modify the path. To make it safe just avoid ".." in the file name.

Also "static" (or probably the url prefix used during the middleware registration) is always added to the root path when searching for the file. It seams to be strange too.

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Oct 30, 2024

Perhaps it would be better to pass the __dirname prefix by replacing it...
I think hardcoding poses a security risk.

__dirname.replace(/^C:/, "")

@yusukebe
Copy link
Member

I'm planning that the serveStatic supports Windows: #3477

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

3 participants