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

Do not serve files when path ends with / #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rmhaiderali
Copy link

@rmhaiderali rmhaiderali commented Jan 20, 2024

When index option is set to false and the environment is Windows, requests that end with a / might result in serving files. This happens because in Windows, when accessing a file or directory, if the path ends with /, the system first checks for a directory. If no directory is found, it then checks if a file with the same name exists, ignoring the / at the end of the path. This enables access to a file unexpectedly, as if the path did not conclude with /.

The proposed fix addresses this issue by introducing a check to ensure that the path does not ends with / before serving a file. For example, in the given case, file is being accessed when it should not be, and the proposed change aims to rectify this behavior.

index.js

var http = require("http");
var send = require("send");

var server = http.createServer(function onRequest(req, res) {
  send(req, "./index.html/", { index: false }).pipe(res);
});

server.listen(3000);

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    HTML File
  </body>
</html>

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

Successfully merging this pull request may close these issues.

None yet

1 participant