instar 1.3.2009 → 1.3.2011

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.
Files changed (59) hide show
  1. package/dashboard-pair/service-yes.js +48 -5
  2. package/dist/core/PinAttemptStore.d.ts +11 -0
  3. package/dist/core/PinAttemptStore.d.ts.map +1 -1
  4. package/dist/core/PinAttemptStore.js +30 -7
  5. package/dist/core/PinAttemptStore.js.map +1 -1
  6. package/dist/core/devGatedFeatures.d.ts.map +1 -1
  7. package/dist/core/devGatedFeatures.js +6 -0
  8. package/dist/core/devGatedFeatures.js.map +1 -1
  9. package/dist/data/standards-guard-index.json +1 -1
  10. package/dist/data/standards-guard-index.meta.json +2 -2
  11. package/dist/data/standards-registry.meta.json +1 -1
  12. package/dist/native/InstarWedgeCanary.app/Contents/MacOS/InstarWedgeCanary +0 -0
  13. package/dist/native/instar-desktop-host +0 -0
  14. package/dist/recommended/confirmStats.d.ts +52 -0
  15. package/dist/recommended/confirmStats.d.ts.map +1 -0
  16. package/dist/recommended/confirmStats.js +149 -0
  17. package/dist/recommended/confirmStats.js.map +1 -0
  18. package/dist/recommended/confirmTokens.d.ts +29 -4
  19. package/dist/recommended/confirmTokens.d.ts.map +1 -1
  20. package/dist/recommended/confirmTokens.js +51 -9
  21. package/dist/recommended/confirmTokens.js.map +1 -1
  22. package/dist/recommended/reoffers.d.ts +9 -3
  23. package/dist/recommended/reoffers.d.ts.map +1 -1
  24. package/dist/recommended/reoffers.js +27 -3
  25. package/dist/recommended/reoffers.js.map +1 -1
  26. package/dist/server/AgentServer.d.ts +2 -0
  27. package/dist/server/AgentServer.d.ts.map +1 -1
  28. package/dist/server/AgentServer.js +151 -46
  29. package/dist/server/AgentServer.js.map +1 -1
  30. package/dist/server/CapabilityIndex.js +1 -1
  31. package/dist/server/CapabilityIndex.js.map +1 -1
  32. package/dist/server/middleware.d.ts.map +1 -1
  33. package/dist/server/middleware.js +4 -0
  34. package/dist/server/middleware.js.map +1 -1
  35. package/dist/server/publicPinHook.d.ts +61 -0
  36. package/dist/server/publicPinHook.d.ts.map +1 -0
  37. package/dist/server/publicPinHook.js +3 -0
  38. package/dist/server/publicPinHook.js.map +1 -0
  39. package/dist/server/recommendedServiceRoutes.d.ts +19 -0
  40. package/dist/server/recommendedServiceRoutes.d.ts.map +1 -1
  41. package/dist/server/recommendedServiceRoutes.js +94 -8
  42. package/dist/server/recommendedServiceRoutes.js.map +1 -1
  43. package/dist/server/routes.d.ts +2 -0
  44. package/dist/server/routes.d.ts.map +1 -1
  45. package/dist/server/routes.js +25 -0
  46. package/dist/server/routes.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/data/awareness/approval-link-guess-bound.md +4 -0
  49. package/src/data/awareness/recommended-services-reoffers.md +1 -1
  50. package/src/data/builtin-manifest.json +47 -47
  51. package/src/data/feature-ladders.json +1 -0
  52. package/src/data/standards-guard-index.json +1 -1
  53. package/src/data/standards-guard-index.meta.json +2 -2
  54. package/src/data/standards-registry.meta.json +1 -1
  55. package/src/data/state-coherence-registry.json +34 -0
  56. package/upgrades/1.3.2010.md +20 -0
  57. package/upgrades/1.3.2011.md +36 -0
  58. package/upgrades/side-effects/recommended-services-reoffers.md +3 -0
  59. package/upgrades/side-effects/sec135-approval-link-guess-bound.md +134 -0
@@ -342,6 +342,7 @@ import { MoneyLayerEnableSurface } from '../core/MoneyLayerEnableSurface.js';
342
342
  import { PROBE_DOOR, PROBE_KEY_REF } from '../core/moneyLayerProbe.js';
343
343
  import { moneyLayerShouldConstruct } from '../core/moneyLayerEnable.js';
344
344
  import { PinAttemptStore } from '../core/PinAttemptStore.js';
345
+ import { PUBLIC_PIN_REQUEST_MAX } from './publicPinHook.js';
345
346
  import { SpendAlertResolver, buildStalePriceAlert } from '../core/SpendAlertResolver.js';
