summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-09-21 12:32:38 +0200
committerErik Larkö <erik@mullvad.net>2017-09-22 08:02:55 +0200
commit578fec0b01768168fe646022e2777988f69f9cbc (patch)
tree804241b860e968a72caae899e074d782efba73f3
parentf615ddacbfbbc04a2147b3ada75cefd318fd220c (diff)
downloadmullvadvpn-578fec0b01768168fe646022e2777988f69f9cbc.tar.xz
mullvadvpn-578fec0b01768168fe646022e2777988f69f9cbc.zip
Review fixes
-rw-r--r--app/main.js10
1 files changed, 3 insertions, 7 deletions
diff --git a/app/main.js b/app/main.js
index 7e69b48ad2..c4de950c20 100644
--- a/app/main.js
+++ b/app/main.js
@@ -182,6 +182,8 @@ const appDelegate = {
return;
}
+ log.debug('Reading the ipc connection info from', rpcAddressFile);
+
const isSecureEnough = isOwnedAndOnlyWritableByRoot(rpcAddressFile);
if (!isSecureEnough) {
log.error('Not trusting the contents of', rpcAddressFile, 'as it was not owned and only writable by root.');
@@ -193,8 +195,6 @@ const appDelegate = {
// permissions and read the contents of the file. We deem the chance
// of that to be small enough to ignore.
- log.debug('Reading the ipc connection info from', rpcAddressFile);
-
fs.readFile(rpcAddressFile, 'utf8', function (err, data) {
if (err) {
return log.error('Could not find backend connection info', err);
@@ -371,11 +371,7 @@ appDelegate.setup();
function isOwnedAndOnlyWritableByRoot(path) {
const stat = fs.statSync(path);
const isOwnedByRoot = stat.uid === 0;
+ const isOnlyWritableByOwner = (stat.mode & parseInt('022', 8)) === 0;
- // Taken from gagle's comment at https://github.com/nodejs/node-v0.x-archive/issues/3045#issuecomment-4865547
- const modeAsOctalString = (stat.mode & parseInt('777', 8)).toString(8);
- const isOnlyWritableByOwner = modeAsOctalString === '604';
-
- log.debug(path, 'is owned by', stat.uid, 'and has permsissions', modeAsOctalString);
return isOwnedByRoot && isOnlyWritableByOwner;
}