@@ -193,6 +193,9 @@ func (v *Vault) Close() {
193193}
194194
195195// GetEntries : return the cardType entries in the Enpass database filtered by filters.
196+ // Note: Each item in Enpass can have multiple fields (e.g., email accounts have
197+ // login, incoming server, outgoing server fields). This function deduplicates
198+ // by UUID, preferring the sensitive field (typically the password).
196199func (v * Vault ) GetEntries (cardType string , filters []string ) ([]Card , error ) {
197200 if v .db == nil || v .vaultInfo .VaultName == "" {
198201 return nil , errors .New ("vault is not initialized" )
@@ -203,7 +206,8 @@ func (v *Vault) GetEntries(cardType string, filters []string) ([]Card, error) {
203206 return nil , errors .Wrap (err , "could not retrieve cards from database" )
204207 }
205208
206- var cards []Card
209+ // Use a map to deduplicate cards by UUID, keeping the sensitive field (password)
210+ cardMap := make (map [string ]Card )
207211
208212 for rows .Next () {
209213 var card Card
@@ -219,6 +223,21 @@ func (v *Vault) GetEntries(cardType string, filters []string) ([]Card, error) {
219223
220224 card .RawValue = card .value
221225
226+ // Deduplicate by UUID: prefer sensitive fields (passwords) over non-sensitive ones
227+ if existing , found := cardMap [card .UUID ]; found {
228+ // Keep the new card if it's sensitive and the existing one isn't
229+ if card .Sensitive && ! existing .Sensitive {
230+ cardMap [card .UUID ] = card
231+ }
232+ // Otherwise keep the existing card
233+ } else {
234+ cardMap [card .UUID ] = card
235+ }
236+ }
237+
238+ // Convert map to slice
239+ cards := make ([]Card , 0 , len (cardMap ))
240+ for _ , card := range cardMap {
222241 cards = append (cards , card )
223242 }
224243
0 commit comments