Skip to content

Commit c24e6ce

Browse files
Add nosec details
1 parent 506039e commit c24e6ce

5 files changed

Lines changed: 32 additions & 6 deletions

File tree

pkg/chain/ethereum/ethutil/ethutil.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func AddressFromHex(hex string) (common.Address, error) {
3535

3636
// DecryptKeyFile reads in a key file and uses the password to decrypt it.
3737
func DecryptKeyFile(keyFile, password string) (*keystore.Key, error) {
38-
data, err := ioutil.ReadFile(keyFile) // #nosec
38+
// #nosec G304 (file path provided as taint input)
39+
// This line is used to read a local key file. There is no user input.
40+
data, err := ioutil.ReadFile(keyFile)
3941
if err != nil {
4042
return nil, fmt.Errorf("unable to read KeyFile %s [%v]", keyFile, err)
4143
}

pkg/generate/generate.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ func OrganizeImports(codeBuffer *bytes.Buffer, filePath string) error {
3838
// error writing the file.
3939
func SaveBufferToFile(buffer *bytes.Buffer, filePath string) error {
4040
file, err := os.Create(filePath)
41-
defer file.Close() // #nosec
41+
42+
// #nosec G104 (audit errors not checked)
43+
// This line is placed in the auxiliary generator code,
44+
// not in the core application. Also, the Close function returns only
45+
// the error. It doesn't return any other values which can be a security
46+
// threat when used without checking the error.
47+
defer file.Close()
4248
if err != nil {
4349
return fmt.Errorf("output file %s creation failed [%v]", filePath, err)
4450
}

pkg/persistence/disk_persistence.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ func write(filePath string, data []byte) error {
140140

141141
// read a file from a file system
142142
func read(filePath string) ([]byte, error) {
143-
readFile, err := os.Open(filePath) // #nosec
143+
// #nosec G304 (file path provided as taint input)
144+
// This line opens a file from the predefined storage.
145+
// There is no user input.
146+
readFile, err := os.Open(filePath)
144147
if err != nil {
145148
return nil, err
146149
}

tools/generators/ethereum/contract.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ func main() {
6161
contractOutputPath := flag.Arg(1)
6262
commandOutputPath := flag.Arg(2)
6363

64-
abiFile, err := ioutil.ReadFile(abiPath) // #nosec
64+
// #nosec G304 (file path provided as taint input)
65+
// This line is placed in the auxiliary generator code,
66+
// not in the core application. User input has to be passed to
67+
// provide a path to the contract ABI.
68+
abiFile, err := ioutil.ReadFile(abiPath)
6569
if err != nil {
6670
panic(fmt.Sprintf(
6771
"Failed to read ABI file at [%v]: [%v].",
@@ -223,7 +227,13 @@ func organizeImports(outFile string, buf *bytes.Buffer) error {
223227
// Stores the Buffer `buf` content to a file in `filePath`
224228
func saveBufferToFile(buf *bytes.Buffer, filePath string) error {
225229
file, err := os.Create(filePath)
226-
defer file.Close() // #nosec
230+
231+
// #nosec G104 (audit errors not checked)
232+
// This line is placed in the auxiliary generator code,
233+
// not in the core application. Also, the Close function returns only
234+
// the error. It doesn't return any other values which can be a security
235+
// threat when used without checking the error.
236+
defer file.Close()
227237
if err != nil {
228238
return fmt.Errorf("output file %s creation failed [%v]", filePath, err)
229239
}

tools/generators/template/template.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ func main() {
3030
}
3131

3232
templateFile := os.Args[templateFileArgIndex]
33-
templateContents, err := ioutil.ReadFile(templateFile) // #nosec
33+
34+
// #nosec G304 (file path provided as taint input)
35+
// This line is placed in the auxiliary generator code,
36+
// not in the core application. User input has to be passed to provide a
37+
// path to the template file.
38+
templateContents, err := ioutil.ReadFile(templateFile)
3439
if err != nil {
3540
errorAndExit(fmt.Sprintf("Failed to open template file: [%v].", err))
3641
}

0 commit comments

Comments
 (0)