A file is given permissions that let every user of the machine change or read it
What it finds
PosixFilePermissions.fromString("rwxrwxrwx") and file.setWritable(true, false) let every user of the machine change the file, and setReadable(true, false) or r--r--r-- with secrets in the file lets them read it (CWE-732). Permissions for the owner, and the group where needed, are usually enough.
Reported are permission strings that give others write access, the constant PosixFilePermission.OTHERS_WRITE among the elements of Set.of or EnumSet.of, and setWritable, setReadable and setExecutable with true and ownerOnly set to false.
From the rule's source, world_writable_file.rs.
import java.io.File;import java.nio.file.attribute.PosixFilePermissions; class Perms { void set(File f) { PosixFilePermissions.fromString("rwxrwxrwx");tx0 reports: rwxrwxrwx lets every user of the machine change the file PosixFilePermissions.fromString("rw-r-----"); f.setWritable(true, false);tx0 reports: setWritable with ownerOnly set to false applies to every user f.setWritable(true, true); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:world-writable-file" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:world-writable-file] reason="..."tx0 explain tx0/java:world-writable-file shows the same in the terminal. Found a false positive? Report it.