-
Notifications
You must be signed in to change notification settings - Fork 245
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
node-static win32 forbiden #42
Comments
Maybe we could have a development flag to allow access outside the path. |
Wasn't clear for me what happened on Windows. Which error was raised? |
Hello. Thanks for your great plugin. I got a same error, when document-root is relative path. TEST: var path = require('path');
var current = path.resolve('.');
console.log('current: ' + current);
var joinedPath = path.join(current, 'foo-bar');
console.log('joinedPath: ' + joinedPath); RESULT: Look the Drive-Letter current: E:\Documents
joinedPath: e:\Documents\foo-bar Therefore, So, Windows ignores that letter of path is upper case or lower case. Therefore, I rewrote below, and this error was resolved. //if (pathname.indexOf(that.root) === 0) {
if ((require('os').platform() === 'win32' ?
pathname.toLowerCase().indexOf(that.root.toLowerCase()) : // Windows
pathname.indexOf(that.root)) === 0) { // Others Or, lower case drive-letter is given to constructor, and this error was resolved too. |
@anseki [I stumbled on the same problem] actually the problem lies in the commit [ it is being discussed on https://github.com/nodejs/node-v0.x-archive/issues/7031 ] Another possible workaround would be to call resolve() and normalize() on any path passed as document-root:
which is what koa-send does |
I didn't know why (But, I don't know that this behaviour of Web Server is good or not. RFC1738 says that |
- Calling resolve() doesn't fully normalize relative path on Windows (in Node v0.11.x, see nodejs/node-v0.x-archive#7031 ), i.e. doesn't lowercase drive letter, while normalize() does, which causes paths resulting from calling normalize() and join() (depending on normalize()) to differ and to break comparisons. Fixes cloudhead#42.
using node + node-static on winxp and setting
var fileServer = new nstatic.Server("C:/public");
gave me an error everytime i tried to acces the localhost:8080 expecting to load the index.html
error comes from this line in node-static.js
this.Server.prototype.servePath = function (pathname, status, headers, req, res, finish)
......
// Make sure we're not trying to access a file outside of the root.
if (new(RegExp)('^' + that.root).test(pathname)) {
in that regex, pathname was C:\public and that.root = C:\public too.
so while in development (i dont have to worry bout someone trying to acces another files)
i comented this line and now is working fine
sorry for my english
The text was updated successfully, but these errors were encountered: