Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Docs: more than one passkey per profile and the one-time code for another device, in self-hosting and the security model (#95)
Duarte Santos1f75653fc71f
diff --git a/SECURITY.md b/SECURITY.mdindex 54513f542..343fc00be 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -52,7 +52,9 @@ in the thread; there's no objection, and no request to sit on it indefinitely.being an admin, or creating a profile without a valid code while `INVITE_ONLY=1`. With`PASSWORD_LOGIN=1`: getting a password checked past the sign-in throttle, telling which nameshave a password, setting a password on someone else's profile, or using a reset code twice or- after it expired (`api/password.js`, `api/rate-limit.js`).+ after it expired (`api/password.js`, `api/rate-limit.js`). Adding a passkey to a profile that+ is not yours, removing a profile's last way in, or redeeming a device code twice, after it+ expired, or for a profile it was not made for (`api/passkeys-store.js`, `api/device-link.js`).- **Frontend** — XSS in the React app, or anything that lets a page on another origin read orchange a signed-in user's data.- **Shipped deployment config** — `docker-compose.yml`, `web/nginx.conf`, the two Dockerfiles:@@ -65,10 +67,11 @@ in the thread; there's no objection, and no request to sit on it indefinitely.operator is trusted by design — see the security model below.- Admins reading their users' workout history. That is the documented purpose of the admindashboard, not a leak.-- **Missing rate limiting** on anything but password sign-in, or "I sent 100k requests and it got- slow". With `PASSWORD_LOGIN=1` the API throttles its password routes — sign-in, password signup,- reset codes, changing a password — and nothing else; volume against the rest, passkey sign-in- and pairing included, belongs in the reverse proxy you put in front of it. A way past that+- **Missing rate limiting** on anything but password sign-in and device codes, or "I sent 100k+ requests and it got slow". With `PASSWORD_LOGIN=1` the API throttles its password routes —+ sign-in, password signup, reset codes, changing a password — and it always throttles the+ redemption of one-time device codes; nothing else. Volume against the rest, passkey sign-in and+ pairing included, belongs in the reverse proxy you put in front of it. A way past thatthrottle *is* in scope, and so is genuine amplification (one small request causing unboundedwork).- **Missing security headers.** `web/nginx.conf.template` sets `X-Frame-Options: DENY`,@@ -106,13 +109,25 @@ Read this before hosting openGym for anyone other than yourself.An admin can issue a one-time reset code — 60 random bits, stored as a SHA-256, 24 hours, singleuse — which also removes the old password and ends every session; admin accounts cannot bereset that way (`api/password.js`, the password block in `api/server.js`).+- **More than one passkey, and one-time device codes.** A profile can hold up to 20 passkeys.+ Adding one from Settings, or making the code that lets another device add its own, needs the+ same proof as a first password — a fresh assertion by one of that profile's passkeys, or its+ current password — because each is a way in that outlives "sign out everywhere". The code is+ 12 characters (60 bits), shown once, stored as a SHA-256, good for ten minutes and one passkey;+ a newer code, signing out everywhere, a new password, an admin reset or a disable voids it. It+ never opens a session by itself: redeeming it registers a passkey on that profile (bound to+ `ORIGIN`/`RP_ID` like any other), and that passkey signs the device in. The redemption routes+ keep the origin check. A profile's last way in — its only passkey, unless a password can sign+ in — cannot be removed. Every addition, removal, code and redemption is audited+ (`api/passkeys-store.js`, `api/device-link.js`, the passkeys block in `api/server.js`).- **Password sign-in is throttled.** Every password route spends a budget of 60 requests a minuteper address; wrong passwords, reset codes and (on password signup) invite codes pause theaddress after 20 (30 s, doubling to 15 min); wrong passwords pause the *name* after 5 (1 min,doubling to 1 h), existing or not. A password check is counted the moment it starts, so guesses- sent all at once get no more checks than guesses sent one by one. Passkey sign-in, passkey- signup and pairing are not throttled at all, so nobody can pause them — not even behind a proxy- that shows the API one address for every visitor. The address is the socket peer unless+ sent all at once get no more checks than guesses sent one by one. The two routes that redeem a+ device code share that budget, and wrong codes pause the address the same way, for code+ redemption only. Passkey sign-in, passkey signup and pairing are not throttled at all, so nobody+ can pause them — not even behind a proxy that shows the API one address for every visitor. The address is the socket peer unless`TRUST_PROXY=1` (set by the bundled compose file, where only the web container reaches theAPI), and IPv6 is counted per /64 (`api/rate-limit.js`).- **Sessions are a signed cookie.** It carries `<uid>:<expiry>:<version>` plus an@@ -183,16 +198,23 @@ Read this before hosting openGym for anyone other than yourself.missing (`api/server.js:344`). Requests authenticated with a Bearer token skip the check —a browser never attaches one by itself, so there is no ambient authority to borrow — as do theregister/login/pair handshakes, which carry their own credential in the body and act on no- existing session (`api/server.js:338`).+ existing session (`api/server.js:338`). The device-code routes are not exempt: a code is+ redeemed on the app's own origin, the only one a passkey for it can be created on.- **User verification is preferred, not required.** Both handshakes pass`requireUserVerification: false` (`api/server.js:575`, `api/server.js:644`), so a passkeyreleased without a biometric or PIN is still accepted. In practice: unlocked device ≈ accountaccess.-- **One passkey per profile, and recovery only through an admin.** Every successful- registration creates a *new* profile; there is no route to attach a second passkey to an- existing one, and no email path. Lose the passkey and that profile is unreachable — unless the+- **Recovery is another passkey, or an admin.** A profile can hold several passkeys, and a+ signed-in device can give a new one its own with a device code; there is no email path. Lose+ every passkey (and every signed-in device) and that profile is unreachable — unless theinstance runs `PASSWORD_LOGIN=1`, where an admin can issue a reset code that sets a password onit. Without that, only direct surgery on `./data` gets it back.+- **A device code is a capability, and removing a passkey does not end sessions.** Anyone who+ reads a code off the screen within its ten minutes can add a passkey to that profile; the owner+ sees it in Settings → Passkeys and in the activity log (`auth.link.ok`) and can remove it.+ Sessions are `uid:expiry:version` and are not tied to the passkey that opened them, so removing+ a passkey stops it signing in but leaves any session it opened running; "sign out everywhere"+ ends those.- **A password is weaker than a passkey, and the throttle is per process.** It can be phished,reused elsewhere or guessed; a stolen `db.json` allows offline guessing against the scrypthashes. The throttle's counters live in memory: a restart clears them, and several API replicas@@ -213,9 +235,9 @@ Read this before hosting openGym for anyone other than yourself.nginx listens on `:80` (`web/nginx.conf`); TLS is your reverse proxy's job. Without it,browsers won't do passkeys at all (except on `http://localhost`) and the session cookie is sentin the clear.-- **Rate limiting covers password sign-in only.** The throttle above applies to the password- routes; passkey sign-in and signup, pairing, writes and everything else behind a session are- not limited, so an instance on the open internet should have a rate limit in front of it. `POST+- **Rate limiting covers password sign-in and device codes only.** The throttle above applies to+ the password routes and to device-code redemption; passkey sign-in and signup, pairing, writes+ and everything else behind a session are not limited, so an instance on the open internet should have a rate limit in front of it. `POST/api/register/options` still answers whether an invite code is valid, unthrottled. New invitecodes are 16 hex characters — 64 bits — which makes guessing one impractical even unthrottled;codes generated by earlier versions are 8 characters / 32 bits and still work, so revoke and@@ -243,7 +265,8 @@ Read this before hosting openGym for anyone other than yourself.than a full disk or a slow server.- **A few endpoints answer without a session:** `/api/health` (which includes the total usercount), `/api/config` (whether invite-only and password sign-in are on), `/api/push/public-key`,- the register/login handshakes, and with `PASSWORD_LOGIN=1` the password sign-in, password+ the register/login handshakes, the two device-code redemption routes (which name the profile a+ valid code belongs to), and with `PASSWORD_LOGIN=1` the password sign-in, passwordregistration and reset-code routes. Password registration says when a name is already takenby a profile with a password, as any sign-up form with usernames does; on an invite-onlyinstance only someone with a valid code gets that far.diff --git a/docs/SELF_HOSTING.md b/docs/SELF_HOSTING.mdindex a9642723a..d6a0d467c 100644--- a/docs/SELF_HOSTING.md+++ b/docs/SELF_HOSTING.md@@ -470,18 +470,45 @@ be stored in Google Password Manager. (#101)**Firefox on Windows 10 does not offer a QR code to sign in with my phone.** Firefox on Windowshands passkeys to Windows' own dialog, and the Windows 10 dialog has no *use a phone* option;Windows 11 added it. On Windows 10, sign in with Chrome or Edge, which show their own QR code, or-keep the passkey in a password manager that has a Firefox extension. (#103)+keep the passkey in a password manager that has a Firefox extension — or give that PC a passkey+of its own (Windows Hello works in Firefox) with a code from your phone, below. (#103)++**Can one profile have more than one passkey?** Yes. **Settings → Account → Passkeys** lists+them — a name, when each was added and last used — and adds, renames or removes one. Adding one+from there is for anything this browser can reach: another password manager, a security key, or+your phone through the browser's own QR prompt. For a second device that can open openGym itself+(a phone, a work laptop), use **Settings → Account → Add another device**: it shows a code of 12+characters and a QR code of a link that carries it. Scan it with the other device, or type the+code there under **Use a code from your other device** on the sign-in screen; the other device+then creates a passkey of its own and is signed in by it. So a Windows Hello passkey on a PC and+the phone's own passkey can sign in to the same profile, instead of the phone ending up with a+second, empty one. (#95)++Both ways ask you to confirm first — with a passkey the profile already has, or its password —+because each adds a lasting way in: a session on its own may be a copied cookie. The code works+once, for ten minutes, and is stored only as a hash; making a new one, signing out everywhere or+changing the password voids it. Wrong codes count toward a per-address pause of code redemption,+like wrong reset codes, and every passkey added or removed and every code made or used is in the+activity log (`auth.passkey.*`, `auth.link.*`).++The last way into a profile cannot be removed: its only passkey stays unless a password can sign+in instead, which counts only while `PASSWORD_LOGIN=1`. Removing a passkey stops it signing in,+but it does not end a session it already opened — sessions are not tied to one passkey. If the+device is lost, remove its passkey *and* use **Sign out everywhere**.**Where does my passkey live?** Where you created it, and wherever that store syncs: GooglePassword Manager to Chrome on your other devices signed in to the same Google account, iCloudKeychain to your Apple devices, a password manager to every device it runs on. A passkey keptonly on one phone (or on a hardware key) goes with that phone.-**I lost my passkey.** An account has one passkey, the one it was registered with, and there is-no self-service recovery yet. If any device is still signed in (a browser, a paired phone),-export a backup there (**Settings → Export backup (JSON)**), register a new profile and import-it. When you ask your admin for help, the id under **Settings → Account → Account ID** tells them-exactly which account is yours.+**I lost my passkey.** If the profile has another passkey, sign in with that one and remove the+lost one under **Settings → Account → Passkeys** (then **Sign out everywhere**). If a browser is+still signed in, it can give a new device a passkey with **Add another device**. Otherwise there+is no self-service recovery: with `PASSWORD_LOGIN=1` an admin can issue a reset code, and without+it the only way back is a backup (**Settings → Export backup (JSON)**, from any device still+signed in) imported into a new profile. When you ask your admin for help, the id under+**Settings → Account → Account ID** tells them exactly which account is yours. Adding a second+passkey early is what keeps one lost phone from being a lost profile.The phone app never uses a passkey at all: it pairs with a one-time code from a signed-inbrowser (see section 2).