You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
user-repository: stop write paths from clobbering admission and vanish state #1253
From the 2026-11-01 scan: F-012 (authorization bypass, CWE-863), F-033 (CWE-862), F-036 (CWE-367), all in src/repositories/user-repository.ts. Reachability was not established by the scan.
Current code (main 49f51378)
F-033 — an invoice write can clear another account's flags. The upsert is insert(row).onConflict('pubkey').merge(omit(['pubkey','balance','created_at'])(row)). A row prepared for a caller-selected beneficiary carries admitted and isVanished as false, so an anonymous invoice request for an existing pubkey merges those defaults over live state.
F-012 — a replica-derived negative becomes authoritative.isVanished() hydrates a user missing from the users table with the value the event repository reports, then writes it; a vanish request missed under replication lag is stored as a permanent false.
F-036 — lazy initialisation races a real vanish. The same hydrate-update writes the earlier snapshot, so a true committed between the read and the write is overwritten with false.
Fix shape
Insert-if-absent, then read back: initialisation must never update an existing row (onConflict().ignore(), then findByPubkey).
Prepare invoice beneficiaries with insert-if-absent; leave admission and vanish changes to their dedicated methods.
Make general upserts merge only fields the caller explicitly supplied.
Acceptance
An invoice for an existing admitted, vanished pubkey leaves both flags unchanged.
Initialisation after a true is committed returns and stores true.
A replica-derived false never overwrites primary state.
The PR is on my fork: saket0187#3 (commit). Invoices and the vanish check no longer overwrite a user's admission or vanish state.
An invoice for an existing pubkey is now insert-if-absent, and a new row takes its vanish state from the stored events; the vanish check never overwrites a row another writer created and reads the primary instead of the replica.
Trade-off: any undeleted stored kind-62 still counts, whatever relay it names, as on the first-event path today.
10 unit cases and 2 integration scenarios (a renewal invoice on an admitted, vanished subscriber; an invoice for a pubkey with only a stored kind-62), all failing on 75b375c.
Could you cherry-pick it when you get a chance? @cameri
Reviewed the fork submission (saket0187#3) against main5d295d73: applied the diff to a clean tree, 3 644 unit tests pass, and reverting only the src/ change makes 8 of the new cases fail. The three findings are genuinely fixed — F-033 by insert-if-absent on the invoice path, F-012 by reading the primary, F-036 because the vanish writer merges unconditionally, so a concurrent vanish wins either ordering.
Three non-blocking notes are on the PR: an extra events query on every invoice, the benchmark description at src/scripts/benchmark-queries.ts:206 which now describes a query that no longer runs per message, and a missing contract comment on IUserRepository.upsert. The two new integration scenarios are provable only in CI.
Activity
saket0187 commentedon Nov 29, 2026
Could you assign it to me?
The PR is on my fork: saket0187#3 (commit). Invoices and the vanish check no longer overwrite a user's admission or vanish state.
Could you cherry-pick it when you get a chance? @cameri
cameri commentedon Nov 29, 2026
@saket0187 assigned to you
saket0187 commentedon Nov 29, 2026
@cameri Could you review my pr and let me know if any changes are needed?
chappie-daemon commentedon Nov 29, 2026
Reviewed the fork submission (saket0187#3) against
main5d295d73: applied the diff to a clean tree, 3 644 unit tests pass, and reverting only thesrc/change makes 8 of the new cases fail. The three findings are genuinely fixed — F-033 by insert-if-absent on the invoice path, F-012 by reading the primary, F-036 because the vanish writer merges unconditionally, so a concurrent vanish wins either ordering.Three non-blocking notes are on the PR: an extra events query on every invoice, the benchmark description at
src/scripts/benchmark-queries.ts:206which now describes a query that no longer runs per message, and a missing contract comment onIUserRepository.upsert. The two new integration scenarios are provable only in CI.