fs module's file watching is not restricted by --allow-fs-read
The Node.js permission system's read restriction did not cover file watching, so a script without read access could still monitor a file. An attacker could therefore learn when a file they should not be able to read was modified.
- Triaged in 18 hours
- Fixed in 52 days
- Disclosed after 3 months
Summary: [add summary of the vulnerability]
The --allow-fs-read flag of the permission system does not prevent file watching.
Description: [add more details about this vulnerability] Attackers can watch files that they don't have read access to.
Steps To Reproduce:
Run the following code with --experimental-permission and do not grant read access to file.txt. Modify file.txt in another process. Information is leaked to the attacker about a file they should not have access to.
'use strict';
const fs = require('node:fs');
async function main() {
fs.watchFile(__dirname + '/file.txt', () => {
console.log('able to watch a file without any permissions');
});
}
main();
Impact: [add why this issue matters]
The permission system is bypassed. Attackers can receive events related to files they do not have access to.
Supporting Material/References:
None
Impact
The permission system is bypassed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the permission check was applied to file read operations but not to the file watching API, leaving that path unchecked.
Impact
The permission system could be bypassed, letting an attacker receive events about files they do not have access to.
What the attacker needed
Experimental permission system enabled; attacker can run a script under it
How it was found
- Run a script with the experimental permission flag and no read access to the target file.
- Have the script watch that file for changes.
- Modify the file from another process.
- Observe that the watching script receives change events despite lacking read permission.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Node.js has an optional permission system that lets you say which files a script may read. This report shows that one file-related feature, watching a file for changes, was not covered by that restriction. So a script could still be told when a file changed even though it was not allowed to read the file.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.