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
Account delete: a cookie sent as a Bearer gets no device pass
Duarte Santos7c811c76392f
diff --git a/api/server.js b/api/server.jsindex ff6b19f11..88ca67969 100644--- a/api/server.js+++ b/api/server.js@@ -2308,7 +2308,12 @@ const routes = {const lastAdmin = () => lastAdminLeaving(user);const refuseLastAdmin = () => json(res, 409, { error: 'the last admin cannot leave while other profiles remain', code: 'last-admin' });if (lastAdmin()) return refuseLastAdmin();- const proof = s.bearer && !passwordWayIn(user) ? 'device' : await proveOwner(req, res, user, body, 'account-delete');+ // The pairing is the proof only for a token the pairing made: a browser's cookie value+ // replayed in an Authorization header is a Bearer too, and is told apart by its kind (`c`,+ // makeSession). Without this a cookie someone walked off with deleted a passkey-only profile+ // with no proof at all, the one case this route exists to refuse.+ const paired = s.bearer && s.kind !== 'c';+ const proof = paired && !passwordWayIn(user) ? 'device' : await proveOwner(req, res, user, body, 'account-delete');if (!proof) return;// Everything above awaited: the session may have ended, and another admin may have left.if (readSession(req) !== user) return json(res, 401, { error: 'not signed in' });diff --git a/api/test/server-account-delete.test.js b/api/test/server-account-delete.test.jsindex ae811f4ba..ea5e36724 100644--- a/api/test/server-account-delete.test.js+++ b/api/test/server-account-delete.test.js@@ -183,6 +183,28 @@ test('a browser never gets the phone’s pass: no proof, no delete', async t =>assert.equal(h.db().users.length, 2);});+test('a browser cookie replayed as a Bearer is still a cookie: no device pass', async t => {+ const h = await startServer(t, { users: ['admin', 'nopw'] });+ // A cookie as the server mints it for a browser: the fourth field says `c`.+ const payload = `u_nopw:${Date.now() + 86400000}:0:c`;+ const cookie = payload + '.' + crypto.createHmac('sha256', SECRET).update(payload).digest('base64url');+ const r = await fetch(`${h.api}/api/account/delete`, {+ method: 'POST', headers: { Authorization: `Bearer ${cookie}`, 'Content-Type': 'application/json' },+ body: JSON.stringify({ name: 'Keyonly' })+ });+ assert.equal(r.status, 403);+ assert.equal((await r.json()).code, 'passkey-required');+ assert.equal(h.db().users.length, 2, 'nothing was removed');+ // A token the pairing made (`b`) still carries the device pass.+ const pb = `u_nopw:${Date.now() + 86400000}:0:b`;+ const paired = pb + '.' + crypto.createHmac('sha256', SECRET).update(pb).digest('base64url');+ const ok = await fetch(`${h.api}/api/account/delete`, {+ method: 'POST', headers: { Authorization: `Bearer ${paired}`, 'Content-Type': 'application/json' },+ body: JSON.stringify({ name: 'Keyonly' })+ });+ assert.equal(ok.status, 200);+});+test('needs proof that the owner is here: missing or wrong, nothing is removed', async t => {const h = await startServer(t, { users: ['admin', 'user', 'nopw'] });const none = await h.del(USER, { name: 'Mallory' });