Skip to content

Commit

Permalink
Reduce permissions for file created according to CWE-276 (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo authored Oct 6, 2024
1 parent 3dfca2a commit 521033d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/egnkey/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func createDir(c *cli.Context, prefix string) (fileName string, err error) {
// Clean the path
cleanFilePath := filepath.Clean(folder + "/" + DefaultKeyFolder)

err = os.MkdirAll(cleanFilePath, 0755)
err = os.MkdirAll(cleanFilePath, 0750)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/bls/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func (k *KeyPair) SaveToFile(path string, password string) error {
}

dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0755); err != nil {
if err := os.MkdirAll(dir, 0750); err != nil {
fmt.Println("Error creating directories:", err)
return err
}
err = os.WriteFile(path, data, 0644)
err = os.WriteFile(path, data, 0600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/ecdsa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func writeBytesToFile(path string, data []byte) error {
dir := filepath.Dir(path)

// create the directory if it doesn't exist. If exists, it does nothing
if err := os.MkdirAll(dir, 0755); err != nil {
if err := os.MkdirAll(dir, 0750); err != nil {
fmt.Println("Error creating directories:", err)
return err
}
Expand Down

0 comments on commit 521033d

Please sign in to comment.