The mode of a file is changed to one that lets every user write to it

tx0/go:world-writable-filerecommendedwarningsecurity, cwe-732

What it finds

os.Chmod(path, 0o777): with the write bit for others set, any account on the machine can change the file, or add and replace files in the directory. Unlike the modes given when a file is created, which the process's umask reduces, a mode set by Chmod applies as it is. Files usually need 0o644 or 0o600, directories 0o755 or 0o700.

The mode must be an integer literal with the bit 0o002 set, passed to os.Chmod, resolved through the imports. Modes such as 0o666 given to os.WriteFile or os.MkdirAll are left alone, since the umask is meant to decide there.

From the rule's source, world_writable_file.rs.

Example from the rule's tests
package p import "os" func f(path string, data []byte) error {	if err := os.Chmod(path, 0777); err != nil {tx0 reports: os.Chmod with mode 0o777 lets every user write		return err	}	if err := os.MkdirAll(path, 0o777); err != nil {		return err	}	if err := os.Chmod(path, 0o644); err != nil {		return err	}	return os.WriteFile(path, data, 0o600)}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/go: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/go:world-writable-file] reason="..."

tx0 explain tx0/go:world-writable-file shows the same in the terminal. Found a false positive? Report it.