fix: use net.JoinHostPort for joining acme host and port (#13367)

- adjusted the starting for the acme HTTP handler to use `net.JoinHostPort` to join host and port
- Resolves #12274
- I tested on my server which only had ipv6 enabled.
  - Log message before fix: `...s/graceful/server.go:76:ListenAndServe() [E] Unable to GetListener: address [[::]:443]:443: too many colons in address`
  - Log message after fix: `...s/graceful/server.go:50:NewServer() [I] Starting new Let's Encrypt HTTP Challenge server: tcp:[::]:80 on PID: 31302`

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13367
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Florian Lang 2026-07-09 15:45:33 +02:00 committed by Gusted
commit 37c2131508

View file

@ -7,6 +7,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"net"
"net/http"
"os"
"strconv"
@ -122,9 +123,11 @@ func runACME(listenAddr string, m http.Handler) error {
_, _, finished := process.GetManager().AddTypedContext(graceful.GetManager().HammerContext(), "Web: ACME HTTP challenge server", process.SystemProcessType, true)
defer finished()
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
acmeListenAddr := net.JoinHostPort(setting.HTTPAddr, setting.PortToRedirect)
log.Info("Running Let's Encrypt handler on %s", acmeListenAddr)
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
err := runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)), setting.RedirectorUseProxyProtocol)
err := runHTTP("tcp", acmeListenAddr, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)), setting.RedirectorUseProxyProtocol)
if err != nil {
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
}