I was reading on race conditions when I encountered the paragraph below:
How exactly does trying to read a non-existing file cause a security vulnerability?
Information Security Stack Exchange is a question and answer site for information security professionals. It only takes a minute to sign up.
Sign up to join this community1 let exists = await fs.access(path_to_file) # FS test 2 if (exists) { # Program test 3 const data = await fs.readFile(path_to_file) # Access file 4 ... 5 }
Between line 1
where the filesystem check is done and line 3
where the file is opened, there is a gap.
For example: An attacker could uses this gap for dropping path_to_file
and creates a symlink to /etc/passwd
, your program will access the wrong file!!
More explanations: Time-of-check to time-of-use at Wikipedia
How exactly does trying to read a non-existing file cause a security vulnerability?
Depending on your object and flaws, TOCTOU could be used as well in read and in write mode!