346
347
  import { SpendAlertDispatcher } from '../core/SpendAlertDispatcher.js';
347
348
  import { TelegramSpendTopicChannel, spendAlertDeliveryId } from '../core/TelegramSpendTopicChannel.js';
@@ -928,6 +929,8 @@ export class AgentServer {
928
929
  meteredSpendGate = null;
929
930
  spendPlanStore = null;
930
931
  pinAttemptStore = null;
932
+ /** SEC-135: sign-in's public PIN limits, handed to routes as ctx.publicPin. Set in the constructor. */
933
+ publicPinHook = null;
931
934
  meteredSweepTimer = null;
932
935
  spendAlertResolver = null;
933
936
  spendAlertTimer = null;
@@ -1484,54 +1487,76 @@ export class AgentServer {
1484
1487
  const markerId = readPinMarker(req);
1485
1488
  return { ip, markerId, isLocalDirect, localUnmarked: isLocalDirect && !markerId };
1486
1489
  };
1487
- /** True when the attempt may reach the compare; otherwise the 429 is already sent. */
1488
- const publicPinAdmit = (c, res, now) => {
1489
- if (c.localUnmarked && localPinBlocked(now)) {
1490
- res.status(429).json({
1491
- error: 'Too many wrong PINs from this machine. Use a browser you have unlocked before or the paired phone app, or try again in a few minutes.',
1492
- retryAfterSeconds: Math.ceil(LOCAL_PIN_WINDOW_MS / 1000),
1493
- });
1494
- return false;
1495
- }
1490
+ const publicPinAdmission = (c, now) => {
1491
+ if (c.localUnmarked && localPinBlocked(now))
1492
+ return { ok: false, limit: 'local', retryAfterSeconds: Math.ceil(LOCAL_PIN_WINDOW_MS / 1000) };
1496
1493
  if (c.isLocalDirect && !c.markerId)
1497
- return true;
1494
+ return { ok: true };
1498
1495
  const decision = pinThrottle.consult(c.ip, c.markerId, now);
1499
- if (!decision.allow) {
1500
- res.status(429).json({ error: 'Too many PIN attempts. Try again later.', retryAfterSeconds: decision.retryAfterSeconds });
1501
- return false;
1502
- }
1496
+ if (!decision.allow)
1497
+ return { ok: false, limit: 'throttle', retryAfterSeconds: decision.retryAfterSeconds };
1503
1498
  if (!c.isLocalDirect && !c.markerId) {
1504
1499
  // Durable cross-restart backstops, never applied to a known browser: the real client's own
1505
1500
  // budget, and the shared unmarked budget (a restart no longer resets it).
1506
1501
  if ((c.ip && this.pinAttemptStore?.blocked(c.ip)) || this.pinAttemptStore?.blocked(GLOBAL_PIN_KEY, GLOBAL_MAX_ATTEMPTS)) {
1507
- res.status(429).json({ error: this.pinAttemptStore?.pausedAfterCorruptLoad
1508
- ? 'PIN sign-in is paused for a few minutes. Use a browser you have signed in with before, your phone, or this computer.'
1509
- : 'Too many attempts. Try again later.', code: this.pinAttemptStore?.pausedAfterCorruptLoad ? 'pin-paused' : undefined });
1510
- return false;
1502
+ return { ok: false, limit: 'durable', retryAfterSeconds: this.pinAttemptStore?.windowSeconds ?? 300 };
1511
1503
  }
1512
1504
  }
1513
- return true;
1505
+ return { ok: true };
1514
1506
  };
1515
- const publicPinFailure = (c, now) => {
1507
+ /** True when the attempt may reach the compare; otherwise the 429 is already sent. */
1508
+ const publicPinAdmit = (c, res, now) => {
1509
+ const admission = publicPinAdmission(c, now);
1510
+ if (admission.ok)
1511
+ return true;
1512
+ if (admission.limit === 'local') {
1513
+ res.status(429).json({
1514
+ error: 'Too many wrong PINs from this machine. Use a browser you have unlocked before or the paired phone app, or try again in a few minutes.',
1515
+ retryAfterSeconds: admission.retryAfterSeconds,
1516
+ });
1517
+ }
1518
+ else if (admission.limit === 'throttle') {
1519
+ res.status(429).json({ error: 'Too many PIN attempts. Try again later.', retryAfterSeconds: admission.retryAfterSeconds });
1520
+ }
1521
+ else {
1522
+ res.status(429).json({ error: this.pinAttemptStore?.pausedAfterCorruptLoad
1523
+ ? 'PIN sign-in is paused for a few minutes. Use a browser you have signed in with before, your phone, or this computer.'
1524
+ : 'Too many attempts. Try again later.', code: this.pinAttemptStore?.pausedAfterCorruptLoad ? 'pin-paused' : undefined });
1525
+ }
1526
+ return false;
1527
+ };
1528
+ /**
1529
+ * Charge one wrong PIN. Every durable key it counts against (the caller's class budget plus any
1530
+ * `extra` key, e.g. an approval link's per-request key) is written in ONE store write. Returns
1531
+ * each charged key's attempts remaining (empty when there is no store).
1532
+ */
1533
+ const publicPinFailure = (c, now, extra = []) => {
1534
+ const keys = [];
1535
+ let bruteForceAlert = false;
1516
1536
  if (!c.isLocalDirect || c.markerId) {
1517
- const { alert } = pinThrottle.recordFailure(c.ip, c.markerId, now);
1537
+ bruteForceAlert = !!pinThrottle.recordFailure(c.ip, c.markerId, now).alert;
1518
1538
  if (!c.isLocalDirect && !c.markerId) {
1519
1539
  if (c.ip)
1520
- this.pinAttemptStore?.recordFailure(c.ip);
1521
- this.pinAttemptStore?.recordFailure(GLOBAL_PIN_KEY, GLOBAL_MAX_ATTEMPTS);
1522
- }
1523
- if (alert) {
1524
- // Plain-words owner alert, downstream of the self-healing cap (Self-Heal Before Notify).
1525
- DegradationReporter.getInstance().report({
1526
- feature: 'DashboardPin.bruteForce',
1527
- primary: 'An attack on the dashboard PIN is under way',
1528
- fallback: 'Unknown browsers are being refused by the hard cap; a known browser or the paired phone app still works',
1529
- reason: 'Sustained wrong-PIN guessing drained the unknown-source cap',
1530
- impact: 'To unlock, use a browser you have unlocked before, or the paired phone app.',
1531
- });
1540
+ keys.push({ key: c.ip });
1541
+ keys.push({ key: GLOBAL_PIN_KEY, max: GLOBAL_MAX_ATTEMPTS });
1532
1542
  }
1533
1543
  }
1534
- if (c.localUnmarked && recordLocalPinFailure(now) && now - lastLocalPinAlertAt >= LOCAL_PIN_ALERT_COOLDOWN_MS) {
1544
+ if (c.localUnmarked && this.pinAttemptStore)
1545
+ keys.push({ key: LOCAL_PIN_KEY, max: LOCAL_PIN_MAX_FAILURES });
1546
+ keys.push(...extra);
1547
+ const remaining = this.pinAttemptStore ? this.pinAttemptStore.recordFailures(keys) : new Map();
1548
+ if (bruteForceAlert) {
1549
+ // Plain-words owner alert, downstream of the self-healing cap (Self-Heal Before Notify).
1550
+ DegradationReporter.getInstance().report({
1551
+ feature: 'DashboardPin.bruteForce',
1552
+ primary: 'An attack on the dashboard PIN is under way',
1553
+ fallback: 'Unknown browsers are being refused by the hard cap; a known browser or the paired phone app still works',
1554
+ reason: 'Sustained wrong-PIN guessing drained the unknown-source cap',
1555
+ impact: 'To unlock, use a browser you have unlocked before, or the paired phone app.',
1556
+ });
1557
+ }
1558
+ const localCapReached = c.localUnmarked && (this.pinAttemptStore ? (remaining.get(LOCAL_PIN_KEY) ?? 1) <= 0 : recordLocalPinFailureInMemory(now));
1559
+ if (localCapReached && now - lastLocalPinAlertAt >= LOCAL_PIN_ALERT_COOLDOWN_MS) {
1535
1560
  lastLocalPinAlertAt = now;
1536
1561
  DegradationReporter.getInstance().report({
1537
1562
  feature: 'DashboardPin.localGuessing',
@@ -1541,6 +1566,7 @@ export class AgentServer {
1541
1566
  impact: 'If this was not you, a program on this machine may be trying to guess your PIN. Your PIN was not accepted.',
1542
1567
  });
1543
1568
  }
1569
+ return remaining;
1544
1570
  };
1545
1571
  /** A correct PIN clears only this source's own counters, never a shared budget. */
1546
1572
  const publicPinSuccess = (c) => {
@@ -1548,6 +1574,21 @@ export class AgentServer {
1548
1574
  if (c.ip)
1549
1575
  this.pinAttemptStore?.recordSuccess(c.ip);
1550
1576
  };
1577
+ /**
1578
+ * The PIN sign-in compares against, read the way sign-in reads it (the durable owner credential
1579
+ * when that policy is in use, else the config). 'unreadable' when the credential read failed.
1580
+ */
1581
+ const readCurrentPin = () => {
1582
+ if (this.usesDurableGraphOwnerPolicy()) {
1583
+ try {
1584
+ configRef.dashboardPin = readConversationGraphOwnerCredential({ stateDir: this.config.stateDir, forceFileKey: this.config.secrets?.forceFileKey }) ?? undefined;
1585
+ }
1586
+ catch {
1587
+ return 'unreadable';
1588
+ } // @silent-fallback-ok — the caller answers 503; nothing is compared
1589
+ }
1590
+ return configRef.dashboardPin || null;
1591
+ };
1551
1592
  // One rule for whether this connection may unlock, shared by the unlock route
1552
1593
  // and the check the console makes BEFORE it shows a PIN box (a box the server
1553
1594
  // will refuse is never shown; the console offers the secure address instead).
@@ -1575,10 +1616,8 @@ export class AgentServer {
1575
1616
  return this.pinAttemptStore.blocked(LOCAL_PIN_KEY, LOCAL_PIN_MAX_FAILURES);
1576
1617
  return now <= localPinMem.resetAt && localPinMem.count >= LOCAL_PIN_MAX_FAILURES;
1577
1618
  };
1578
- /** Records one local failure; true when this failure reached the cap (alert once). */
1579
- const recordLocalPinFailure = (now) => {
1580
- if (this.pinAttemptStore)
1581
- return this.pinAttemptStore.recordFailure(LOCAL_PIN_KEY, LOCAL_PIN_MAX_FAILURES) <= 0;
1619
+ /** Records one local failure when there is no durable store; true when it reached the cap (alert once). */
1620
+ const recordLocalPinFailureInMemory = (now) => {
1582
1621
  if (now > localPinMem.resetAt)
1583
1622
  localPinMem = { count: 0, resetAt: now + LOCAL_PIN_WINDOW_MS };
1584
1623
  localPinMem.count++;
@@ -1586,19 +1625,84 @@ export class AgentServer {
1586
1625
  };
1587
1626
  const LOCAL_PIN_ALERT_COOLDOWN_MS = 30 * 60 * 1000;
1588
1627
  let lastLocalPinAlertAt = -Infinity;
1628
+ // SEC-135 (docs/specs/sec135-approval-link-guess-bound.md §1-2): one synchronous verifier for the
1629
+ // recommended-services confirm page, on sign-in's own limits. No await anywhere in it, so parallel
1630
+ // requests (sign-in or confirm) cannot pass a limit together.
1631
+ const requestKeyMem = new Map();
1632
+ const memRequestBlocked = (key, now) => {
1633
+ const e = requestKeyMem.get(key);
1634
+ if (e && now > e.resetAt) {
1635
+ requestKeyMem.delete(key);
1636
+ return false;
1637
+ }
1638
+ return !!e && e.count >= PUBLIC_PIN_REQUEST_MAX;
1639
+ };
1640
+ const memRequestCharge = (key, now) => {
1641
+ let e = requestKeyMem.get(key);
1642
+ if (!e || now > e.resetAt) {
1643
+ e = { count: 0, resetAt: now + LOCAL_PIN_WINDOW_MS };
1644
+ requestKeyMem.set(key, e);
1645
+ }
1646
+ e.count++;
1647
+ if (requestKeyMem.size > 4096) {
1648
+ const oldest = requestKeyMem.keys().next().value;
1649
+ if (oldest !== undefined)
1650
+ requestKeyMem.delete(oldest);
1651
+ }
1652
+ };
1653
+ /** Whether the strangers' shared aggregate is used up right now (read-only). */
1654
+ const publicAggregateFull = (now) => pinThrottle.consult(UNATTRIBUTED_PIN_SOURCE, null, now).reason === 'global-cap'
1655
+ || this.pinAttemptStore?.blocked(GLOBAL_PIN_KEY, GLOBAL_MAX_ATTEMPTS) === true;
1656
+ const publicPinVerify = (req, candidate, opts) => {
1657
+ if (unlockRefusedHere(req))
1658
+ return { ok: false, reason: 'insecure-connection' };
1659
+ const current = readCurrentPin();
1660
+ if (current === 'unreadable' || !current)
1661
+ return { ok: false, reason: 'unavailable' };
1662
+ const now = Date.now();
1663
+ const c = publicPinContext(req);
1664
+ const path = c.isLocalDirect && !c.markerId ? 'local' : c.markerId ? 'marker' : 'public';
1665
+ const store = this.pinAttemptStore;
1666
+ const admission = publicPinAdmission(c, now);
1667
+ if (!admission.ok)
1668
+ return { ok: false, reason: 'paused', path, retryAfterSeconds: admission.retryAfterSeconds, aggregateFull: publicAggregateFull(now) };
1669
+ // The per-request key is enforced on all three paths, durable when the store is there, else in memory.
1670
+ if (store ? store.blocked(opts.requestKey, PUBLIC_PIN_REQUEST_MAX) : memRequestBlocked(opts.requestKey, now)) {
1671
+ return { ok: false, reason: 'paused', path, retryAfterSeconds: store?.windowSeconds ?? Math.ceil(LOCAL_PIN_WINDOW_MS / 1000), aggregateFull: publicAggregateFull(now) };
1672
+ }
1673
+ if (typeof candidate !== 'string' || !candidate)
1674
+ return { ok: false, reason: 'missing', path };
1675
+ const ha = createHash('sha256').update(candidate).digest();
1676
+ const hb = createHash('sha256').update(current).digest();
1677
+ if (!timingSafeEqual(ha, hb)) {
1678
+ const extra = [{ key: opts.requestKey, max: PUBLIC_PIN_REQUEST_MAX }];
1679
+ // Stranger guesses feed the throttle's brute-force alert; marked and local ones feed the alert-only count.
1680
+ const countAlert = path !== 'public' && !!opts.alertKey && !!store && !store.blocked(opts.alertKey, GLOBAL_MAX_ATTEMPTS);
1681
+ if (countAlert)
1682
+ extra.push({ key: opts.alertKey, max: GLOBAL_MAX_ATTEMPTS });
1683
+ const remaining = publicPinFailure(c, now, store ? extra : []);
1684
+ if (!store)
1685
+ memRequestCharge(opts.requestKey, now);
1686
+ if (countAlert && remaining.get(opts.alertKey) === 0) {
1687
+ DegradationReporter.getInstance().report({ feature: 'DashboardPin.approvalLinkGuessing',
1688
+ primary: 'Wrong PINs are being entered on approval links', fallback: 'Each approval link allows only a few wrong PINs',
1689
+ reason: `${GLOBAL_MAX_ATTEMPTS} wrong PINs on approval links within the window`,
1690
+ impact: 'If this was not you, someone may be trying to guess your PIN through an approval link.' });
1691
+ }
1692
+ return { ok: false, reason: 'wrong-pin', path, retryAfterSeconds: 0, aggregateFull: publicAggregateFull(now) };
1693
+ }
1694
+ const aggregateFull = publicAggregateFull(now);
1695
+ publicPinSuccess(c);
1696
+ return { ok: true, path, aggregateFull };
1697
+ };
1698
+ this.publicPinHook = { context: publicPinContext, verify: publicPinVerify };
1589
1699
  this.app.post('/dashboard/unlock', (req, res) => {
1590
1700
  if (unlockRefusedHere(req)) {
1591
1701
  res.status(403).json({ error: 'Open this dashboard through its HTTPS tunnel or from the machine itself.' });
1592
1702
  return;
1593
1703
  }
1594
- if (this.usesDurableGraphOwnerPolicy()) {
1595
- try {
1596
- configRef.dashboardPin = readConversationGraphOwnerCredential({ stateDir: this.config.stateDir, forceFileKey: this.config.secrets?.forceFileKey }) ?? undefined;
1597
- }
1598
- catch {
1599
- return void res.status(503).json({ error: 'PIN authentication is temporarily unavailable.' });
1600
- }
1601
- }
1704
+ if (readCurrentPin() === 'unreadable')
1705
+ return void res.status(503).json({ error: 'PIN authentication is temporarily unavailable.' });
1602
1706
  if (!configRef.dashboardPin || !configRef.authToken) {
1603
1707
  res.status(503).json({ error: 'PIN authentication not yet available. Try again shortly.' });
1604
1708
  return;
@@ -6245,6 +6349,7 @@ export class AgentServer {
6245
6349
  meteredLaneRuntime: this.meteredLaneRuntime,
6246
6350
  requestSupervisedRestart: (reason, requestedBy) => this.requestSupervisedRestart(reason, requestedBy),
6247
6351
  pinAttemptStore: this.pinAttemptStore,
6352
+ publicPin: this.publicPinHook,
6248
6353
  pinEntryRefusedHere: (req) => dashboardUnlockRefused(Boolean(this.directDesktopAccess), req.secure, req.socket.remoteAddress, req.headers['x-forwarded-proto']),
6249
6354
  providerCostReportStore: this.providerCostReportStore,
6250
6355
  resourceLedger: this.resourceLedger,