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

Accessing /static/{dir} will redirect to OS relative path #1020

Closed
firdausramlan opened this issue Feb 7, 2017 · 10 comments
Closed

Accessing /static/{dir} will redirect to OS relative path #1020

firdausramlan opened this issue Feb 7, 2017 · 10 comments
Assignees

Comments

@firdausramlan
Copy link

Version: 1.2.3 & 2.0.0-beta.24

Let say I have folder /static/img, accessing url http://localhost:3000/static/img will redirect to http://localhost:3000/Users/bob/myapp/static/img/ .

@arunoda
Copy link
Contributor

arunoda commented Feb 7, 2017

Can we have a sample repo for that and how to re-produce this?

@firdausramlan
Copy link
Author

Sample repo: https://github.com/firdausramlan/static-dir-redirect

You can test it here. Click /static/img link and observe the url.

@timneutkens
Copy link
Member

Just tested. Seeing the same issue you're seeing. I'll have a look @firdausramlan 😄

@arunoda
Copy link
Contributor

arunoda commented Feb 7, 2017

Yeah! This is critical.
Since it expose the actual server path name.

@timneutkens
Copy link
Member

Indeed. Fixing a critical bug in micro right now. Having a look after.

@arunoda
Copy link
Contributor

arunoda commented Feb 7, 2017

@timneutkens I'll add some helpful info here to ease you task :)

@timneutkens
Copy link
Member

@arunoda ❤️

@arunoda
Copy link
Contributor

arunoda commented Feb 7, 2017

@timneutkens here's the source of the problem.
It's on the send npm module.
See: https://github.com/pillarjs/send/blob/master/index.js#L675

It redirect to the path if it find out the path is a dir.

@arunoda
Copy link
Contributor

arunoda commented Feb 7, 2017

@timneutkens Changing our server/render.js as follows will work.
But need more testing.

export function serveStatic (req, res, path) {
  return new Promise((resolve, reject) => {
    send(req, path)
    .on('error', reject)
    .on('directory', function() {
      const err = new Error('No dir access')
      err.code = 'ENOENT'
      reject(err)
    })
    .pipe(res)
    .on('finish', resolve)
  })
}

@timneutkens
Copy link
Member

@arunoda example works totally fine 👍 added a comment to explain why we do that 😉

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants