Fix LNURL onion detection and go vet findings

A five-character domain was treated as an onion address (strings.Index
returned -1 == len-6) and the lnurlp:// scheme check tested an empty
string. Also: wrong format verb in the AnonID migration log, an error
that was built but never logged, an unreachable return, and the message
log line was passed as a format string.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-13 20:50:26 +00:00
co-authored by Claude Fable 5.1
parent 8514341118
commit 7268fe6d31
5 changed files with 6 additions and 7 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ func MigrateAnonIdInt32Hash(db *gorm.DB) error {
users := []lnbits.User{}
_ = db.Find(&users)
for _, u := range users {
log.Infof("[MigrateAnonIdInt32Hash] %d -> %d", u.ID, str.Int32Hash(u.ID))
log.Infof("[MigrateAnonIdInt32Hash] %s -> %d", u.ID, str.Int32Hash(u.ID))
u.AnonID = fmt.Sprint(str.Int32Hash(u.ID))
tx := db.Save(u)
if tx.Error != nil {
+1 -1
View File
@@ -289,7 +289,7 @@ func (w Lnurl) serveLNURLpSecond(username string, amount_msat int64, comment str
// get user settings
user2, err := db.FindUserSettings(user, w.bot.DB.Users.Preload("Settings"))
if err != nil {
fmt.Errorf("[serveLNURLpSecond] Couldn't fetch user settings from database: %v", err)
log.Errorf("[serveLNURLpSecond] Couldn't fetch user settings from database: %v", err)
} else {
user = user2
}
+1 -1
View File
@@ -232,7 +232,7 @@ func (bot TipBot) logMessageInterceptor(ctx intercept.Context) (intercept.Contex
if ctx.Message().IsReply() {
log_string = fmt.Sprintf("%s -> %s", log_string, GetUserStr(ctx.Message().ReplyTo.Sender))
}
log.Infof(log_string)
log.Info(log_string)
} else if ctx.Message().Photo != nil {
log.Infof("[%s:%d %s:%d] %s", ctx.Message().Chat.Title, ctx.Message().Chat.ID, GetUserStr(ctx.Message().Sender), ctx.Message().Sender.ID, photoTag)
}
+3 -3
View File
@@ -183,7 +183,7 @@ func (bot *TipBot) HandleLNURL(rawlnurl string) (string, lnurl.LNURLParams, erro
var rawurl string
if name, domain, ok := lnurl.ParseInternetIdentifier(rawlnurl); ok {
isOnion := strings.Index(domain, ".onion") == len(domain)-6
isOnion := strings.HasSuffix(domain, ".onion")
rawurl = domain + "/.well-known/lnurlp/" + name
if isOnion {
rawurl = "http://" + rawurl
@@ -197,11 +197,11 @@ func (bot *TipBot) HandleLNURL(rawlnurl string) (string, lnurl.LNURLParams, erro
strings.HasPrefix(rawlnurl, "lnurla://") ||
strings.HasPrefix(rawlnurl, "keyauth://") {
location := strings.SplitN(rawlnurl, ":", 2)[1]
scheme := "https:"
if strings.Contains(rawurl, ".onion/") || strings.HasSuffix(rawurl, ".onion") {
if strings.Contains(location, ".onion/") || strings.HasSuffix(location, ".onion") {
scheme = "http:"
}
location := strings.SplitN(rawlnurl, ":", 2)[1]
rawurl = scheme + location
} else {
lnurl_str, ok := lnurl.FindLNURLInText(rawlnurl)
-1
View File
@@ -123,5 +123,4 @@ func (bot *TipBot) enterUserHandler(ctx intercept.Context) (intercept.Context, e
ResetUserState(user, bot)
return ctx, errors.Create(errors.InvalidSyntaxError)
}
return ctx, nil
}