-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
accessSync not throwing error when no permissions in Windows 11 #44010
Comments
Because So if the issue continues with |
@WillianAgostini sorry for being unclear, my issue only occurs with test.mjs import { access, accessSync, constants } from 'fs'
await access('C://Windows', constants.W_OK, () => console.error(`Cannot write (access)`))
try { accessSync('C://Windows', constants.W_OK) }
catch (e) { console.error('Cannot write (accessSync)') } Expected output:
Actual output
I initially had this issue in 16.9.0 but I assumed that my version may have been outdated so I updated to 18.7.0 |
I think because the process have the write permission on |
@theanarkh When running your snippet I end up with no output. I know my process does not have write permissions on writeFileSync('C://Windows/test.txt', 'test') I am given the expected
|
What does "no permissions" mean? Keep in mind access() is not aware of Windows ACLs. |
@bnoordhuis clearly it is aware of the process' permissions to some degree if My issue is with |
That was already pointed out by the @theanarkh - your asynchronous version has a bug. The other part of the story is that access() and accessSync() don't know about Windows ACLs and report success when the ACL will in fact block access. Having said that, if you're using access() (whether sync or async) to determine whether you can write to a location, you're doing it wrong - just try to write and handle the error. Look up TOCTOU bugs. |
@bnoordhuis Hmm thanks for the info, I've been using that alternative regardless. I've just reread the docs on Would I be correct to say that try {
accessSync('etc/passwd', constants.R_OK | constants.W_OK);
console.log('can read/write');
} catch (err) {
console.error('no access!');
} although a similar Windows translation could be try {
accessSync('C:\\Windows\\System32\\cmd.exe', constants.R_OK | constants.W_OK);
console.log('can read/write');
} catch (err) {
console.error('no access!');
} which does not produce the same behavior. TL;DR
|
It has already been discussed on #2949 (comment). |
Exactly. I'll close this out but to answer two of OP's questions:
It is.
TOCTOU - the ACL can change after the check. More generally, you can't really know what ACL applies until you actually try it. |
Version
v18.7.0
Platform
Microsoft Windows NT 10.0.25158.0 x64
Subsystem
fs
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Reproduces 100% of the time
What is the expected behavior?
The expected behavior was to throw an
EPERM
errorWhat do you see instead?
Returns
undefined
and doesn't throw an error like expected.Additional information
No response
The text was updated successfully, but these errors were encountered: