Skip to content

Commit

Permalink
use fs.lchown rather than fs.chown and thereby fix isaacs#14
Browse files Browse the repository at this point in the history
fixes the symlinks problem isaacs#3 while not causing the TOCTOU vulnerability isaacs#14

The [patch in libuv 1.21.0](https://github.com/libuv/libuv/releases/tag/v1.21.0) that undeprecates `fs.lchown` [has been incorporated in nodejs Version 10.6.0](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V10.md#2018-07-04-version-1060-current-targos).

So I specified the minimum nodejs version in `package.json` with the `engine` key: https://docs.npmjs.com/files/package.json#engines
  • Loading branch information
Paolo Greppi committed Aug 10, 2018
1 parent c6c4384 commit 3bd6861
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
11 changes: 2 additions & 9 deletions chownr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ function chownr (p, uid, gid, cb) {
, errState = null
children.forEach(function (child) {
var pathChild = path.resolve(p, child);
fs.lstat(pathChild, function(er, stats) {
if (er)
return cb(er)
if (!stats.isSymbolicLink())
chownr(pathChild, uid, gid, then)
else
then()
})
chownr(pathChild, uid, gid, then)
})
function then (er) {
if (errState) return
if (er) return cb(errState = er)
if (-- len === 0) return fs.chown(p, uid, gid, cb)
if (-- len === 0) return fs.lchown(p, uid, gid, cb)
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"scripts": {
"test": "tap test/*.js"
},
"license": "ISC"
"license": "ISC",
"engines": { "node" : ">=10.6.0" }
}

0 comments on commit 3bd6861

Please sign in to comment.