Fix lint warnings by properly formatting the files

Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
This commit is contained in:
Cosmin Cojocar 2023-12-08 14:30:54 +01:00 committed by Cosmin Cojocar
parent 0e2a61899a
commit 2aad3f02a5
32 changed files with 259 additions and 321 deletions

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeCgo - Cgo file sample
// SampleCodeCgo - Cgo file sample var SampleCodeCgo = []CodeSample{
SampleCodeCgo = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -48,5 +47,4 @@ func main() {
C.printData(cData) C.printData(cData)
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG102 code snippets for network binding
// SampleCodeG102 code snippets for network binding var SampleCodeG102 = []CodeSample{
SampleCodeG102 = []CodeSample{
// Bind to all networks explicitly // Bind to all networks explicitly
{[]string{` {[]string{`
package main package main
@ -102,5 +101,4 @@ func main() {
defer l.Close() defer l.Close()
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG103 find instances of unsafe blocks for auditing purposes
// SampleCodeG103 find instances of unsafe blocks for auditing purposes var SampleCodeG103 = []CodeSample{
SampleCodeG103 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -63,5 +62,4 @@ func main() {
fmt.Printf("ptr: %p\n", ptr) fmt.Printf("ptr: %p\n", ptr)
} }
`}, 2, gosec.NewConfig()}, `}, 2, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG106 - ssh InsecureIgnoreHostKey
// SampleCodeG106 - ssh InsecureIgnoreHostKey var SampleCodeG106 = []CodeSample{
SampleCodeG106 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -16,5 +15,4 @@ func main() {
_ = ssh.InsecureIgnoreHostKey() _ = ssh.InsecureIgnoreHostKey()
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG107 - SSRF via http requests with variable url
// SampleCodeG107 - SSRF via http requests with variable url var SampleCodeG107 = []CodeSample{
SampleCodeG107 = []CodeSample{
{[]string{` {[]string{`
// Input from the std in is considered insecure // Input from the std in is considered insecure
package main package main
@ -194,5 +193,4 @@ func main() {
get(url) get(url)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG108 - pprof endpoint automatically exposed
// SampleCodeG108 - pprof endpoint automatically exposed var SampleCodeG108 = []CodeSample{
SampleCodeG108 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -38,5 +37,4 @@ func main() {
log.Fatal(http.ListenAndServe(":8080", nil)) log.Fatal(http.ListenAndServe(":8080", nil))
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG109 - Potential Integer OverFlow
// SampleCodeG109 - Potential Integer OverFlow var SampleCodeG109 = []CodeSample{
SampleCodeG109 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -110,5 +109,4 @@ func main() {
fmt.Println(b, err) fmt.Println(b, err)
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG110 - potential DoS vulnerability via decompression bomb
// SampleCodeG110 - potential DoS vulnerability via decompression bomb var SampleCodeG110 = []CodeSample{
SampleCodeG110 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -124,5 +123,4 @@ func main() {
} }
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG111 - potential directory traversal
// SampleCodeG111 - potential directory traversal var SampleCodeG111 = []CodeSample{
SampleCodeG111 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -25,5 +24,4 @@ func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG112 - potential slowloris attack
// SampleCodeG112 - potential slowloris attack var SampleCodeG112 = []CodeSample{
SampleCodeG112 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -103,5 +102,4 @@ func main() {
fmt.Print("test") fmt.Print("test")
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG113 - Usage of Rat.SetString in math/big with an overflow
// SampleCodeG113 - Usage of Rat.SetString in math/big with an overflow var SampleCodeG113 = []CodeSample{
SampleCodeG113 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -20,5 +19,4 @@ func main() {
fmt.Println(r) fmt.Println(r)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG114 - Use of net/http serve functions that have no support for setting timeouts
// SampleCodeG114 - Use of net/http serve functions that have no support for setting timeouts var SampleCodeG114 = []CodeSample{
SampleCodeG114 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -69,5 +68,4 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG201 - SQL injection via format string
// SampleCodeG201 - SQL injection via format string var SampleCodeG201 = []CodeSample{
SampleCodeG201 = []CodeSample{
{[]string{` {[]string{`
// Format string without proper quoting // Format string without proper quoting
package main package main
@ -399,5 +398,4 @@ func main() {
defer stmt.Close() defer stmt.Close()
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG202 - SQL query string building via string concatenation
// SampleCodeG202 - SQL query string building via string concatenation var SampleCodeG202 = []CodeSample{
SampleCodeG202 = []CodeSample{
{[]string{` {[]string{`
// infixed concatenation // infixed concatenation
package main package main
@ -280,5 +279,4 @@ func main() {
fmt.Println(result) fmt.Println(result)
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG203 - Template checks
// SampleCodeG203 - Template checks var SampleCodeG203 = []CodeSample{
SampleCodeG203 = []CodeSample{
{[]string{` {[]string{`
// We assume that hardcoded template strings are safe as the programmer would // We assume that hardcoded template strings are safe as the programmer would
// need to be explicitly shooting themselves in the foot (as below) // need to be explicitly shooting themselves in the foot (as below)
@ -88,5 +87,4 @@ func main() {
t.Execute(os.Stdout, v) t.Execute(os.Stdout, v)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG204 - Subprocess auditing
// SampleCodeG204 - Subprocess auditing var SampleCodeG204 = []CodeSample{
SampleCodeG204 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -156,7 +155,8 @@ func RunCmd(command string) {
func main() { func main() {
RunCmd("sleep") RunCmd("sleep")
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig(),
},
{[]string{` {[]string{`
package main package main
@ -242,5 +242,4 @@ func main() {
log.Printf("Command finished with error: %v", err) log.Printf("Command finished with error: %v", err)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,8 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG301 - mkdir permission check // SampleCodeG301 - mkdir permission check
SampleCodeG301 = []CodeSample{ var SampleCodeG301 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -52,5 +52,4 @@ func main() {
} }
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG302 - file create / chmod permissions check
// SampleCodeG302 - file create / chmod permissions check var SampleCodeG302 = []CodeSample{
SampleCodeG302 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -69,5 +68,4 @@ func main() {
} }
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG303 - bad tempfile permissions & hardcoded shared path
// SampleCodeG303 - bad tempfile permissions & hardcoded shared path var SampleCodeG303 = []CodeSample{
SampleCodeG303 = []CodeSample{
{[]string{` {[]string{`
package samples package samples
@ -57,5 +56,4 @@ func main() {
} }
} }
`}, 9, gosec.NewConfig()}, `}, 9, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG304 - potential file inclusion vulnerability
// SampleCodeG304 - potential file inclusion vulnerability var SampleCodeG304 = []CodeSample{
SampleCodeG304 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -303,5 +302,4 @@ package main
var THEWD string var THEWD string
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG305 - File path traversal when extracting zip/tar archives
// SampleCodeG305 - File path traversal when extracting zip/tar archives var SampleCodeG305 = []CodeSample{
SampleCodeG305 = []CodeSample{
{[]string{` {[]string{`
package unzip package unzip
@ -174,5 +173,4 @@ func extractFile(f *tar.Header, tr *tar.Reader, destPath string) error {
return os.Chmod(filePath, f.FileInfo().Mode()) return os.Chmod(filePath, f.FileInfo().Mode())
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG306 - Poor permissions for WriteFile
// SampleCodeG306 - Poor permissions for WriteFile var SampleCodeG306 = []CodeSample{
SampleCodeG306 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -54,5 +53,4 @@ func main() {
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG307 - Poor permissions for os.Create
// SampleCodeG307 - Poor permissions for os.Create var SampleCodeG307 = []CodeSample{
SampleCodeG307 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -45,5 +44,4 @@ func main() {
defer f.Close() defer f.Close()
} }
`}, 1, gosec.Config{"G307": "0o600"}}, `}, 1, gosec.Config{"G307": "0o600"}},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG402 - TLS settings
// SampleCodeG402 - TLS settings var SampleCodeG402 = []CodeSample{
SampleCodeG402 = []CodeSample{
{[]string{` {[]string{`
// InsecureSkipVerify // InsecureSkipVerify
package main package main
@ -294,5 +293,4 @@ func main() {
_ = cryptotls.Config{MinVersion: cryptotls.VersionTLS12} _ = cryptotls.Config{MinVersion: cryptotls.VersionTLS12}
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG403 - weak key strength
// SampleCodeG403 - weak key strength var SampleCodeG403 = []CodeSample{
SampleCodeG403 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -23,5 +22,4 @@ func main() {
fmt.Println(pvk) fmt.Println(pvk)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG404 - weak random number
// SampleCodeG404 - weak random number var SampleCodeG404 = []CodeSample{
SampleCodeG404 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -100,5 +99,4 @@ func main() {
_ = rand3.Intn(2) // bad _ = rand3.Intn(2) // bad
} }
`}, 3, gosec.NewConfig()}, `}, 3, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG501 - Blocklisted import MD5
// SampleCodeG501 - Blocklisted import MD5 var SampleCodeG501 = []CodeSample{
SampleCodeG501 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -20,5 +19,4 @@ func main() {
} }
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG502 - Blocklisted import DES
// SampleCodeG502 - Blocklisted import DES var SampleCodeG502 = []CodeSample{
SampleCodeG502 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -33,5 +32,4 @@ func main() {
fmt.Println("Secret message is: %s", hex.EncodeToString(ciphertext)) fmt.Println("Secret message is: %s", hex.EncodeToString(ciphertext))
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG503 - Blocklisted import RC4
// SampleCodeG503 - Blocklisted import RC4 var SampleCodeG503 = []CodeSample{
SampleCodeG503 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -25,5 +24,4 @@ func main() {
fmt.Println("Secret message is: %s", hex.EncodeToString(ciphertext)) fmt.Println("Secret message is: %s", hex.EncodeToString(ciphertext))
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG504 - Blocklisted import CGI
// SampleCodeG504 - Blocklisted import CGI var SampleCodeG504 = []CodeSample{
SampleCodeG504 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -17,5 +16,4 @@ func main() {
cgi.Serve(http.FileServer(http.Dir("/usr/share/doc"))) cgi.Serve(http.FileServer(http.Dir("/usr/share/doc")))
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG505 - Blocklisted import SHA1
// SampleCodeG505 - Blocklisted import SHA1 var SampleCodeG505 = []CodeSample{
SampleCodeG505 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -20,5 +19,4 @@ func main() {
} }
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
} }
)

View file

@ -2,9 +2,8 @@ package testutils
import "github.com/securego/gosec/v2" import "github.com/securego/gosec/v2"
var ( // SampleCodeG602 - Slice access out of bounds
// SampleCodeG602 - Slice access out of bounds var SampleCodeG602 = []CodeSample{
SampleCodeG602 = []CodeSample{
{[]string{` {[]string{`
package main package main
@ -251,5 +250,4 @@ func main() {
} }
} }
`}, 0, gosec.NewConfig()}, `}, 0, gosec.NewConfig()},
} }
)