This java method has the following signature:
The first two arguments do not affect security of the created file.
In Linux, files and directories are different entities, they have their own permissions and are isolated from other files and directories.
Protections you apply to the directory
do not affect the files inside of it.
if I protect the directory
I can prevent an attacker
from executing the
but nothing impedes the attacker
To prevent access to the file we must protect the file, not the directory.
Additionally, we make sure that permissions are set atomically. If we do not, the following situation can happen:
- At moment A we
- At moment B we add secure permissions to the file.
After moment B the file is secured. However, between moment A and moment B the file has insecure permissions and an attacker had enough opportunity to get control over it.
java.io.File.createTempFile method creates files
with write permissions in groups and other:
- Use the
attrsargument (an optional list of file attributes to set atomically when creating the file).