mirror of https://github.com/bumi/lntip
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?)
This commit is contained in:
parent
bdd3b70e1f
commit
5d2c9cd639
11
lnme.go
11
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,
|
||||
|
|
Loading…
Reference in New Issue