Do not create a file with too much permissions

This page is not yet available in Spanish. We are working on its translation.
If you have any questions or feedback about our current translation project, feel free to reach out to us!

Metadata

ID: go-security/write-file-permissions

Language: Go

Severity: Warning

Category: Security

CWE: 284

Description

Granting write access to a file is a security since other users can modify the content of the file. The issue is amplified for executable files that can be easily compromised (like scripts). Avoid giving write permissions to others to files.

Learn More

Non-Compliant Code Examples

package main

import (
	"fmt"
	"os"
)

func main() {
	d1 := []byte("something somethingn")
	err := ioutil.WriteFile("myfile", d1, 0777)
	check(err)
}

Compliant Code Examples

package main

import (
	"fmt"
	"os"
)

func main() {
	d1 := []byte("something somethingn")
	err := ioutil.WriteFile("myfile", d1, 0770)
	check(err)
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis