Skip to content

Simple Whitelist for File Extensions - #122

Open
alexgurrola wants to merge 2 commits into
nodeftpd:masterfrom
Sitetheory:master
Open

Simple Whitelist for File Extensions#122
alexgurrola wants to merge 2 commits into
nodeftpd:masterfrom
Sitetheory:master

Conversation

@alexgurrola

Copy link
Copy Markdown

In many cases, you want to limit the file extensions saved on the server to prevent executables or other formats from being uploaded.

@sstur sstur left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I've added a little feedback inline..

Comment thread lib/FtpConnection.js
// Filter extensions if whitelist available
var whitelist = self.server.options.allowedExtensions;
var accepted = true;
if (whitelist && typeof whitelist === 'object' && Array.isArray(whitelist) && whitelist.length) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.isArray(whitelist) && whitelist.length should be sufficient, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if it's an object and has a length, why check for array-ity?

Comment thread lib/FtpConnection.js
if (whitelist && typeof whitelist === 'object' && Array.isArray(whitelist) && whitelist.length) {
accepted = false;
whitelist.forEach(function (ext) {
if (fileto.endsWith(ext)) accepted = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check what version of Node added support for endsWith since we want to make sure we don't break existing installations..

@mk-pmb mk-pmb Jan 6, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should allow RegExps too, or Cartesian product will explode for relatively simple stuff like /\.(html?|jpe?g|png|gif|p[pgx]m|txt)(\.((t?g|7)z|zip|tar(\.[g7]z|))|)$/. And that doesn't even yet include rules to allow some parts to be all-uppercase when using tar. ;-)

Comment thread lib/FtpConnection.js
whitelist.forEach(function (ext) {
if (filename.endsWith(ext)) accepted = true;
});
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're repeating this whitelist checking logic, I think it would make sense to put it in a function so we can do: var accepted = checkWhitelist(self.server.options.allowedExtensions, filename);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it should be have "extension" in its name because we might add other whitelists in the future.

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.

3 participants