feat: make self-hosted auth work without a mail relay by rewriting the platform SMTP transport with real AUTH and TLS (it did neither, so SMTP_USERNAME/SMTP_PASSWORD were dead and every documented relay was unreachable), adding MAIL_TRANSPORT=smtp|log|ses with a log transport that prints codes so a fresh install can sign in with no relay, demoting the emailed login code to AUTH_LOGIN_CODE=always|new_device|off (off on self-host, per NIST SP 800-63B and OWASP ASVS), claiming the first owner through a single-use setup link or WARMBLY_BOOTSTRAP_* instead of register-then-psql, deriving every emailed URL from APP_URL rather than a hardcoded app.warmbly.com that leaked live reset tokens to the vendor, fixing the confirm hooks that read path params against paramless routes and broke login, register and reset confirmation in the dashboard everywhere, adding generic OIDC with PKCE, one-time state, verified nonce and (issuer,subject) identity binding, enforcing 2FA on the social paths that skipped it, adding a per-IP limiter and trusted-proxy handling to the unthrottled auth group, refusing boot on the published default secrets, and dropping mailpit from the default stack (#99)
2026-08-14 14:57:09 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/warmbly/warmbly/internal/app/token"
|
|
|
|
|
"github.com/warmbly/warmbly/internal/errx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type setupClaimRequest struct {
|
|
|
|
|
Token string `json:"token"`
|
|
|
|
|
Email string `json:"email"`
|
|
|
|
|
Password string `json:"password"`
|
|
|
|
|
FirstName string `json:"first_name"`
|
|
|
|
|
LastName string `json:"last_name"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetupClaim exchanges the one-time link printed at first boot for the owner
|
|
|
|
|
// account, and signs them straight in.
|
|
|
|
|
//
|
|
|
|
|
// Public by necessity: there is no account to authenticate as yet. The token is
|
|
|
|
|
// the protection, and it is consumed atomically, refused once any user exists,
|
|
|
|
|
// and covered by the same per-IP limiter as the rest of the auth group.
|
|
|
|
|
func (h *Handler) SetupClaim(c *gin.Context) {
|
|
|
|
|
if h.BootstrapService == nil {
|
|
|
|
|
errx.Handle(c, errx.New(errx.NotFound, "Setup is not available on this deployment."))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var req setupClaimRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
2026-09-22 20:21:41 -07:00
|
|
|
errx.Handle(c, errx.InvalidBody(err))
|
feat: make self-hosted auth work without a mail relay by rewriting the platform SMTP transport with real AUTH and TLS (it did neither, so SMTP_USERNAME/SMTP_PASSWORD were dead and every documented relay was unreachable), adding MAIL_TRANSPORT=smtp|log|ses with a log transport that prints codes so a fresh install can sign in with no relay, demoting the emailed login code to AUTH_LOGIN_CODE=always|new_device|off (off on self-host, per NIST SP 800-63B and OWASP ASVS), claiming the first owner through a single-use setup link or WARMBLY_BOOTSTRAP_* instead of register-then-psql, deriving every emailed URL from APP_URL rather than a hardcoded app.warmbly.com that leaked live reset tokens to the vendor, fixing the confirm hooks that read path params against paramless routes and broke login, register and reset confirmation in the dashboard everywhere, adding generic OIDC with PKCE, one-time state, verified nonce and (issuer,subject) identity binding, enforcing 2FA on the social paths that skipped it, adding a per-IP limiter and trusted-proxy handling to the unthrottled auth group, refusing boot on the published default secrets, and dropping mailpit from the default stack (#99)
2026-08-14 14:57:09 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u, xerr := h.BootstrapService.Claim(
|
|
|
|
|
c.Request.Context(),
|
|
|
|
|
req.Token,
|
|
|
|
|
req.Email,
|
|
|
|
|
req.Password,
|
|
|
|
|
req.FirstName,
|
|
|
|
|
req.LastName,
|
|
|
|
|
)
|
|
|
|
|
if xerr != nil {
|
|
|
|
|
errx.Handle(c, xerr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hand back a session rather than bouncing them to the login screen. They
|
|
|
|
|
// just proved ownership of the instance; asking them to type the password
|
|
|
|
|
// again immediately is friction with no security value.
|
|
|
|
|
session, terr := h.TokenService.GenerateSession(
|
|
|
|
|
c.Request.Context(),
|
|
|
|
|
u.ID,
|
|
|
|
|
u.Email,
|
|
|
|
|
c.ClientIP(),
|
|
|
|
|
c.Request.UserAgent(),
|
|
|
|
|
token.AuthProviderEmail,
|
|
|
|
|
)
|
|
|
|
|
if terr != nil {
|
|
|
|
|
errx.Handle(c, terr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, session)
|
|
|
|
|
}
|