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

upload-server safeName #8

Open
HenryTi opened this issue May 28, 2015 · 3 comments
Open

upload-server safeName #8

HenryTi opened this issue May 28, 2015 · 3 comments

Comments

@HenryTi
Copy link

HenryTi commented May 28, 2015

hi,
maybe it's is an issue:

FileInfo.prototype.safeName = function () {
// Prevent directory traversal and creating hidden system files:
this.name = path.basename(this.name).replace(/^.+/, '');
// Prevent overwriting existing files:
while (_existsSync(options.uploadDir + '/' + this.name)) {
this.name = this.name.replace(nameCountRegexp, nameCountFunc);
}
};

The options.uploadDir should be options.getDirectory() ?

For example, img.png is in /dir1, when another img.png uploaded, there will be error throw out. Am I right?

Thank you, I like your this upload package.

  • Henry
@HenryTi HenryTi closed this as completed May 28, 2015
@HenryTi
Copy link
Author

HenryTi commented May 28, 2015

I build a subdirectory for each user, so when the user uploads same image again, it will override last uploaded image.

@HenryTi HenryTi reopened this May 28, 2015
@tomitrescak
Copy link
Owner

Henry, it's definitelly a bug. Would you be keen in doing the pull request? I'm extremely busy these days. Thanks!

@HenryTi
Copy link
Author

HenryTi commented May 29, 2015

Hi,

I don’t know what is "pull request".

I carefully checked the code, the following can fix the code.

  1. remove FileInfo.safeName function
  2. add a new function:
    function getSafeName(fileName) {
    var n = fileName;
    // Prevent directory traversal and creating hidden system files:
    n = path.basename(n).replace(/^.+/, '');
    // Prevent overwriting existing files:
    while (_existsSync(options.uploadDir + '/' + n)) {
    n = n.replace(nameCountRegexp, nameCountFunc);
    }
    return n;
    }
  3. add a code in upload_server.js after line 429
    newFileName = getSafeName(newFileName);
  4. ok
  • Henry

On May 28, 2015, at 7:06 PM, Tomas Trescak notifications@github.com wrote:

Henry, it's definitelly a bug. Would you be keen in doing the pull request? I'm extremely busy these days. Thanks!


Reply to this email directly or view it on GitHub #8 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants