Skip to content

feat: keep a record of every change to a member's devices - #75

Merged
crazeydave merged 1 commit into
mainfrom
feat/device-events
Nov 28, 2026
Merged

crazeydave merged 1 commit into
mainfrom
feat/device-events

Conversation

@crazeydave

Copy link
Copy Markdown
Contributor

Stage 5, piece 1 of the security review's follow-up. Fellowship decides who a member is, so a compromised site could enrol a phone as any member, or replace a phone's key, and receive that member's messages from then on. That can't be prevented without moving the member list out of WordPress, so this makes it visible: a record the site can't erase. Pieces 2 (telling the member, in Link) and 3 (Fellowship's Devices screen) come later, each in its own PR.

Everything is under firebase/, which isn't in the plugin zip.

What changes

  • deviceEvents: each enrol, replaceKey, takeOverDevice, signOut, adminRevoke, adminRemove and adminRevokeMember writes one entry, in the same transaction or batch as the change.
    • Each holds memberId, deviceId, kind, actor (member, device or site), signInProvider (google.com, apple.com, or custom for a Unity password or a device), platform and at.
    • A takeover keeps its device id, so instead of an old id it records previous: {platform, label}, plus keyProved.
    • No addresses or names.
  • Removal keeps the record. The entry is written before the delete, and erasing a member (adminRevokeMember with remove) keeps their entries. Otherwise one admin call could hide what the site had done.
  • A takeover may prove the private key. Today it only needs the device's public key, which resolveAudience gives every sender. It now accepts an optional keySignature: RSA-PSS/SHA-256 over takeover:<deviceId>:<sign-in uid>:<auth_time> (takeoverStatement()). The sign-in works only once, so this can't be replayed.
    • Unsigned: accepted, recorded with keyProved: false, until a Link release sends it.
    • Badly signed: refused as fellowship_key_mismatch, with the sign-in left unspent, so Link enrols as new as it already does.
  • Nobody outside the Functions can change it: firestore.rules refuses every client read and write. The site's account (fellowship-site@) only has Datastore Viewer.
  • Retention: DEVICE_EVENT_RETENTION_DAYS = 365. The daily sweep deletes older entries whatever the site's retentionDays says, including 0.
  • Index: deviceEvents (memberId ASC, at DESC), for the history views to come.
  • adminRevoke on an unknown device answers 404 fellowship_no_such_device rather than 500. Fellowship treats both as a failure.
  • README: "The record of device changes".

Tests

  • New deviceEvents.test.ts:
    • each action writes one entry with the right fields;
    • refused actions write nothing;
    • removal and erasure keep entries;
    • a signed takeover is proved; signatures from another key, sign-in or device are refused and change nothing;
    • the sweep keeps a year whatever the message window.
  • rules.test.ts: no device, identity or anonymous client can read, list, write or delete an entry.
  • Emulators: 200 pass.
  • No PHP changed, so the plugin's own gates aren't affected.

After merge

  • Deploy firestore and the functions as the README says. Changed: enrol, replaceKey, takeOverDevice, signOut, adminRevoke, adminRemove, adminRevokeMember, sweep. Redeploy any that fail in groups of three.
  • On /amber: enrol, sign out and revoke a phone, and check the entries in the console.

Fellowship decides who a member is, so a compromised site could enrol a
phone as any member or replace a key and receive that member's messages.
That can't be prevented without moving the member list out of WordPress,
so it is made visible instead.

Each enrolment, key replacement, takeover, sign-out, revoke and removal
now writes an entry to deviceEvents in the same write as the change: the
member and device ids, what happened, who did it, the sign-in that proved
it, and when. Clients can't read or change it, the site's account only
reads Firestore, and erasing a member keeps the record. The sweep removes
entries after a year, apart from the site's message retention.

A takeover may also sign a statement bound to its sign-in with the
device's private key. An unsigned one is still accepted and recorded with
keyProved false until Link sends it; a bad signature is refused as a key
mismatch.
@crazeydave
crazeydave merged commit 0041877 into main Nov 28, 2026
6 checks passed
@crazeydave
crazeydave deleted the feat/device-events branch November 28, 2026 22:44
crazeydave added a commit that referenced this pull request Nov 29, 2026
Stage 5 piece 3. The Functions record every change to a member's devices
in Firestore's deviceEvents (#75). The Devices screen now shows it:

- The newest 20 changes across all members, above the device list, shown
  even when no phones are enrolled.
- Each member's name links to their newest 50 changes: when, what, which
  device, by whom, the sign-in used, and for takeovers whether the old key
  was proved.
- Flags for a change made by the site, an enrolment with a sign-in method
  that member hadn't used before in what's shown, and a takeover without
  the old key.
- A Firestore failure shows the usual "could not be reached" notice, never
  an empty history.

FirestoreClient gains memberEvents, recentEvents and getMany (one batch
read for a history's phone labels). The README and readme.txt say plainly
that a compromised site could hide this view, and that the member's own
notice in Link is the check that doesn't depend on the site.
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.

1 participant