fix: API responses never include a user's password, verification code or reset code hashes, or their expiry dates; verifying an account returns only the public user fields

This commit is contained in:
fsylvain committed 2026-09-24 15:39:50 +02:00
1 parent aa865af2e9
commit 2ee28203ab
4 files changed
+389 -1

No files matched your search

+25 -1
View File
@@ -52,6 +52,26 @@ type ResetPasswordCredentials struct {
Password string `json:"password" validate:"required,min=8"`
}
type PublicUser struct {
ID uint32 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
IsVerified bool `json:"is_verified"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func newPublicUser(u user.User) PublicUser {
return PublicUser{
ID: u.ID,
Username: u.Username,
Email: u.Email,
IsVerified: u.IsVerified,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
}
}
func (h *Handler) removeJwtCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: "jwt",
@@ -205,7 +225,11 @@ func (h *Handler) Verify(w http.ResponseWriter, r *http.Request) {
return
}
body, _ := json.Marshal(verifiedUser)
body, err := json.Marshal(newPublicUser(verifiedUser))
if err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
_, _ = w.Write(body)
}