From 5d2c9cd639298c95b02de6a8a5333359216cd524 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Fri, 6 May 2022 20:30:35 +0200 Subject: [PATCH] Fix: use correct header to get the original request host Proxy servers can set the X-Forwarded-Host and X-Forwarded-Proto headers to pass on the original host and protocol. We should also support the Forwarded header (which combines this in one header described in RFC7239 - but seems echo does not support parsing that one?) --- lnme.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lnme.go b/lnme.go index 0f1502a..08f5b83 100644 --- a/lnme.go +++ b/lnme.go @@ -152,9 +152,14 @@ func main() { if !cfg.Bool("disable-ln-address") { lnurlHandler := func(c echo.Context) error { host := c.Request().Host - if c.Request().Header.Get(echo.HeaderXForwardedFor) != "" { - host = c.Request().Header.Get(echo.HeaderXForwardedFor) + proto := c.Scheme() + // TODO: support RFC7239 Forwarded header + if c.Request().Header.Get("X-Forwarded-Host") != "" { + host = c.Request().Header.Get("X-Forwarded-Host") } + if c.Request().Header.Get("X-Forwarded-Proto") != "" { + proto = c.Request().Header.Get("X-Forwarded-Proto") + } name := c.Param("name") lightningAddress := name + "@" + host lnurlMetadata := "[[\"text/identifier\", \"" + lightningAddress + "\"], [\"text/plain\", \"Sats for " + lightningAddress + "\"]]" @@ -162,7 +167,7 @@ func main() { if amount := c.QueryParam("amount"); amount == "" { lnurlPayResponse1 := lnurl.LNURLPayResponse1{ LNURLResponse: lnurl.LNURLResponse{Status: "OK"}, - Callback: fmt.Sprintf("%s://%s%s", c.Scheme(), host, c.Request().URL.Path), + Callback: fmt.Sprintf("%s://%s%s", proto, host, c.Request().URL.Path), MinSendable: 1000, MaxSendable: 100000000, EncodedMetadata: lnurlMetadata,