chore: build
This commit is contained in:
@@ -61,13 +61,16 @@ func (h *Handler) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
token, err := h.startSession(c, user)
|
||||
if err != nil {
|
||||
// Le JWT n'est plus jamais renvoyé dans le corps JSON (pentest F-003) :
|
||||
// uniquement posé en cookie HttpOnly par startSession. Le renvoyer ici
|
||||
// permettait au frontend de le dupliquer en localStorage, annulant la
|
||||
// protection HttpOnly contre un vol de session via XSS.
|
||||
if _, err := h.startSession(c, user); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "erreur serveur"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"token": token, "token_type": "Bearer", "role": user.Role})
|
||||
c.JSON(http.StatusOK, gin.H{"role": user.Role})
|
||||
}
|
||||
|
||||
// Me renvoie l'identité de la session courante (dont le rôle, pour le front).
|
||||
@@ -111,7 +114,18 @@ func (h *Handler) Register(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, exists := h.users.ByUsername(req.Username); exists {
|
||||
if existing, exists := h.users.ByUsername(req.Username); exists {
|
||||
// Un statut 409 distinct de la création (201) permet d'énumérer les
|
||||
// comptes existants (pentest F-002) — inévitable pour un flux
|
||||
// d'inscription instantané sans vérification email (l'utilisateur a
|
||||
// besoin de savoir qu'il doit choisir un autre nom). On protège au
|
||||
// moins la cible à plus fort enjeu : un compte admin ne confirme
|
||||
// jamais son existence, la réponse est indiscernable d'un nom
|
||||
// d'utilisateur simplement invalide.
|
||||
if existing.Role == RoleAdmin {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "nom d'utilisateur déjà pris"})
|
||||
return
|
||||
}
|
||||
@@ -127,12 +141,11 @@ func (h *Handler) Register(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
token, err := h.startSession(c, user)
|
||||
if err != nil {
|
||||
if _, err := h.startSession(c, user); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "erreur serveur"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"token": token, "token_type": "Bearer", "role": user.Role})
|
||||
c.JSON(http.StatusCreated, gin.H{"role": user.Role})
|
||||
}
|
||||
|
||||
// startSession ouvre une session Redis, signe le JWT et pose le cookie.
|
||||
|
||||
Reference in New Issue
Block a user