Skip to content

some people don't want the paths to be decoded #30

Closed

Description

@jonathanong

Activity

  1. netnichols commented on Jan 3, 2014

    @netnichols

    Copying over some example paths from a duplicate issue that was closed in Express, just to demonstrate some 'real world' paths that are affected by this logic...

    Some examples of paths that are rejected/mangled by Send in res.sendfile:

    express rejects path: /Users/jeff/Pictures/iPhoto Library/Thumbnails/2012/10/06/20121006-103601/yI%6UxAgRnOnHWH6659V0Q/P9225012.jpg
    express rejects path: /Users/jeff/Pictures/iPhoto Library/Thumbnails/2012/10/06/20121006-103601/jMQ%putSQKm58erJTWmn+g/P9225014.jpg
    express mangles path: /Users/jeff/Pictures/iPhoto Library/Thumbnails/2012/10/06/20121006-103601/Eo%64jpVT36booQOByN2MA/P9225017.jpg
    
  2. tj commented on Jan 4, 2014

    @tj
    Contributor

    IMO still doesn't make sense, they should be url-encoded first so that % escapes

  3. netnichols commented on Jan 4, 2014

    @netnichols

    @visionmedia I'm not sure I follow you. Do you mean that every call to res.sendfile (in express) should look like the following?

    res.sendfile(encodeURIComponent(path));
    

    In my particular case I have no control over those paths (and there are many thousands of them), so I'd need to URI encode them all just to be safe. Also, if I'm understanding your suggestion, one should always URI encode any path sent to res.sendfile unless the user is absolutely sure that the path does not contain any sequences that will be 'decoded' by decodeURIComponent.

    For a method that purports to send a 'file', and takes a file system 'path', I just don't really understand why one should need to defensively URI encode a valid file system path.

  4. tj commented on Jan 5, 2014

    @tj
    Contributor

    I just mean the original client that is creating the url that is clicked on should probably just encodeURIComponent, you'd have to do it for other characters anyway so it seems a little strange, not that it's "wrong", just seems strange to me, or use "url safe" hashes

  5. added this to the 1.0.0 milestone on Apr 23, 2014
  6. dougwilson commented on Apr 24, 2014

    @dougwilson
    Contributor

    I think the file names given to this module should be file system-style names, not URL-style names, personally. This would be a breaking change, so would have to wait for a 1.0.0 anyway, which gives time for people to argue about it.

  7. dougwilson commented on May 28, 2014

    @dougwilson
    Contributor

    Another reason they should probably be file system names is because if they are URL-style names, people may just pass a URI directly into the module, which assumes that the URL has octets encoded in the same way as the file system, which is not always the case :)

  8. added a commit that references this issue on Jun 12, 2014
    96332a5
  9. added a commit that references this issue on Jun 28, 2014
    3e979ed
  10. kennu commented on Aug 11, 2014

    @kennu

    I just spent several hours debugging a problem caused by this implicit URI decoding. I think it would be good to highlight it in the documentation of both send() and Express sendfile(), so people know they have to encodeURIComponent the path parameter.

    The worst thing is that when the filename happens to contain "%2F", it will be implicitly decoded into a "/", so send() will try to read a random file from a random directory. This probably opens up various directory traversal attacks in many applications.

  11. dougwilson commented on Aug 11, 2014

    @dougwilson
    Contributor

    Use res.sendFile in express 4.8 (with the capital F). That takes a file system path.

  12. dougwilson commented on Aug 11, 2014

    @dougwilson
    Contributor

    Anyway, there is the solution for express. This module will never take a file system path, because it does things like URL redirects and needs a URL as the path to do so. I can certainly call it out in the readme here, though.

  13. locked and limited conversation to collaborators on Aug 11, 2014
  14. added a commit that references this issue on Jan 5, 2015
    5102702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions