diff --git a/lib/service/user.go b/lib/service/user.go index 6b21bd81..1153a9d6 100644 --- a/lib/service/user.go +++ b/lib/service/user.go @@ -12,7 +12,6 @@ import ( "github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/security" "github.com/getAlby/lndhub.go/lnd" - "github.com/getsentry/sentry-go" "github.com/labstack/echo/v4" "github.com/labstack/gommon/log" "github.com/uptrace/bun" @@ -138,7 +137,15 @@ func (svc *LndhubService) CheckOutgoingPaymentAllowed(c echo.Context, lnpayReq * limits := svc.GetLimits(c) if limits.MaxSendAmount >= 0 { if lnpayReq.PayReq.NumSatoshis > limits.MaxSendAmount { - svc.Logger.Errorf("Max send amount exceeded for user_id %v (amount:%v)", userId, lnpayReq.PayReq.NumSatoshis) + svc.Logger.Warnj( + log.JSON{ + "message": "max send amount exceeded", + "user_id": userId, + "lndhub_user_id": userId, + "amount": lnpayReq.PayReq.NumSatoshis, + "limit": limits.MaxSendAmount, + }, + ) return &responses.SendExceededError, nil } } @@ -156,13 +163,14 @@ func (svc *LndhubService) CheckOutgoingPaymentAllowed(c echo.Context, lnpayReq * return nil, err } if volume > limits.MaxSendVolume { - svc.Logger.Errorj( + svc.Logger.Warnj( log.JSON{ - "message": "transaction volume exceeded", - "lndhub_user_id": userId, + "message": "max send volume exceeded", + "lndhub_user_id": userId, + "volume": volume, + "limit": limits.MaxSendVolume, }, ) - sentry.CaptureMessage(fmt.Sprintf("transaction volume exceeded for user %d", userId)) return &responses.TooMuchVolumeError, nil } } @@ -197,7 +205,15 @@ func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, us limits := svc.GetLimits(c) if limits.MaxReceiveAmount >= 0 { if amount > limits.MaxReceiveAmount { - svc.Logger.Errorf("Max receive amount exceeded for user_id %d", userId) + svc.Logger.Warnj( + log.JSON{ + "message": "max receive amount exceeded", + "user_id": userId, + "lndhub_user_id": userId, + "amount": amount, + "limit": limits.MaxReceiveAmount, + }, + ) return &responses.ReceiveExceededError, nil } } @@ -215,8 +231,14 @@ func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, us return nil, err } if volume > limits.MaxReceiveVolume { - svc.Logger.Errorf("Transaction volume exceeded for user_id %d", userId) - sentry.CaptureMessage(fmt.Sprintf("transaction volume exceeded for user %d", userId)) + svc.Logger.Warnj( + log.JSON{ + "message": "max receive volume exceeded", + "lndhub_user_id": userId, + "volume": volume, + "limit": limits.MaxReceiveVolume, + }, + ) return &responses.TooMuchVolumeError, nil } } @@ -234,7 +256,14 @@ func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, us return nil, err } if currentBalance+amount > limits.MaxAccountBalance { - svc.Logger.Errorf("Max account balance exceeded for user_id %d", userId) + svc.Logger.Warnj( + log.JSON{ + "message": "max balance exceeded", + "lndhub_user_id": userId, + "new_balance": currentBalance + amount, + "limit": limits.MaxAccountBalance, + }, + ) return &responses.BalanceExceededError, nil } } diff --git a/lib/tokens/jwt.go b/lib/tokens/jwt.go index bf92b13b..0baf4638 100644 --- a/lib/tokens/jwt.go +++ b/lib/tokens/jwt.go @@ -12,6 +12,7 @@ import ( "github.com/golang-jwt/jwt" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" + "github.com/labstack/gommon/log" ) type jwtCustomClaims struct { @@ -42,12 +43,25 @@ func Middleware(secret []byte) echo.MiddlewareFunc { config.SuccessHandler = func(c echo.Context) { token := c.Get("UserJwt").(*jwt.Token) claims := token.Claims.(*jwtCustomClaims) + c.Logger().Warnj(log.JSON{ + "msg": "JWT details", + "UserID": claims.ID, + "MaxSendVolume": claims.MaxSendVolume, + "MaxSendAmount": claims.MaxSendAmount, + "MaxReceiveVolume": claims.MaxReceiveVolume, + "MaxReceiveAmount": claims.MaxReceiveAmount, + "MaxAccountBalance": claims.MaxAccountBalance, + }) c.Set("UserID", claims.ID) - c.Set("MaxSendVolume", claims.MaxSendVolume) - c.Set("MaxSendAmount", claims.MaxSendAmount) - c.Set("MaxReceiveVolume", claims.MaxReceiveVolume) - c.Set("MaxReceiveAmount", claims.MaxReceiveAmount) - c.Set("MaxAccountBalance", claims.MaxAccountBalance) + // enable it only for getalbycom calls + // there might still be old tokens out there that have these set to 0 (which meant disabled) + if claims.Issuer == "getalbycom" { + c.Set("MaxSendVolume", claims.MaxSendVolume) + c.Set("MaxSendAmount", claims.MaxSendAmount) + c.Set("MaxReceiveVolume", claims.MaxReceiveVolume) + c.Set("MaxReceiveAmount", claims.MaxReceiveAmount) + c.Set("MaxAccountBalance", claims.MaxAccountBalance) + } // pass UserID to sentry for exception notifications if hub := sentryecho.GetHubFromContext(c); hub != nil { hub.Scope().SetUser(sentry.User{ID: strconv.FormatInt(claims.ID, 10)})