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

Fix #1: Fix windows required permissions for .env #2

Merged
merged 3 commits into from
Mar 15, 2018

Conversation

Nargonath
Copy link
Contributor

No description provided.

@Nargonath
Copy link
Contributor Author

I tried to add some tests to verify this behavior. I cannot run the tests suite right now as I'm on windows and all the prepare chmod command do not work in my case. I don't have my linux machine close by so if you don't mind testing that my test runs successfully.

index.js Outdated
@@ -61,7 +67,10 @@ const envy = (input) => {
return filterObj(camelizedGlobalEnv, camelizedExampleEnvKeys);
}

if (checkMode(envPath, permissionMask) !== ownerReadWrite) {
if (isWindows() && checkMode(envPath, permissionMask) !== windowsPermission) {
throw new Error(`File permissions are unsafe. Make them 666 '${envPath}'`);
Copy link
Owner

Choose a reason for hiding this comment

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

Make them 666

But the closest you can make them is 555, right? And if you somehow found a way to make them 666, this would fail anyway.

Also, is there a way to make them 555 from the command line on Windows? Would be nice to tell the user how to fix it. From what I read, maybe icacls could do it.

An alternative approach we could take here would be:

if (checkMode(envPath, num.S_IWGRP | num.S_IWOTH) === 0) {
    throw new Error('...');
}

That asserts that the writable bits for the "group" and "others" are off, as opposed to checking that all readable and executable bits are on and all writable bits are off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not aware of a command line way. I've been doing it from windows configuration panels but indeed it would be nice to do it with the command line. I wonder if you can call that command from bash or if you want to open Powershell or something similar.

Copy link
Contributor 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 update the PR with the "group" and "others" write bits off?

package.json Outdated
@@ -31,7 +31,8 @@
"dependencies": {
"camelcase": "^4.1.0",
"camelcase-keys": "^4.1.0",
"filter-obj": "^1.1.0"
"filter-obj": "^1.1.0",
"is-wsl": "1.1.0"
Copy link
Owner

Choose a reason for hiding this comment

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

Missing the ^

Copy link
Contributor Author

@Nargonath Nargonath Mar 15, 2018

Choose a reason for hiding this comment

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

Indeed sorry, my default NPM settings are --save-exact. I'll change it.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I figured. I had that for a while, too. Gave it up because it is a false sense of security. It only locks down your top level dependencies. If any of those dependencies have semver ranges and a sub-dependency violates semver (or has other issues), you're probably still going to be exposed to it. Updates tend to be good, anyway. And when you really need to lock things down properly, there is shrinkwrap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I might reconsider it indeed.

test.js Outdated
fixture('unsafe-perm-windows-env-777');
}, Error);
const filepath = path.join('fixture', 'unsafe-perm-env-640', '.env');
t.is(err.message, `File permissions are unsafe. Fix: chmod 600 '${filepath}'`);
Copy link
Owner

Choose a reason for hiding this comment

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

The Fix: part of this error message doesn't align with what is thrown in the Windows environment.

test.js Outdated
const err = t.throws(() => {
fixture('unsafe-perm-windows-env-777');
}, Error);
const filepath = path.join('fixture', 'unsafe-perm-env-640', '.env');
Copy link
Owner

Choose a reason for hiding this comment

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

The filepath here doesn't match the fixture that was actually used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oups sorry, went a bit too quick on this one and the previous one as well.

@sholladay sholladay merged commit 9e87558 into sholladay:master Mar 15, 2018
@sholladay
Copy link
Owner

Thanks, @Nargonath! ❤️

Windows support has been released.

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.

2 participants