-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
security,unix: audit use of process.env in lib/ for setuid binary #9160
Comments
Previously, a user could read environment variables even if the real uid/gid did not match the effective uid/gid. This change will make process.env.* return undefined in that case. Ref: nodejs#9160
@bnoordhuis are you thinking that we should disable reading all environment variables or certain ones? |
Good question. Variables like NODE_DISABLE_COLORS are probably safe but I wouldn't oppose a blanket ban. |
@bnoordhuis @evanlucas Should this remain open? If so, should we add a |
I would like to take this as my second contribution, is this possible?. I'm currently checking os and module code. I'll come back as soon as I'm more comfortable with that. |
@j0t3x Let me know what you find or if you have questions. |
@bnoordhuis between vacations and family I was unable to start the work earlier. So sorry for the delay. Please let me know if I'm understanding this correctly. Here goes the problem: Possible solution: build a function to check for the match, but where should this function go, utils? About the env variables, in which cases is it necessary to disable all/some? Thanks to all in advance. |
One solution is to add a method to |
Hi @bnoordhuis, Coming back after some research time. Here are some questions: For the method i need to understand a little bit more how exactly will be used: For example, Should i throw an error if the env var is banned? Thanks in advance. |
@bnoordhuis I already have it implemented in c++, to make the js part, I need your help with this questions :D Thanks in advance. |
Missed your ping, sorry.
That's a policy question that we haven't really decided on. Could be judged on a case-by-case basis or simply by issuing a blanket ban. Since you're working on it, you get to make the call. Maybe someone will flag it during review but we'll cross that bridge when we get to it.
No, just ignore it as if it isn't set. (edit: that's how |
C++ Thanks! |
Hi @bnoordhuis , After just exposing to jsland the already existent c++
here are some comments & questions about it: Apparently, and this is something I need to understand, there are some env vars not accessed through For the errors in tests, my main problem is that instead of using system declared env vars for the test cases, user constructed env vars are used. I need to further understand why is this the case because if I go directly to system declared env vars in I found one annotation by @addaleax in
is this related to this issue? what does this mean? Thanks in advance for your great help. |
That said, adding a suid check to those functions is probably too slow; people already complain about the overhead in applications that check |
No, it’s completely unrelated. What it means is that on Windows, using
|
First of all, thanks to both of you for your help. I'm ready for the pr now. === release test-inspector-break-when-eval === Path: sequential/test-inspector-break-when-eval [test] Connecting to a child Node process [test] Testing /json/list [err] Debugger listening on ws://127.0.0.1:64630/deb4b9ce-e4bc-4e72-b650-729603fd9c45 [err] For help see https://nodejs.org/en/docs/inspector [err] [err] Debugger attached. [err] [test] Setting up a debugger [test] Breaking in the code [out] Ready! [out] Timed out waiting for matching notification (break on /Users/tex/Documents/repos/node/test/fixtures/inspector-global-function.js:9)) 1 Command: out/Release/node /Users/tex/Documents/repos/node/test/sequential/test-inspector-break-when-eval.js Thanks again for the great and quick help. |
Can you check |
@bnoordhuis |
@j0t3x Can you back out any changes you made to |
@bnoordhuis there's no error in tests now, I'm going to start the pr. Thanks for the help. |
To really close this out we'll also need to devise something for the getenv/setenv/etc. calls in our dependencies. We could perhaps exploit weak symbols or build our deps with |
Wrap SafeGetenv() in util binding with the purpose of protecting the cases when env vars are accessed with the privileges of another user in jsland. PR-URL: nodejs#18511 Fixes: nodejs#9160 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Wrap SafeGetenv() in util binding with the purpose of protecting the cases when env vars are accessed with the privileges of another user in jsland. PR-URL: nodejs#18511 Fixes: nodejs#9160 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Functions like
os.tmpdir()
andModule._initPaths()
use file paths from environment variables.This is unsafe when the node binary has the setuid bit set - i.e., when it runs with the privileges of a different user (usually root) than the user executing it - because it can be used to read or write files that otherwise wouldn't be accessible.
On the C++ side we have
secure_getenv()
which checks that the real uid and gid match the effective uid and gid before accessing an environment variable. Perhaps we need something similar for JS land.Caveat emptor: our implementation of- edit 20171221: it does now and it's been renamed tosecure_getenv()
does not take Linux process capabilities into consideration but neither does glibc's, as far as I can tell.SafeGetenv()
.The text was updated successfully, but these errors were encountered: