shadok-ai 0.20.16 → 0.20.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1166,6 +1166,15 @@ know before opening it up:
1166
1166
  the cockpit renews it — or 30 days after the sign-in at the latest), the open tab
1167
1167
  returns you to the login screen on its next request instead of failing in
1168
1168
  place — a paste that would not send, an agent list that would not refresh.
1169
+ - **Someone forgot their password.** An admin opens *reset password…* on that
1170
+ person's row in the **Users** panel and hands over the link it shows — valid
1171
+ 48 hours, single use, and they choose the new password themselves, so the
1172
+ admin never types or sees it. Their open sessions stop working right away,
1173
+ including a stolen one. Nobody can reset themselves: ask another admin. The
1174
+ instance password (`admin`) is not an account and is not reset here — change
1175
+ `--password` / `SHADOK_GUI_PASSWORD` and restart. With **two-factor** on that
1176
+ same row reads *recover access…* and offers the three levels below, each
1177
+ confirmed with the acting admin's own passkey.
1169
1178
  - **Two-factor sign-in (passkeys).** From the **Users** panel, anyone signed in
1170
1179
  with a named account can register a passkey on their device — the
1171
1180
  fingerprint / face / PIN unlock of the phone or laptop (WebAuthn, user
package/dist/server.js CHANGED
@@ -1198,9 +1198,11 @@ function loginHtml(v) {
1198
1198
  const e = escapeXml;
1199
1199
  const accent = accentFor(v.theme);
1200
1200
  const name = v.instance || "Shadok-AI";
1201
- const heading = v.invite ? `Welcome, ${e(v.invite.name)}` : e(name);
1201
+ const heading = v.invite ? `${v.invite.reset ? "Hello again" : "Welcome"}, ${e(v.invite.name)}` : e(name);
1202
1202
  const sub = v.invite
1203
- ? "Choose a password to join this cockpit."
1203
+ ? v.invite.reset
1204
+ ? "Choose a new password. The old one no longer works."
1205
+ : "Choose a password to join this cockpit."
1204
1206
  : v.agent
1205
1207
  ? `Sign in to open <b>${e(v.agent)}</b>.`
1206
1208
  : "Sign in to continue.";
@@ -1209,7 +1211,7 @@ function loginHtml(v) {
1209
1211
  const pw = v.invite
1210
1212
  ? '<input id=pw type=password placeholder="Choose a password (8+ characters)" autofocus autocomplete=new-password>'
1211
1213
  : '<input id=pw type=password placeholder="Password" autofocus autocomplete=current-password>';
1212
- const title = v.invite ? `${e(name)} — choose a password` : `${e(name)} — sign in`;
1214
+ const title = v.invite ? `${e(name)} — ${v.invite.reset ? "new password" : "choose a password"}` : `${e(name)} — sign in`;
1213
1215
  return `<!doctype html><meta charset=utf8><meta name=viewport content="width=device-width,initial-scale=1">
1214
1216
  <meta name=robots content="noindex,nofollow"><link rel=icon href="/icons/icon-192.png">
1215
1217
  <title>${title}</title>${v.meta ? "\n" + v.meta : ""}
@@ -1329,8 +1331,8 @@ function sendLogin(req, res, agentId) {
1329
1331
  /** The page an invited person lands on: the login shell, pointed at the
1330
1332
  * redemption route. Same CSP and same nonce — a page that exempted itself from
1331
1333
  * the policy protecting every other page would be a strange message. */
1332
- function invitePage(name, token) {
1333
- return loginHtml({ ...brandView(), invite: { name, token } });
1334
+ function invitePage(name, token, reset = false) {
1335
+ return loginHtml({ ...brandView(), invite: { name, token, reset } });
1334
1336
  }
1335
1337
  /** This server's same-origin guard (see `originAllowed`). */
1336
1338
  /**
@@ -1736,7 +1738,8 @@ app.get("/invite/:token", (req, res) => {
1736
1738
  const v = inviteVerdict(acct, token, Date.now());
1737
1739
  if (!v.ok)
1738
1740
  return res.status(400).type("text").send(v.error);
1739
- return sendAuthPage(res, invitePage(acct.name, token), 200);
1741
+ // A level-1 reset link wears the same form with a different sentence.
1742
+ return sendAuthPage(res, invitePage(acct.name, token, acct.invite?.reason === "password"), 200);
1740
1743
  });
1741
1744
  app.post("/invite/:token", async (req, res) => {
1742
1745
  const token = String(req.params.token ?? "");
@@ -6822,7 +6825,8 @@ function askRequest(me, kind, target) {
6822
6825
  * 2 lost passkey, password known: two admins, then a device code.
6823
6826
  * 3 lost everything: a full reset, effective in 24 h or at a second admin's approval.
6824
6827
  * With two-factor OFF, levels 2 and 3 have nothing to protect and act at once
6825
- * (a device code / the v1 reset), like before.
6828
+ * (a device code / the v1 reset), like before — and no level asks the issuing
6829
+ * admin for a passkey, since there are none to assert there.
6826
6830
  */
6827
6831
  app.post("/2fa/recover", async (req, res) => {
6828
6832
  const me = tfaPerson(req, res, true);
@@ -6835,7 +6839,26 @@ app.post("/2fa/recover", async (req, res) => {
6835
6839
  const v = resetVerdict({ actor: me, target, accounts: loadAccounts() });
6836
6840
  if (!v.ok)
6837
6841
  return res.status(400).json({ error: v.error });
6838
- if (!(await stepUpOk(req, res, me)))
6842
+ // A FRESH passkey, but only while two-factor is ON — `stepUpIfTwoFactor`, the
6843
+ // same gate as inviting or deleting an account.
6844
+ //
6845
+ // Unconditional, this route could not run at all on an instance with
6846
+ // two-factor off: nobody there HAS a passkey (registering one is what turning
6847
+ // it on requires, not the reverse), and the bootstrap admin — the instance
6848
+ // password, which is who an admin is until named accounts exist — cannot hold
6849
+ // one by construction (invariant 46). So every level answered "confirm with
6850
+ // your passkey first", and a lost password had no remedy short of editing the
6851
+ // account file by hand. The comment above this handler already described the
6852
+ // intent ("with two-factor OFF, levels 2 and 3 ... act at once"); the gate
6853
+ // contradicted it.
6854
+ //
6855
+ // What remains when it is off: an admin, signed in, from a same-origin
6856
+ // browser (`tfaPerson(req, res, true)`) — exactly the bar `DELETE /users`
6857
+ // clears, and that one destroys a private space irreversibly. The assertion
6858
+ // defends the SECOND FACTOR, so it is worth demanding only where there is one;
6859
+ // the routes that could undo it for someone (`/2fa/enabled`,
6860
+ // `/2fa/passkey/delete`, `/2fa/enroll-code`) keep it unconditionally.
6861
+ if (!(await stepUpIfTwoFactor(req, res, me)))
6839
6862
  return;
6840
6863
  const now = Date.now();
6841
6864
  if (level === 1) {