0

I was reading on race conditions when I encountered the paragraph below:

Race conditions

How exactly does trying to read a non-existing file cause a security vulnerability?

1 Answers1

1

TOCTOU

1    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!

  • Reading and publishing secret files or
  • Writing, then altering crucial files...