Skip to content

Commit

Permalink
Fix gosec vulnerabilities: file and directory permissions (#142)
Browse files Browse the repository at this point in the history
- Fix G301: Poor file permissions used when creating a directory.
- Fix G306: Poor file permissions used when writing to a new file.

See https://github.com/securego/gosec#available-rules
  • Loading branch information
kl09 committed Dec 13, 2020
1 parent 0d9680f commit b052143
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func run(flags userFlags) error {
}

// create the file
err = os.MkdirAll(filepath.Dir(flags.outFile), 0755)
err = os.MkdirAll(filepath.Dir(flags.outFile), 0750)
if err != nil {
return err
}

return ioutil.WriteFile(flags.outFile, buf.Bytes(), 0644)
return ioutil.WriteFile(flags.outFile, buf.Bytes(), 0600)
}
2 changes: 1 addition & 1 deletion pkg/moq/moq_modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// copy copies srcPath to destPath, dirs and files
func copy(srcPath, destPath string, item os.FileInfo) error {
if item.IsDir() {
if err := os.MkdirAll(destPath, os.FileMode(0755)); err != nil {
if err := os.MkdirAll(destPath, os.FileMode(0750)); err != nil {
return err
}
items, err := ioutil.ReadDir(srcPath)
Expand Down
4 changes: 2 additions & 2 deletions pkg/moq/moq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ func matchGoldenFile(goldenFile string, actual []byte) error {
// To update golden files, run the following:
// go test -v -run '^<Test-Name>$' github.com/matryer/moq/pkg/moq -update
if *update {
if err := os.MkdirAll(filepath.Dir(goldenFile), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(goldenFile), 0750); err != nil {
return fmt.Errorf("create dir: %s", err)
}
if err := ioutil.WriteFile(goldenFile, actual, 0644); err != nil {
if err := ioutil.WriteFile(goldenFile, actual, 0600); err != nil {
return fmt.Errorf("write: %s", err)
}

Expand Down

0 comments on commit b052143

Please sign in to comment.