fix: credential data corruption - Create handler mutating store pointer
- CreateCredential was setting cred.Data = cred.Masked directly on the store pointer, corrupting stored credentials with masked data - Fixed by using a value copy for API response - Also fix nextID starts at 1 to avoid ID=0 issue
This commit is contained in:
@@ -73,6 +73,7 @@ func InitCredentialStore(cfg *Config) {
|
|||||||
CredStore = &CredentialStore{
|
CredStore = &CredentialStore{
|
||||||
data: make(map[uint]*Credential),
|
data: make(map[uint]*Credential),
|
||||||
path: cfg.DataDir + "/credentials.json",
|
path: cfg.DataDir + "/credentials.json",
|
||||||
|
nextID: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := CredStore.Load(); err != nil {
|
if err := CredStore.Load(); err != nil {
|
||||||
|
|||||||
@@ -89,9 +89,10 @@ func (h *CredentialHandler) CreateCredential(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return without secrets
|
// Return without secrets (use a copy to avoid mutating store)
|
||||||
cred.Data = cred.Masked
|
resp := *cred
|
||||||
c.JSON(http.StatusCreated, cred)
|
resp.Data = cred.Masked
|
||||||
|
c.JSON(http.StatusCreated, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCredential updates a credential
|
// UpdateCredential updates a credential
|
||||||
|
|||||||
Reference in New Issue
Block a user