{"id":22531580,"url":"https://github.com/timkuijsten/node-chroot","last_synced_at":"2025-04-09T16:55:03.572Z","repository":{"id":57198636,"uuid":"11597772","full_name":"timkuijsten/node-chroot","owner":"timkuijsten","description":"Safely chroot the current process and drop privileges","archived":false,"fork":false,"pushed_at":"2022-04-22T00:38:30.000Z","size":43,"stargazers_count":21,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T19:05:52.901Z","etag":null,"topics":["chroot","nodejs","security"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/chroot","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timkuijsten.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-23T02:39:39.000Z","updated_at":"2025-02-01T15:15:22.000Z","dependencies_parsed_at":"2022-09-16T14:11:48.556Z","dependency_job_id":null,"html_url":"https://github.com/timkuijsten/node-chroot","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timkuijsten%2Fnode-chroot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timkuijsten%2Fnode-chroot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timkuijsten%2Fnode-chroot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timkuijsten%2Fnode-chroot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timkuijsten","download_url":"https://codeload.github.com/timkuijsten/node-chroot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248074212,"owners_count":21043479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chroot","nodejs","security"],"created_at":"2024-12-07T08:08:12.359Z","updated_at":"2025-04-09T16:55:03.516Z","avatar_url":"https://github.com/timkuijsten.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chroot\n\nSafely chroot the current process and drop privileges.\n\n## Example\n\nBind a TCP server to a privileged port, chroot and drop privileges to \"wwwuser\".\n\n```js\nvar net = require('net');\nvar chroot = require('chroot');\n\nvar server = net.createServer();\nserver.listen(80, function(err) {\n  if (err) { throw err; }\n\n  try {\n    chroot('/var/empty', 'wwwuser');\n    console.log('changed root to \"/var/empty\" and user to \"wwwuser\"');\n  } catch(err) {\n    console.error('changing root or user failed', err);\n    process.exit(1);\n  }\n});\n```\n\nNote: the process must be started as the super user.\n\n## Installation\n\n    $ npm install chroot\n\n## API\n\n### chroot(newRoot, user, [group])\n* newRoot {String} The path to the new root directory for this process. The\n       whole path should be owned by the super user and may not be writable by\n       the group owner or others.\n* user {String|Number} The user to switch to after changing the root directory.\n       Can be either a name or a numeric id.\n* group {String|Number} The group to switch to after changing the root\n       directory. Can be either a name or a numeric id. If omitted the default\n       is to set all the groups the user is a member of (see /etc/groups) plus\n       the primary group of the user (see /etc/passwd).\n\nChange the root directory of the current process. A normal user must be provided\nsince changing root without dropping privileges makes no sense from a security\npoint of view.\n\n## Notes\n* The current working dir is updated to \"/\".\n* If the environment variable PWD is set, it will be updated to \"/\".\n* Open file descriptors are not closed and environment variables and argv are\n  not cleared, use `child_process.fork()` to accomplish that.\n\n## General chroot notes\nChrooting a program is not a security solution. It is only one aspect of the\nmuch broader principle of least privilege. When done right it can be used as a\nmitigation to seriously hinder a compromised process in further compromising the\nsystem. Keep the following things in mind when setting up and using a chroot:\n\n* Anything that is stored in the chroot can be used against you. Use an empty\n  non-writable directory if possible.\n* Include modules before chrooting.\n* Create a separate user account used only for running the chrooted process.\n* Use child_process.fork() to clear the environment and close file descriptors.\n\nFurther reading:\n* [http://www.unixwiz.net/techtips/chroot-practices.html](http://www.unixwiz.net/techtips/chroot-practices.html)\n* [http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/minimize-privileges.html](http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/minimize-privileges.html)\n\n## License\n\nISC\n\nCopyright (c) 2014, 2015, 2021 Tim Kuijsten\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimkuijsten%2Fnode-chroot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimkuijsten%2Fnode-chroot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimkuijsten%2Fnode-chroot/lists"}