SONARGO-393 Modify rule S4423 for Go: remove examples for HTTP servers (#4726)
This commit is contained in:
parent
c9e1585367
commit
e7c5865c64
@ -28,25 +28,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
For HTTP servers:
|
|
||||||
|
|
||||||
[source,go,diff-id=2,diff-type=noncompliant]
|
|
||||||
----
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
w.Write([]byte("Hello world!\n"))
|
|
||||||
})
|
|
||||||
err := http.ListenAndServeTLS(":443", "tls.crt", "tls.key", nil) // Noncompliant: TLS 1.0 by default for servers
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
----
|
|
||||||
|
|
||||||
==== Compliant solution
|
==== Compliant solution
|
||||||
|
|
||||||
For HTTP clients:
|
For HTTP clients:
|
||||||
@ -67,35 +48,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
For HTTP servers:
|
|
||||||
|
|
||||||
[source,go,diff-id=2,diff-type=compliant]
|
|
||||||
----
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
w.Write([]byte("Hello world!\n"))
|
|
||||||
})
|
|
||||||
cfg := &tls.Config{
|
|
||||||
MinVersion: tls.VersionTLS12,
|
|
||||||
}
|
|
||||||
srv := &http.Server{
|
|
||||||
Addr: ":443",
|
|
||||||
Handler: mux,
|
|
||||||
TLSConfig: cfg,
|
|
||||||
}
|
|
||||||
err := srv.ListenAndServeTLS("tls.crt", "tls.key")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
=== How does this work?
|
=== How does this work?
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user