Skip to content

fix: write login entries in the shape the Enpass app expects - #165

Merged
hazcod merged 1 commit into
hazcod:masterfrom
bendtherules:fix/login-entry-shape
Nov 14, 2026
Merged

hazcod merged 1 commit into
hazcod:masterfrom
bendtherules:fix/login-entry-shape

Conversation

@bendtherules

Copy link
Copy Markdown
Contributor

Summary

Entries created or edited with enpass-cli are not shaped the way the Enpass app expects. On Enpass 6.12.8 (macOS) an entry created by enpass-cli makes the app crash while drawing the item list. On builds that tolerate the row, the entry loads but shows bare values: no field labels, no section grouping, no icon.

Two separate problems, both in pkg/enpass/write.go:

  1. CreateEntry writes a partial item row and three itemfield rows with invented uids and no display order.
  2. UpdateEntry replaces item.key and re-encrypts only the password, which invalidates the item's other sensitive fields, and it matches fields by type alone, so every password field in the item is overwritten.

Why the app crashes

The app resolves a field's label and section through the item template: (item.template, itemfield.item_field_uid, orde). The writer left item.template NULL:

before (enpass-cli)                     after (row written by the app)
item.template  = NULL                   item.template  = 'login.default'
item.category  = 'Login'                item.category  = 'login'
item.icon      = 'card_password'        item.icon      = '{"fav":"example.com",...}'
itemfield:                              itemfield:
  128|password|orde NULL|label ''         10|username|orde 1
  129|username|orde NULL                  12|email|orde 2
  130|url|orde NULL                       11|password|orde 3
                                          ...

Crash report from the app:

EXC_BAD_ACCESS (SIGSEGV)
KERN_INVALID_ADDRESS at 0x0
_platform_strlen

i.e. strlen(NULL) on item.template.

What this changes

Create

  • complete item row: template, meta_updated_at, updated_at, auto_submit, usage_count, last_used, wearable, form_data, extra, JSON icon
  • full stock login.default field set: uids 10, 12, 11, 13, 101, 14, 102, 15, 16, orde 1-9, with the app's sensitive flags, plus hash (SHA-1 of the plaintext), initial, strength, algo_version, historical, pwned_check_time
  • lower-case category
  • vault.json: vault_items_count and last_modified_time kept in step
  • non-login categories return an error instead of writing a row that cannot be mapped onto a template

Update

  • reuse item.key; only encrypt the field being changed
  • locate the field by template uid first, then by type, so entries written by older versions are repaired instead of duplicated
  • refresh hash/initial/strength and the item timestamps

Schema differences

Column sets differ between vaults of different ages: the vault bundled in test/ has 23 itemfield columns, a 6.12-created vault has 25 (non_compliant, non_compliant_check_time). Inserts are therefore built from pragma_table_info and skip columns the vault does not have, instead of hard-coding a list that breaks on another version.

Verification

  • reproduced the crash on macOS with Enpass 6.12.8 against a scratch vault
  • with this patch the same vault opens, renders labels and sections, and the item survives an edit in the app
  • rotating the password of an item that has two sensitive fields (uids 11 and 6890) leaves item.key unchanged and both fields decrypt; before this patch the second field became undecryptable
  • go test ./... passes

Known limitation

The stock template is hard-coded. It cannot be read from the vault: on stock vaults the template and category tables are empty and the definitions ship inside the app bundle. The uids and order here were taken from items written by Enpass 6.12; the fields shared with 6.8-era items match.

A more future-proof approach — a good follow-up — is to copy the skeleton from an existing item of the same template in the same vault (the template-provided slots are exactly the fields with an empty label), falling back to this constant only when the vault has no such item. That needs a fallback path and a policy for custom fields, so it is not folded into this fix.

Follow-ups

  • turn the skipped write tests into structural assertions (they currently only round-trip through this package's own reader, which is why a row that crashed the app could pass)
  • template discovery and other categories

CreateEntry wrote a partial item row: item.template was left NULL, category
used the wrong case, icon was a bare string, and only three itemfield rows
were written with invented uids and no order. Enpass 6.12 dereferences
item.template with strlen() while rendering and crashes with EXC_BAD_ACCESS
(KERN_INVALID_ADDRESS at 0x0); builds that tolerate the NULL show the values
without labels or section grouping.

Write the complete stock login.default template (uids 10, 12, 11, 13, 101,
14, 102, 15, 16 with orde 1-9), lower-case the category, store the JSON icon
the app expects, and fill the per-field metadata (hash, initial, strength,
algo_version, timestamps).

UpdateEntry had two related defects: it generated a new item key and
re-encrypted only the password, leaving the item's other sensitive fields
encrypted under a discarded key, and it matched fields by type alone, so
every password row in the item was overwritten. Reuse the existing item key,
target the template uid (falling back to the first field of that type so
entries written by older versions are repaired in place), and refresh
hash/initial/strength.

Both paths keep vault.json's vault_items_count and last_modified_time in
step, and only fill columns that exist in the vault, since the itemfield
schema differs between vault versions (6.8 vs 6.12).

Creating a non-login category now returns an error instead of writing a row
the app cannot map onto a template.
Comment thread pkg/enpass/template.go
return ""
}

sum := sha1.Sum([]byte(value))
@hazcod
hazcod merged commit c288645 into hazcod:master Nov 14, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants