LiftLog gives users the option of publishing their workouts to a feed that their friends can see. Friends see each other's workouts, plan and weekly activity, can follow a workout live while it happens if its owner shares live workouts, and can cheer each other's workouts. The feed is entirely opt in.
Privacy is extremely important to preserve here. Data is end to end encrypted (see Technical Details), and users are in full control of who their friends are. Friendship is always mutual, and a friendship always starts with a link and an explicit accept:
Bobsends hisSHARE_URLtoAlice- After opening the
SHARE_URL,AlicesendsBoba friend request. Nothing of hers is shared yet. Bobopens his app, sees thatAlicewants to be friends (the Feed tab shows a badge), and accepts or denies.- If
Bobaccepts, they are both friends. Each sees the other's workouts once the apps have exchanged keys. The key exchange happens on their next inbox poll without either of them doing anything.
Users are free to provide any name they like, and a link carries whatever name its sender typed. The share screen warns that names are self-chosen, and asks users to only send requests to people they know.
Each person in the friends list has one of these statuses:
| Status | Meaning | What the user can do |
|---|---|---|
incoming |
They asked to be friends. | Accept or deny |
pending |
We asked to be friends and are waiting for them to accept. | Cancel |
friend |
Mutual friends. | Remove |
legacyFollowing |
We followed them in a version with one-way follows, and they did not follow us back. | Share back or remove |
legacyFollower |
They followed us in a version with one-way follows, and we are waiting for them to share back. | Remove |
Only friend appears in the feed and the calendar, and only a friend can cheer or be cheered.
The app accepts automatically only where consent already exists:
- Crossed requests. Alice asks Bob while Bob's request to Alice is still waiting, so each has already asked for the other.
- Asking again. A request from someone who is already a friend, which happens after they restore a backup.
- Sharing back. A
legacyFollowerwho shares back already had our consent, because we were the one being followed.
Either side can remove the other at any time, including cancelling or denying a request. Removing someone:
- removes them from the list and drops any messages still waiting to be sent to them
- tells them, with
Unfriend(orFriendRejectfor a request we received) - revokes the
FollowSecretwe issued them, so they can no longer fetch our feed items - rotates our AES key, if they ever held it (see Key rotation)
Being told by the other side does the same, except we do not reply.
Versions before friends had one-way follows. When the app upgrades:
- A pair who followed each other become friends.
- A one-way follow becomes
legacyFollowingfor the follower, who is asked to share back, andlegacyFollowerfor the person followed. Declining to share back removes the follow. - Follow requests we had not answered are turned down, and requests we sent are dropped.
Apps that still use follows cannot become friends. A FollowRequest from such an app is turned down automatically, an UnfollowNotification is treated as Unfriend, and a FollowResponse is ignored.
Apps from before share links carried a share secret cannot start new friendships with current apps. A current app refuses a link without a share secret, and drops a FriendRequest from a stranger that does not carry its share secret.
As mentioned, personal information (including workouts) is end to end encrypted. Personal Information that is NOT encrypted is limited to:
- Timestamp of request - this is the timestamp of when a feed item was submitted. This could correlate to a time of workout, and therefore could be considered PII.
- Expiry of a feed item.
- When someone sharing live workouts is training, and when each update to the live workout was sent (see Live workouts).
- User ID (a UUID) - this is stored on the device, but is not linked to the device (i.e. The LiftLog servers cannot trace userId to device)
- The recipient of an inbox message as a User ID, and when the message was sent. The sender is only named inside the encrypted message.
Data is encrypted by the user before sending to the LiftLog server. Data is encrypted via AES-GCM, and signed via RSA-PSS to prove who wrote the data (see Payload Encryption). At no point does the server store the unencrypted private keys. Public keys are stored alongside the user's information.
A feed account is optional. Its identity is generated when the user creates an account from the feed or feed settings, or when they first share a workout or plan link, and is stored on THEIR device. Deleting the account removes the identity from the server and the device. An identity consists of:
- An optional name
- An AES-128-GCM key, plus the AES keys it replaced in the last 90 days (see Key rotation)
- An RSA key pair (2048 key size)
- A User ID (UUID)
- A share secret: 12 random bytes that only travel inside share links (see Share links)
The client registers its identity with the LiftLog servers by sending ONLY its UserId to the createUser endpoint. If a user does not already exist with that ID the server generates a random Password and sends it back to the client. The Password is salted and hashed, then stored against the user's ID on the server. This Password must be provided when publishing any data for that UserId to the server.
The profile (name and current plan) is published encrypted with the current AES key. Workouts are published only while the user has Publish workouts turned on.
Using this identity, the client can create a SHARE_URL. This url consists of 3 parts from the identity:
- UserId (or its lookup)
- Name (still optional)
- Share secret, base64url encoded in the URL fragment
An example share url could look like this (note this is non functional):
https://app.liftlog.online/feed/share?id=tz4a98xxat96&name=Liam#h7Ks2mQ9Lr4tVb8n
The structure of the url being:
https://app.liftlog.online/feed/share?id=USER_ID&name=Name#SHARE_SECRET
The server hands out every public key, so a server that swapped a public key for its own could read the FriendKeys sent to that key. In order for the server to be unable to swap keys when two people become friends, the share secret proves both keys.
Bob publishes a share tag with his profile:
shareTag = HMAC-SHA256(key: shareSecret, data: Bob's public key)
Only Bob can make this share tag, because the share secret only travels in the URL fragment, which browsers never send to a server.
When Alice opens Bob's link, her app has the share secret from the link, and a public key and share tag from the server. Her app computes the share tag itself and compares:
HMAC-SHA256(key: shareSecret from the link, data: public key the server returned) == share tag the server returned
- If the server returned Bob's real key, the two match.
- If the server swapped in a key of its own, the two differ, and the link is refused. The server cannot publish a share tag that matches its own key, because the server never sees the share secret.
Alice's FriendRequest then carries her public key and Bob's share secret. The request is encrypted to Bob's checked key, so the server can neither read the share secret nor change the key. Bob's app keeps the key from the request, and only keeps a request from a stranger if the request carries Bob's share secret.
Friends exchange two things: an AES key list, to decrypt each other's feed items and profile, and a FollowSecret. A FollowSecret is generated by the server for the user who issues it, and acts as a sort of API key, which allows its holder to request that user's encrypted feed items. The issuer can revoke a FollowSecret at any time.
When Alice opens Bob's link, the app fetches Bob's public key and share tag with the UserId, checks them against the share secret, and shows the share screen. If Alice sends the request, her app sends a FriendRequest inbox message carrying her name, her public key and Bob's share secret, and stores Bob as pending.
Bob's app receives the request, checks the share secret, and stores Alice as incoming with the public key from the request. If Bob accepts, his app issues a FollowSecret for Alice and sends her a FriendKeys message with his keys and that secret. Alice's app stores Bob's keys and secret, issues its own FollowSecret for Bob, and sends its own FriendKeys back. Bob already has a secret for Alice, so his app does not reply again.
A flow chart demonstrating this process is below. Note items in (are encrypted with RSA public key):
sequenceDiagram
actor Alice
participant LiftLog as LiftLog Server
actor Bob
Bob->>Alice: SHARE_URL: UserId, Name, Share secret
Alice->>LiftLog: Get Bob's Public Key
LiftLog-->>Alice: Bob's RSA Public Key, Share tag
Alice->>Alice: Check Share tag with Share secret
Alice->>LiftLog: Bob's UserId<br/>(FriendRequest: Alice's name, Alice's Public Key, Share secret)
Bob->>LiftLog: Request InboxMessages
LiftLog-->>Bob: FriendRequest
Bob->>Bob: Check Share secret, keep Alice's Public Key
Bob->>Bob: Accept
Bob->>LiftLog: Request FollowSecret
LiftLog-->>Bob: FollowSecret for Alice
Bob->>LiftLog: Alice's UserId<br/>(FriendKeys: Bob's AES keys, FollowSecret)
Alice->>LiftLog: Request InboxMessages
LiftLog-->>Alice: FriendKeys
Alice->>Alice: Store Bob's keys and FollowSecret
Alice->>LiftLog: Request FollowSecret
LiftLog-->>Alice: FollowSecret for Bob
Alice->>LiftLog: Bob's UserId<br/>(FriendKeys: Alice's AES keys, FollowSecret)
Bob->>LiftLog: Request InboxMessages
LiftLog-->>Bob: FriendKeys
Bob->>Bob: Store Alice's keys and FollowSecret
The inbox message types:
| Type | Payload | On receipt |
|---|---|---|
FriendRequest |
name, public key, share secret | From a stranger: stored as incoming with the public key it carries, only if it carries our share secret. From an incoming: replaces the name and public key, only if it carries our share secret. From a pending, friend or legacyFollower: they get our keys. Ignored from a legacyFollowing. |
FriendKeys |
AES keys (newest first, at most 20), FollowSecret | Replaces their keys and secret. A pending or legacyFollower becomes a friend. Our keys are resent if they were pending, or if we asked them to repair the friendship. Ignored from strangers and incoming, and when older than the last FriendKeys applied. |
FriendReject |
none | Ends a request we are waiting on. |
Unfriend |
none | Removes them (see Removing a friend). |
Reaction |
a cheer on a feed item | Accepted only from a friend |
PUT /inbox is unauthenticated by design: anyone who knows a user id can post into that user's inbox. The signature proves who wrote a message, never that the sender was entitled to send it, which is why every rule above checks the sender's status first.
A user's workout sessions are a type of feed item. When a user finishes a workout with Publish workouts on, they create a SessionUserEvent payload consisting of that session's data, using the session id as the event id. This payload is signed with their RSA private key, then the payload and the signature are encrypted with their current AES key (see Payload Encryption). Bodyweight is left out unless the user publishes it.
This encrypted payload is then sent to the LiftLog server as a Feed Item, and is stored encrypted at rest against their UserId. Feed items expire after 90 days.
When a friend requests feed items with a valid FollowSecret, the feed items are returned in this encrypted and signed form. The friend tries each AES key it holds for that user, newest first, then verifies the decrypted payload's signature with the user's RSA public key. If the signature is valid, the feed item is displayed in their feed.
A flow chart demonstrating this process is below. Note items in [are encrypted via AES and signed via RSA].
sequenceDiagram
actor Alice
participant LiftLog as LiftLog Server
actor Bob
Alice->>LiftLog: [SessionUserEvent:<br/>Workout Session]
Bob->>LiftLog: Request Alice's Feed Items:<br/>FollowSecret
LiftLog-->>Bob: [SessionUserEvent]
Bob->>Bob: Decrypt and Verify SessionUserEvent
Alice->>LiftLog: Revoke Bob's FollowSecret
Bob->>LiftLog: Request Alice's FeedItems:<br/>FollowSecret
LiftLog-->>Bob: FollowSecret Revoked
Bob->>Bob: Remove Alice
Share live workouts is off by default, and only takes effect while Publish workouts is on. While a workout is open with Share live workouts on, the app sends the workout so far as a LiveSessionUserEvent, under the session's id, signed and encrypted like any feed item. The app sends again whenever the workout changes, a couple of seconds after the last change.
Live workouts travel over a SignalR hub (/feed-hub) rather than the feed:
- Trainer. The app authenticates with its user id and password, then publishes each update. The server keeps only the latest update per user, in memory, for 30 minutes after the update was sent, and passes the update on to friends watching. Nothing is written to the database, so a server restart forgets the live workout until the next update.
- Friends. The app watches its friends with their
FollowSecrets, the same secrets the app fetches feed items with. The app receives the latest update of each friend who is training, then each new update as it is sent. Revoking aFollowSecretstops its holder receiving live updates. - Finishing. In order for friends to fetch the finished workout as the live workout disappears, the app publishes the
SessionUserEventfirst, then tells the hub the live workout has ended. Discarding the workout, or turning sharing off during the workout, ends the live workout the same way.
The app holds a connection to the hub only while the feed is on screen, or while the workout screen is open and sharing live, and only while the app is in the foreground. Updates made in the background are sent when the workout screen comes back. A backend without the hub still has the feed, without live workouts.
Friends keep live workouts in memory only, and hide a live workout that has not been updated for 30 minutes. Live workouts appear as Training now above the week's activity and open on the normal workout page, where friends can cheer them. In order for a cheer to stay with the workout once the workout is finished, the cheer is keyed by the session id.
Cheers are inbox messages. In order for a cheer to reach the workout screen within seconds, the server tells someone connected to the hub to fetch their inbox when an inbox message arrives for them. The app also fetches its inbox whenever it connects, to catch up on anything sent while it was away.
The server can tell when a user sharing live workouts is training, and when each change to the workout was made. It cannot read the workouts.
Revoking a FollowSecret stops a removed friend fetching new feed items. In addition, we rotate the AES keys used for encrypting our feed items.
- A new AES key is generated. The previous key is marked to expire after 90 days. Expiration is just when we stop sending the key to followers.
- A
FriendKeysmessage is sent to all active friends, containing the new keychain. - The profile is published again with the new key.
Friends replace their key list when the FriendKeys arrives, and keep reading older feed items with the older keys in that list. A previous key is dropped 90 days after it was replaced, when every feed item encrypted with it has expired, so FriendKeys never needs more than the last 90 days of keys.
Delivery is at least once, but a message can still be lost to a bug or a message the server rejects, and restoring an older backup leaves one side behind. Each of these leaves a symptom on at least one side, so the app repairs a friendship when the app notices a symptom, after every successful feed fetch:
| Symptom | Likely cause | Repair | When |
|---|---|---|---|
A friend's profile or feed items decrypt with none of their keys, while their FollowSecret is still valid |
We missed a rotation, or they restored a backup | FriendRequest |
Straight away, then weekly, at most 4 times |
A friend whose keys never arrived |
Our accept or their reply was lost | Our FriendKeys, then a FriendRequest |
After a week, then weekly, at most 4 times |
A pending request |
The request was lost | FriendRequest |
Once, after two weeks |
Inbox messages are aimed to be small messages which can be encoded and sent to a user with their RSA Public key.
Since RSA has a rather small max payload length, these messages are split into chunks (at most 20), then each chunk is encrypted. These chunks are then sent to the server. The user can use their private key to decrypt the chunks, then stitch them back together to form the original payload. Each message is signed with the sender's RSA private key over the payload, the sender's id and the recipient's id. A FriendRequest that carries a public key is verified with that public key. Every other message is verified with the sender's public key from the server.
Inbox messages are delivered at least once:
- Sending. A message is signed and encrypted when it is created, then written to a local outbox (
feed_outbox). The outbox sends each recipient's messages in order, and retries with backoff when the server cannot be reached. A message the server rejects as invalid is dropped, as are messages to a user the server says does not exist. A message that still has not been sent after 30 days is dropped. - Receiving. The app polls its inbox asking the server to keep messages until they are acknowledged. The app decrypts the messages, writes them to a local queue (
feed_inbox_queue) and acknowledges them. In order to stop unreadable messages being delivered forever, the app acknowledges those messages too. Then the app handles the queue in the order the messages were sent. - Deduplicating. Every message carries a
messageIdand asentAtinside its signed payload. Retries can deliver a message more than once, so the app remembers the ids it has queued for 60 days (feed_inbox_seen) and skips repeats.
Feed item and profile payloads are signed, then encrypted with AES-GCM. AES-GCM authenticates the ciphertext, so a payload that was modified, or encrypted with a different key, fails to decrypt. AES-GCM authentication proves only that someone holding the key wrote the payload, and every friend holds the key, so the RSA signature is what proves which user wrote the payload.
On encryption:
- The SHA256 hash of the payload is calculated - Creating the PayloadHash
- A signature of the PayloadHash is generated with the RSA private key
- The signature is appended to the end of the payload - Creating the SignedPayload
- The SignedPayload is encrypted with AES-GCM under a random 12-byte nonce, and the 16-byte authentication tag is appended - Creating the EncryptedSignedPayload
A nonce is never reused with the same key. A feed item sends its nonce in encryptedEventIV. A profile stores each field (name, current plan) as its own nonce, ciphertext and tag, and leaves encryptionIV empty.
On decryption, each key held for that user is tried, newest first:
- The EncryptedSignedPayload is decrypted with AES-GCM - Creating the SignedPayload
- The last 256 bytes of the SignedPayload are split off - Creating the UnverifiedPayload and the Signature
- The SHA256 hash of the UnverifiedPayload is calculated - Creating the UnverifiedPayloadHash
- The Signature is verified using the PublicKey and the UnverifiedPayloadHash
- If the signature is valid, then the payload is valid
A feed item is shown only if the user named inside the payload is the friend whose key verified the payload. Otherwise one friend could sign an item in another friend's name.
Keys created before AES-GCM are AES-CBC, and a key with no recorded algorithm is AES-CBC. AES-CBC keys use the same steps with a random 16-byte IV, and a profile encrypts every field under the one encryptionIV. AES-CBC does not authenticate ciphertext, so an attacker who knows part of the plaintext can modify the ciphertext without the key, as described in this post by Seald. The RSA signature covers this attack, because a modified payload hashes differently and its signature no longer verifies.
All paths are under app/src/.
store/feed/friend-effects.ts- friend actions (request, accept, deny, share back, remove) and the inbox handlers for friend messages.store/feed/inbox-effects.ts- polling, the inbox queue, and routing each message to its handler.store/feed/outbox-effects.ts- sending the outbox.store/feed/rotation-effects.ts- key rotation.store/feed/repair-effects.ts- repairing friendships that drifted out of sync.store/feed/feed-items-effects.ts- publishing workouts, fetching friends' feed items and profiles.store/feed/live-session-effects.ts- publishing the workout in progress, and ending the live workout when discarded.store/feed/feed-hub-effects.ts- watching friends' live workouts, and fetching the inbox when the hub says to.services/feed-hub-service.ts- the connection to the feed hub, held open while the feed or a live workout needs the connection.store/feed/feed-timeline.ts- merging your own sessions into the feed.services/feed-follow-service.ts- building and encrypting inbox messages.services/js-migrations/merge-follows-into-friends.ts- turning follows into friends.