-
Notifications
You must be signed in to change notification settings - Fork 701
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
clientManager: don't write user configs outside of lounge's users dir #238
Conversation
@@ -35,6 +35,7 @@ | |||
"lodash": "4.6.1", | |||
"mkdirp": "0.5.1", | |||
"moment": "2.12.0", | |||
"path-is-inside": "1.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not bring in modules for stuff that can be done in one line.
I'm thinking we should only be allowing a-zA-Z0-9_-
in usernames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really a one-liner though :). A custom one-liner is also far from as robust and well-tested (across numerous platforms) as a package too. Unix philosophy + Node ftw!
I'm thinking we should only be allowing a-zA-Z0-9_- in usernames.
I thought so as well, but didn't want to make such a decision in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A custom one-liner is also far from as robust and well-tested (across numerous platforms) as a package too. Unix philosophy + Node ftw!
/me looks at left-pad in panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, that's just the shortcomings of npm
though. They've retroactively done some damage control by disabling unpublish
on packages that are >24 hrs old.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to change to testing the name with /^[a-z0-9_-]+$/i
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ideally we should simply disallow what is not valid characters for the filesystem. /^[^\/\\<>:"|?*]+$/
. This should cover at least Linux and Windows, and probably Mac as well. I think Windows is alone having such restricted file names.
Source: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use path.basename to fix writing outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use path.basename to fix writing outside.
Do you mean that ../../MZuckerberg
silently becomes MZuckerberg
, or should it do it interactively, like;
if (path.basename(user) !== user) {
// interactively ask if path.basename(user) should be used instead - else error
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just error out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated patch now
0352432
to
bf123de
Compare
@@ -70,16 +72,20 @@ ClientManager.prototype.addUser = function(name, password) { | |||
return false; | |||
} | |||
try { | |||
var path = Helper.HOME + "/users"; | |||
var usersPath = Helper.HOME + "/users"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this, do path.join(Helper.HOME, "users");
instead.
Sorry for previous comment, didn't notice it creates the folder
cfd39c1
to
0b1365e
Compare
Looks good to me. Should we perform same check in any other commands? Like edit or remove? Also looking at this code try/catch is completely useless here... |
0b1365e
to
5e38060
Compare
Not anymore! |
👍 |
537929b
to
a44f4a0
Compare
@@ -3,13 +3,31 @@ var fs = require("fs"); | |||
var Client = require("./client"); | |||
var mkdirp = require("mkdirp"); | |||
var Helper = require("./helper"); | |||
var path = require("path"); | |||
|
|||
var USERS_PATH = path.join(Helper.HOME, "users"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can directly assign it to ClientManager.USERS_PATH
, and in this file use this.USERS_PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"static" properties are hidden from the prototype chain, so this.USERS_PATH
would be undefined
. I could do var USERS_PATH = ClientManager.USERS_PATH = path....
though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sure about that? It seems to work.
function ClientManager() {}
ClientManager.test = 'kek';
ClientManager.w = function(){console.log(this.test);}
ClientManager.w(); // "kek"
You could assign it inside the "constructor" though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that would work since you're not working with its prototype;
function CM() {}
CM.FOO = 'bar';
CM.prototype.bar = function () { console.log(this.FOO); };
a = new CM
a.bar(); // undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I went that way as your two new functions didn't use prototype
, but others in the file do.
a44f4a0
to
5e38060
Compare
Looks good to me. I still think it would have been better to check for valid file names entirely, but this works too. 👍 Leaving open so other people can confirm and merge. |
👍 |
clientManager: don't write user configs outside of lounge's users dir
No description provided.