diff --git a/exporter b/exporter new file mode 100755 index 000000000..3dbfc97ab Binary files /dev/null and b/exporter differ diff --git a/monitoring/exporter/main.go b/monitoring/exporter/main.go index e64105af0..3a64e5b65 100644 --- a/monitoring/exporter/main.go +++ b/monitoring/exporter/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "html" "log" "net/http" "strings" @@ -200,12 +201,18 @@ func main() { w.Write([]byte(`Tinode Push

Tinode Push

-
` + msg + `
+
` + html.EscapeString(msg) + `
`)) }) } log.Println("Reading Tinode expvar from", *tinodeAddr) log.Printf("Exporter running at %s. Server type %s", *listenAt, serverTypeString) - log.Fatalln(http.ListenAndServe(*listenAt, nil)) + exporterServer := &http.Server{ + Addr: *listenAt, + ReadHeaderTimeout: 10 * time.Second, + IdleTimeout: 30 * time.Second, + WriteTimeout: 90 * time.Second, + } + log.Fatalln(exporterServer.ListenAndServe()) } diff --git a/server/http.go b/server/http.go index eb77dbabf..8a9fd66cd 100644 --- a/server/http.go +++ b/server/http.go @@ -62,7 +62,15 @@ func listenAndServe(addr string, mux *http.ServeMux, tlfConf *tls.Config, stop < // This is a second HTTP server listenning on a different port. go func() { - if err := http.ListenAndServe(globals.tlsRedirectHTTP, tlsRedirect(addr)); err != nil && err != http.ErrServerClosed { + redirectServer := &http.Server{ + Addr: globals.tlsRedirectHTTP, + Handler: tlsRedirect(addr), + ReadHeaderTimeout: 10 * time.Second, + IdleTimeout: 30 * time.Second, + WriteTimeout: 90 * time.Second, + MaxHeaderBytes: 1 << 14, + } + if err := redirectServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { logs.Info.Println("HTTP redirect failed:", err) } }() diff --git a/server/validate/email/validate.go b/server/validate/email/validate.go index 33c2437aa..cbdf353b8 100644 --- a/server/validate/email/validate.go +++ b/server/validate/email/validate.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "math/big" - "math/rand" "mime" qp "mime/quotedprintable" "net/mail" @@ -19,6 +18,7 @@ import ( "strconv" "strings" textt "text/template" + "time" "slices" @@ -549,7 +549,10 @@ func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { func randomBoundary() string { var buf [24]byte - rand.Read(buf[:]) + if _, err := crand.Read(buf[:]); err != nil { + // Fall back to a time-based boundary on the unlikely event crypto/rand fails. + return fmt.Sprintf("tinode--%x", time.Now().UnixNano()) + } return fmt.Sprintf("tinode--%x", buf[:]) }