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

User: fix file permissions on create #4507

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/clientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ ClientManager.prototype.addUser = function (name, password, enableLog) {
};

try {
fs.writeFileSync(userPath, JSON.stringify(user, null, "\t"));
fs.writeFileSync(userPath, JSON.stringify(user, null, "\t"), {
mode: 0o600,
});
} catch (e) {
log.error(`Failed to create user ${colors.green(name)} (${e})`);
throw e;
Expand Down Expand Up @@ -231,7 +233,9 @@ ClientManager.prototype.saveUser = function (client, callback) {
try {
// Write to a temp file first, in case the write fails
// we do not lose the original file (for example when disk is full)
fs.writeFileSync(pathTemp, newUser);
fs.writeFileSync(pathTemp, newUser, {
mode: 0o600,
});
fs.renameSync(pathTemp, pathReal);

return callback ? callback() : true;
Expand Down
2 changes: 1 addition & 1 deletion src/command-line/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ function initalizeConfig() {
log.info(`Configuration file created at ${colors.green(Helper.getConfigPath())}.`);
}

fs.mkdirSync(Helper.getUsersPath(), {recursive: true});
fs.mkdirSync(Helper.getUsersPath(), {recursive: true, mode: 0o700});
}
4 changes: 3 additions & 1 deletion src/command-line/users/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ function change(name, password) {

// Write to a temp file first, in case the write fails
// we do not lose the original file (for example when disk is full)
fs.writeFileSync(pathTemp, newUser);
fs.writeFileSync(pathTemp, newUser, {
mode: 0o600,
});
fs.renameSync(pathTemp, pathReal);

log.info(`Successfully reset password for ${colors.bold(name)}.`);
Expand Down