feat(auth): require changing default admin password (#778)

This commit is contained in:
h44z
2026-11-09 19:57:23 +01:00
committed by GitHub
parent 137286d46b
commit 276f120b60
30 changed files with 641 additions and 90 deletions
@@ -29,6 +29,8 @@ type AuthenticationService interface {
OauthLoginStep2(ctx context.Context, providerId, nonce, code, codeVerifier string) (*domain.User, string, error)
// OauthProviderLogoutUrl returns an IdP logout URL for the given provider if supported.
OauthProviderLogoutUrl(providerId, idTokenHint, postLogoutRedirectUri string) (string, bool)
// IsDefaultPasswordInUse checks if the default admin password is still in use.
IsDefaultPasswordInUse(ctx context.Context) bool
}
type WebAuthnService interface {
@@ -114,16 +116,13 @@ func (e AuthEndpoint) RegisterRoutes(g *routegroup.Bundle) {
apiGroup.HandleFunc("POST /webauthn/login/start", e.handleWebAuthnLoginStart())
apiGroup.HandleFunc("POST /webauthn/login/finish", e.handleWebAuthnLoginFinish())
apiGroup.With(e.authenticator.LoggedIn()).HandleFunc("GET /webauthn/credentials",
e.handleWebAuthnCredentialsGet())
apiGroup.With(e.authenticator.LoggedIn()).HandleFunc("POST /webauthn/register/start",
e.handleWebAuthnRegisterStart())
apiGroup.With(e.authenticator.LoggedIn()).HandleFunc("POST /webauthn/register/finish",
e.handleWebAuthnRegisterFinish())
apiGroup.With(e.authenticator.LoggedIn()).HandleFunc("DELETE /webauthn/credential/{id}",
e.handleWebAuthnCredentialsDelete())
apiGroup.With(e.authenticator.LoggedIn()).HandleFunc("PUT /webauthn/credential/{id}",
e.handleWebAuthnCredentialsPut())
authenticatedApiGroup := apiGroup.With(e.authenticator.LoggedIn(), e.authenticator.RequireNonDefaultPassword())
authenticatedApiGroup.HandleFunc("GET /webauthn/credentials", e.handleWebAuthnCredentialsGet())
authenticatedApiGroup.HandleFunc("POST /webauthn/register/start", e.handleWebAuthnRegisterStart())
authenticatedApiGroup.HandleFunc("POST /webauthn/register/finish", e.handleWebAuthnRegisterFinish())
authenticatedApiGroup.HandleFunc("DELETE /webauthn/credential/{id}", e.handleWebAuthnCredentialsDelete())
authenticatedApiGroup.HandleFunc("PUT /webauthn/credential/{id}", e.handleWebAuthnCredentialsPut())
apiGroup.HandleFunc("POST /login", e.handleLoginPost())
apiGroup.With(e.authenticator.LoggedIn()).HandleFunc("POST /logout", e.handleLogoutPost())
@@ -174,13 +173,19 @@ func (e AuthEndpoint) handleSessionInfoGet() http.HandlerFunc {
email = &e
}
isDefault := false
if e.authService != nil {
isDefault = e.authService.IsDefaultPasswordInUse(r.Context())
}
respond.JSON(w, http.StatusOK, model.SessionInfo{
LoggedIn: currentSession.LoggedIn,
IsAdmin: currentSession.IsAdmin,
UserIdentifier: loggedInUid,
UserFirstname: firstname,
UserLastname: lastname,
UserEmail: email,
LoggedIn: currentSession.LoggedIn,
IsAdmin: currentSession.IsAdmin,
UserIdentifier: loggedInUid,
UserFirstname: firstname,
UserLastname: lastname,
UserEmail: email,
DefaultPasswordInUse: isDefault,
})
}
}
@@ -345,7 +350,7 @@ func (e AuthEndpoint) handleOauthCallbackGet() http.HandlerFunc {
if returnUrl != nil {
redirectToReturn("success")
} else {
respond.JSON(w, http.StatusOK, user)
respond.JSON(w, http.StatusOK, model.NewUser(user, false))
}
}
}
@@ -362,6 +367,9 @@ func (e AuthEndpoint) setAuthenticatedUser(r *http.Request, user *domain.User, o
currentSession.Firstname = user.Firstname
currentSession.Lastname = user.Lastname
currentSession.Email = user.Email
if e.authService != nil {
currentSession.DefaultPasswordInUse = e.authService.IsDefaultPasswordInUse(r.Context())
}
currentSession.OauthState = ""
currentSession.OauthNonce = ""
@@ -407,7 +415,7 @@ func (e AuthEndpoint) handleLoginPost() http.HandlerFunc {
e.setAuthenticatedUser(r, user, "", "")
respond.JSON(w, http.StatusOK, user)
respond.JSON(w, http.StatusOK, model.NewUser(user, false))
}
}