Exploit databaseDownload repository ZIP
GH-f0a9bb99064fc5c640a8aca726a5dee3
actions-marketplace-validations/securego_gosec
Sources for CVE-2022-23772
3 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files69
actions-marketplace-validations/securego_gosecRevision a3d5223361a5
- ↑..Parent directory
- build_samples.go
- cgo_samples.go
- deps_test.go
- g101_samples.go
- g102_samples.go
- g103_samples.go
- g104_samples.go
- g106_samples.go
- g107_samples.go
- g108_samples.go
- g109_samples.go
- g110_samples.go
- g111_samples.go
- g112_samples.go
- g113_samples.go
- g114_samples.go
- g115_samples.go
- g116_samples.go
- g117_samples.go
- g118_samples.go
- g119_samples.go
- g120_samples.go
- g121_samples.go
- g122_samples.go
- g123_samples.go
- g124_samples.go
- g125_samples.go
- g201_samples.go
- g202_samples.go
- g203_samples.go
- g204_samples.go
- g301_samples.go
- g302_samples.go
- g303_samples.go
- g304_samples.go
- g305_samples.go
- g306_samples.go
- g307_samples.go
- g401_samples.go
- g402_samples.go
- g403_samples.go
- g404_samples.go
- g405_samples.go
- g406_samples.go
- g407_samples.go
- g408_samples.go
- g501_samples.go
- g502_samples.go
- g503_samples.go
- g504_samples.go
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
testutils/g104_samples.go
Go · 4,445 bytespackage testutils
import "github.com/securego/gosec/v2"
var (
// SampleCodeG104 finds errors that aren't being handled
SampleCodeG104 = []CodeSample{
{[]string{`
package main
import "fmt"
func test() (int,error) {
return 0, nil
}
func main() {
v, _ := test()
fmt.Println(v)
}
`}, 0, gosec.NewConfig()},
{[]string{`
package main
import (
"io/ioutil"
"os"
"fmt"
)
func a() error {
return fmt.Errorf("This is an error")
}
func b() {
fmt.Println("b")
ioutil.WriteFile("foo.txt", []byte("bar"), os.ModeExclusive)
}
func c() string {
return fmt.Sprintf("This isn't anything")
}
func main() {
_ = a()
a()
b()
c()
}
`}, 2, gosec.NewConfig()},
{[]string{`
package main
import "fmt"
func test() error {
return nil
}
func main() {
e := test()
fmt.Println(e)
}
`}, 0, gosec.NewConfig()},
{[]string{`
// +build go1.10
package main
import "strings"
func main() {
var buf strings.Builder
_, err := buf.WriteString("test string")
if err != nil {
panic(err)
}
}`, `
package main
func dummy(){}
`}, 0, gosec.NewConfig()},
{[]string{`
package main
import (
"bytes"
)
type a struct {
buf *bytes.Buffer
}
func main() {
a := &a{
buf: new(bytes.Buffer),
}
a.buf.Write([]byte{0})
}
`}, 0, gosec.NewConfig()},
{[]string{`
package main
import (
"io/ioutil"
"os"
"fmt"
)
func a() {
fmt.Println("a")
ioutil.WriteFile("foo.txt", []byte("bar"), os.ModeExclusive)
}
func main() {
a()
}
`}, 0, gosec.Config{"G104": map[string]interface{}{"ioutil": []interface{}{"WriteFile"}}}},
{[]string{`
package main
import (
"bytes"
"fmt"
"io"
"os"
"strings"
)
func createBuffer() *bytes.Buffer {
return new(bytes.Buffer)
}
func main() {
new(bytes.Buffer).WriteString("*bytes.Buffer")
fmt.Fprintln(os.Stderr, "fmt")
new(strings.Builder).WriteString("*strings.Builder")
_, pw := io.Pipe()
pw.CloseWithError(io.EOF)
createBuffer().WriteString("*bytes.Buffer")
b := createBuffer()
b.WriteString("*bytes.Buffer")
}
`}, 0, gosec.NewConfig()},
{[]string{`
package main
import "crypto/rand"
func main() {
b := make([]byte, 8)
rand.Read(b)
_ = b
}
`}, 0, gosec.NewConfig()},
{[]string{`
package main
import (
crand "crypto/rand"
f "fmt"
"os"
)
func main() {
b := make([]byte, 8)
crand.Read(b)
f.Fprintln(os.Stderr, "renamed imports")
}
`}, 0, gosec.NewConfig()},
{[]string{`
package main
import (
iou "io/ioutil"
"os"
)
func main() {
iou.WriteFile("foo.txt", []byte("bar"), os.ModeExclusive)
}
`}, 0, gosec.Config{"G104": map[string]interface{}{"ioutil": []interface{}{"WriteFile"}}}},
{[]string{`
package main
import (
crand "crypto/rand"
o "os"
)
type reader struct{}
func (reader) Read(b []byte) error { return nil }
var _ = crand.Reader
func main() {
b := make([]byte, 8)
rand := reader{}
rand.Read(b)
crand := reader{}
crand.Read(b)
o.Remove("foo.txt")
}
`}, 3, gosec.NewConfig()},
} // it shouldn't return any errors because all method calls are whitelisted by default
// SampleCodeG104Audit finds errors that aren't being handled in audit mode
SampleCodeG104Audit = []CodeSample{
{[]string{`
package main
import "fmt"
func test() (int,error) {
return 0, nil
}
func main() {
v, _ := test()
fmt.Println(v)
}
`}, 1, gosec.Config{gosec.Globals: map[gosec.GlobalOption]string{gosec.Audit: "enabled"}}},
{[]string{`
package main
import (
"io/ioutil"
"os"
"fmt"
)
func a() error {
return fmt.Errorf("This is an error")
}
func b() {
fmt.Println("b")
ioutil.WriteFile("foo.txt", []byte("bar"), os.ModeExclusive)
}
func c() string {
return fmt.Sprintf("This isn't anything")
}
func main() {
_ = a()
a()
b()
c()
}
`}, 3, gosec.Config{gosec.Globals: map[gosec.GlobalOption]string{gosec.Audit: "enabled"}}},
{[]string{`
package main
import "fmt"
func test() error {
return nil
}
func main() {
e := test()
fmt.Println(e)
}
`}, 0, gosec.Config{gosec.Globals: map[gosec.GlobalOption]string{gosec.Audit: "enabled"}}},
{[]string{`
// +build go1.10
package main
import "strings"
func main() {
var buf strings.Builder
_, err := buf.WriteString("test string")
if err != nil {
panic(err)
}
}
`, `
package main
func dummy(){}
`}, 0, gosec.Config{gosec.Globals: map[gosec.GlobalOption]string{gosec.Audit: "enabled"}}},
{[]string{`
package main
import crand "crypto/rand"
func main() {
b := make([]byte, 8)
_, _ = crand.Read(b)
}
`}, 0, gosec.Config{gosec.Globals: map[gosec.GlobalOption]string{gosec.Audit: "enabled"}}},
}
)