2023-11-25 22:51:38 +00:00
|
|
|
package testutils
|
|
|
|
|
|
|
|
import "github.com/securego/gosec/v2"
|
|
|
|
|
2023-12-08 13:30:54 +00:00
|
|
|
// SampleCodeG114 - Use of net/http serve functions that have no support for setting timeouts
|
|
|
|
var SampleCodeG114 = []CodeSample{
|
|
|
|
{[]string{`
|
2023-11-25 22:51:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := http.ListenAndServe(":8080", nil)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
`}, 1, gosec.NewConfig()},
|
2023-12-08 13:30:54 +00:00
|
|
|
{[]string{`
|
2023-11-25 22:51:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
`}, 1, gosec.NewConfig()},
|
2023-12-08 13:30:54 +00:00
|
|
|
{[]string{`
|
2023-11-25 22:51:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
l, err := net.Listen("tcp", ":8080")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer l.Close()
|
|
|
|
err = http.Serve(l, nil)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
`}, 1, gosec.NewConfig()},
|
2023-12-08 13:30:54 +00:00
|
|
|
{[]string{`
|
2023-11-25 22:51:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
l, err := net.Listen("tcp", ":8443")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer l.Close()
|
|
|
|
err = http.ServeTLS(l, nil, "cert.pem", "key.pem")
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
`}, 1, gosec.NewConfig()},
|
2023-12-08 13:30:54 +00:00
|
|
|
}
|