Permission logic in fs.open(), fs.openSync(), and fsPromises.open() can easily be bypassed #47090
Labels
confirmed-bug
Issues with confirmed bugs.
fs
Issues and PRs related to the fs subsystem / file system.
permission
Issues and PRs related to the Permission Model
security
Issues and PRs related to security.
The permission logic in these functions seems flawed. Using
fs.open()
orfs.openSync()
, both read and write restrictions can easily be bypassed simply by passing extra flags. Some examples:O_RDWR | 0x10000000
gives both read and write access - regardless of any restrictions.O_RDONLY | O_NOCTTY
gives read access - even if all file system access has been blocked.O_RDONLY | O_TEMPORARY
allows deleting files on Windows - even without write access.fsPromises.open()
contains similarly obvious flaws, but it also contains a mostly redundant (and likely also incorrect) check that always requires read permission, even if opening in a write-only mode. Still, as long as read permission is granted, code can open the file for writing using, for example,O_RDWR | O_NOFOLLOW
.Overall, this combination of multiple logical flaws trivially allows arbitrary read and write access to any file, even when access should be restricted.
I'm opening this as a public issue because the feature hasn't been released yet due to the previous vulnerability that was found by @cjihrig (see #46975 (comment)).
The flawed validation logic is implemented here:
node/src/node_file.cc
Lines 1968 to 1982 in 334bb17
The incorrect and/or redundant additional check in
fsPromises.open()
is implemented here:node/src/node_file.cc
Lines 2014 to 2015 in 334bb17
Followed by the same validation logic as above:
node/src/node_file.cc
Lines 2023 to 2037 in 334bb17
The text was updated successfully, but these errors were encountered: