Go

Go

Made by DeepSource

Poor file permissions used when creating a file or using os.Chmod GSC-G302

Security
Major
a05 cwe-276 owasp top 10

Excessive permissions granted to a file/directory. This warning is triggered whenever permission greater than 0600 is granted.

Generally, all security rules follow the principle of least privilege, except when the file being created needs to be accessed by anyone other than the user creating it.

Bad practice

package main

import (
    "fmt"
    "os"
)

func main() {
    err := os.Chmod("/tmp/somefile", 0777)
    if err != nil {
        fmt.Println("Error when changing file permissions!")
        return
    }
}

Recommended

package main

import (
    "fmt"
    "os"
)

func main() {
    err := os.Chmod("/tmp/mydir", 0400)
    if err != nil {
        fmt.Println("Error")
        return
    }
}

References