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

clientManager: don't write user configs outside of lounge's users dir #238

Merged
merged 1 commit into from
May 8, 2016

Conversation

williamboman
Copy link
Member

No description provided.

@@ -35,6 +35,7 @@
"lodash": "4.6.1",
"mkdirp": "0.5.1",
"moment": "2.12.0",
"path-is-inside": "1.0.1",
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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
}

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated patch now

@williamboman williamboman force-pushed the fix/safer-add-user branch 3 times, most recently from 0352432 to bf123de Compare April 2, 2016 21:48
@xPaw xPaw added the Type: Bug Issues that report and PRs that solve any defects that cause unexpected behaviors. label Apr 20, 2016
@@ -70,16 +72,20 @@ ClientManager.prototype.addUser = function(name, password) {
return false;
}
try {
var path = Helper.HOME + "/users";
var usersPath = Helper.HOME + "/users";
Copy link
Member

@xPaw xPaw May 7, 2016

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

@williamboman williamboman force-pushed the fix/safer-add-user branch 2 times, most recently from cfd39c1 to 0b1365e Compare May 7, 2016 11:27
@xPaw
Copy link
Member

xPaw commented May 7, 2016

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...

@williamboman williamboman force-pushed the fix/safer-add-user branch from 0b1365e to 5e38060 Compare May 7, 2016 11:35
@williamboman
Copy link
Member Author

Also looking at this code try/catch is completely useless here...

Not anymore!

@xPaw
Copy link
Member

xPaw commented May 7, 2016

👍

@williamboman williamboman force-pushed the fix/safer-add-user branch 6 times, most recently from 537929b to a44f4a0 Compare May 7, 2016 12:14
@@ -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");
Copy link
Member

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

Copy link
Member Author

@williamboman williamboman May 7, 2016

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

Copy link
Member

@xPaw xPaw May 7, 2016

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.

Copy link
Member Author

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

Copy link
Member

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.

@maxpoulin64
Copy link
Member

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.

@astorije
Copy link
Member

astorije commented May 8, 2016

👍

@astorije astorije merged commit 29e0717 into thelounge:master May 8, 2016
@astorije astorije added this to the ★ Next Release milestone May 15, 2016
@astorije astorije added the Type: Security Security concern or PRs that must be reviewed with extra care regarding security. label May 21, 2016
@williamboman williamboman deleted the fix/safer-add-user branch May 26, 2016 14:15
matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
clientManager: don't write user configs outside of lounge's users dir
@xPaw xPaw removed their assignment Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issues that report and PRs that solve any defects that cause unexpected behaviors. Type: Security Security concern or PRs that must be reviewed with extra care regarding security.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants