@astram/core 0.1.0

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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/admin/admin-service.d.ts +221 -0
  4. package/dist/admin/admin-service.d.ts.map +1 -0
  5. package/dist/admin/admin-service.js +155 -0
  6. package/dist/admin/admin-service.js.map +1 -0
  7. package/dist/admin/command/grants.d.ts +40 -0
  8. package/dist/admin/command/grants.d.ts.map +1 -0
  9. package/dist/admin/command/grants.js +196 -0
  10. package/dist/admin/command/grants.js.map +1 -0
  11. package/dist/admin/command/index.d.ts +23 -0
  12. package/dist/admin/command/index.d.ts.map +1 -0
  13. package/dist/admin/command/index.js +23 -0
  14. package/dist/admin/command/index.js.map +1 -0
  15. package/dist/admin/command/invitations.d.ts +72 -0
  16. package/dist/admin/command/invitations.d.ts.map +1 -0
  17. package/dist/admin/command/invitations.js +241 -0
  18. package/dist/admin/command/invitations.js.map +1 -0
  19. package/dist/admin/command/permissions.d.ts +33 -0
  20. package/dist/admin/command/permissions.d.ts.map +1 -0
  21. package/dist/admin/command/permissions.js +67 -0
  22. package/dist/admin/command/permissions.js.map +1 -0
  23. package/dist/admin/command/pipeline.d.ts +79 -0
  24. package/dist/admin/command/pipeline.d.ts.map +1 -0
  25. package/dist/admin/command/pipeline.js +106 -0
  26. package/dist/admin/command/pipeline.js.map +1 -0
  27. package/dist/admin/command/policies.d.ts +50 -0
  28. package/dist/admin/command/policies.d.ts.map +1 -0
  29. package/dist/admin/command/policies.js +219 -0
  30. package/dist/admin/command/policies.js.map +1 -0
  31. package/dist/admin/command/service-accounts.d.ts +58 -0
  32. package/dist/admin/command/service-accounts.d.ts.map +1 -0
  33. package/dist/admin/command/service-accounts.js +272 -0
  34. package/dist/admin/command/service-accounts.js.map +1 -0
  35. package/dist/admin/command/service.d.ts +65 -0
  36. package/dist/admin/command/service.d.ts.map +1 -0
  37. package/dist/admin/command/service.js +128 -0
  38. package/dist/admin/command/service.js.map +1 -0
  39. package/dist/admin/command/tiers.d.ts +40 -0
  40. package/dist/admin/command/tiers.d.ts.map +1 -0
  41. package/dist/admin/command/tiers.js +79 -0
  42. package/dist/admin/command/tiers.js.map +1 -0
  43. package/dist/admin/index.d.ts +36 -0
  44. package/dist/admin/index.d.ts.map +1 -0
  45. package/dist/admin/index.js +63 -0
  46. package/dist/admin/index.js.map +1 -0
  47. package/dist/admin/ports.d.ts +288 -0
  48. package/dist/admin/ports.d.ts.map +1 -0
  49. package/dist/admin/ports.js +39 -0
  50. package/dist/admin/ports.js.map +1 -0
  51. package/dist/admin/query/audit-view.d.ts +52 -0
  52. package/dist/admin/query/audit-view.d.ts.map +1 -0
  53. package/dist/admin/query/audit-view.js +84 -0
  54. package/dist/admin/query/audit-view.js.map +1 -0
  55. package/dist/admin/query/catalog.d.ts +70 -0
  56. package/dist/admin/query/catalog.d.ts.map +1 -0
  57. package/dist/admin/query/catalog.js +169 -0
  58. package/dist/admin/query/catalog.js.map +1 -0
  59. package/dist/admin/query/explain.d.ts +52 -0
  60. package/dist/admin/query/explain.d.ts.map +1 -0
  61. package/dist/admin/query/explain.js +145 -0
  62. package/dist/admin/query/explain.js.map +1 -0
  63. package/dist/admin/query/index.d.ts +45 -0
  64. package/dist/admin/query/index.d.ts.map +1 -0
  65. package/dist/admin/query/index.js +58 -0
  66. package/dist/admin/query/index.js.map +1 -0
  67. package/dist/admin/query/simulate.d.ts +42 -0
  68. package/dist/admin/query/simulate.d.ts.map +1 -0
  69. package/dist/admin/query/simulate.js +91 -0
  70. package/dist/admin/query/simulate.js.map +1 -0
  71. package/dist/admin/safeguards-impl.d.ts +67 -0
  72. package/dist/admin/safeguards-impl.d.ts.map +1 -0
  73. package/dist/admin/safeguards-impl.js +318 -0
  74. package/dist/admin/safeguards-impl.js.map +1 -0
  75. package/dist/admin/safeguards.d.ts +89 -0
  76. package/dist/admin/safeguards.d.ts.map +1 -0
  77. package/dist/admin/safeguards.js +91 -0
  78. package/dist/admin/safeguards.js.map +1 -0
  79. package/dist/admin/types.d.ts +485 -0
  80. package/dist/admin/types.d.ts.map +1 -0
  81. package/dist/admin/types.js +38 -0
  82. package/dist/admin/types.js.map +1 -0
  83. package/dist/audit/audit-recorder.d.ts +129 -0
  84. package/dist/audit/audit-recorder.d.ts.map +1 -0
  85. package/dist/audit/audit-recorder.js +265 -0
  86. package/dist/audit/audit-recorder.js.map +1 -0
  87. package/dist/audit/canonicalize.d.ts +38 -0
  88. package/dist/audit/canonicalize.d.ts.map +1 -0
  89. package/dist/audit/canonicalize.js +174 -0
  90. package/dist/audit/canonicalize.js.map +1 -0
  91. package/dist/audit/errors.d.ts +56 -0
  92. package/dist/audit/errors.d.ts.map +1 -0
  93. package/dist/audit/errors.js +41 -0
  94. package/dist/audit/errors.js.map +1 -0
  95. package/dist/audit/index.d.ts +45 -0
  96. package/dist/audit/index.d.ts.map +1 -0
  97. package/dist/audit/index.js +24 -0
  98. package/dist/audit/index.js.map +1 -0
  99. package/dist/audit/ports.d.ts +131 -0
  100. package/dist/audit/ports.d.ts.map +1 -0
  101. package/dist/audit/ports.js +27 -0
  102. package/dist/audit/ports.js.map +1 -0
  103. package/dist/audit/sensitive.d.ts +68 -0
  104. package/dist/audit/sensitive.d.ts.map +1 -0
  105. package/dist/audit/sensitive.js +159 -0
  106. package/dist/audit/sensitive.js.map +1 -0
  107. package/dist/audit/walk.d.ts +109 -0
  108. package/dist/audit/walk.d.ts.map +1 -0
  109. package/dist/audit/walk.js +117 -0
  110. package/dist/audit/walk.js.map +1 -0
  111. package/dist/authentication/authenticator.d.ts +74 -0
  112. package/dist/authentication/authenticator.d.ts.map +1 -0
  113. package/dist/authentication/authenticator.js +208 -0
  114. package/dist/authentication/authenticator.js.map +1 -0
  115. package/dist/authentication/credential-resolver.d.ts +76 -0
  116. package/dist/authentication/credential-resolver.d.ts.map +1 -0
  117. package/dist/authentication/credential-resolver.js +21 -0
  118. package/dist/authentication/credential-resolver.js.map +1 -0
  119. package/dist/authentication/index.d.ts +52 -0
  120. package/dist/authentication/index.d.ts.map +1 -0
  121. package/dist/authentication/index.js +27 -0
  122. package/dist/authentication/index.js.map +1 -0
  123. package/dist/authentication/password-hasher.d.ts +41 -0
  124. package/dist/authentication/password-hasher.d.ts.map +1 -0
  125. package/dist/authentication/password-hasher.js +21 -0
  126. package/dist/authentication/password-hasher.js.map +1 -0
  127. package/dist/authentication/totp.d.ts +101 -0
  128. package/dist/authentication/totp.d.ts.map +1 -0
  129. package/dist/authentication/totp.js +151 -0
  130. package/dist/authentication/totp.js.map +1 -0
  131. package/dist/authorization/cross-tenant/grant-evaluator.d.ts +90 -0
  132. package/dist/authorization/cross-tenant/grant-evaluator.d.ts.map +1 -0
  133. package/dist/authorization/cross-tenant/grant-evaluator.js +165 -0
  134. package/dist/authorization/cross-tenant/grant-evaluator.js.map +1 -0
  135. package/dist/authorization/decision-authority.d.ts +212 -0
  136. package/dist/authorization/decision-authority.d.ts.map +1 -0
  137. package/dist/authorization/decision-authority.js +200 -0
  138. package/dist/authorization/decision-authority.js.map +1 -0
  139. package/dist/authorization/default-gates.d.ts +41 -0
  140. package/dist/authorization/default-gates.d.ts.map +1 -0
  141. package/dist/authorization/default-gates.js +47 -0
  142. package/dist/authorization/default-gates.js.map +1 -0
  143. package/dist/authorization/delegation/operation-identity.d.ts +132 -0
  144. package/dist/authorization/delegation/operation-identity.d.ts.map +1 -0
  145. package/dist/authorization/delegation/operation-identity.js +220 -0
  146. package/dist/authorization/delegation/operation-identity.js.map +1 -0
  147. package/dist/authorization/errors.d.ts +54 -0
  148. package/dist/authorization/errors.d.ts.map +1 -0
  149. package/dist/authorization/errors.js +63 -0
  150. package/dist/authorization/errors.js.map +1 -0
  151. package/dist/authorization/gates/object-type.d.ts +63 -0
  152. package/dist/authorization/gates/object-type.d.ts.map +1 -0
  153. package/dist/authorization/gates/object-type.js +177 -0
  154. package/dist/authorization/gates/object-type.js.map +1 -0
  155. package/dist/authorization/gates/tenant.d.ts +50 -0
  156. package/dist/authorization/gates/tenant.d.ts.map +1 -0
  157. package/dist/authorization/gates/tenant.js +87 -0
  158. package/dist/authorization/gates/tenant.js.map +1 -0
  159. package/dist/authorization/gates/wiring.d.ts +57 -0
  160. package/dist/authorization/gates/wiring.d.ts.map +1 -0
  161. package/dist/authorization/gates/wiring.js +56 -0
  162. package/dist/authorization/gates/wiring.js.map +1 -0
  163. package/dist/authorization/index.d.ts +136 -0
  164. package/dist/authorization/index.d.ts.map +1 -0
  165. package/dist/authorization/index.js +82 -0
  166. package/dist/authorization/index.js.map +1 -0
  167. package/dist/authorization/ports.d.ts +271 -0
  168. package/dist/authorization/ports.d.ts.map +1 -0
  169. package/dist/authorization/ports.js +36 -0
  170. package/dist/authorization/ports.js.map +1 -0
  171. package/dist/authorization/reason-codes.d.ts +75 -0
  172. package/dist/authorization/reason-codes.d.ts.map +1 -0
  173. package/dist/authorization/reason-codes.js +98 -0
  174. package/dist/authorization/reason-codes.js.map +1 -0
  175. package/dist/authorization/record/permit-tier.d.ts +57 -0
  176. package/dist/authorization/record/permit-tier.d.ts.map +1 -0
  177. package/dist/authorization/record/permit-tier.js +79 -0
  178. package/dist/authorization/record/permit-tier.js.map +1 -0
  179. package/dist/authorization/record/rule-evaluator.d.ts +116 -0
  180. package/dist/authorization/record/rule-evaluator.d.ts.map +1 -0
  181. package/dist/authorization/record/rule-evaluator.js +125 -0
  182. package/dist/authorization/record/rule-evaluator.js.map +1 -0
  183. package/dist/authorization/record/shares.d.ts +70 -0
  184. package/dist/authorization/record/shares.d.ts.map +1 -0
  185. package/dist/authorization/record/shares.js +107 -0
  186. package/dist/authorization/record/shares.js.map +1 -0
  187. package/dist/identity/broker.d.ts +59 -0
  188. package/dist/identity/broker.d.ts.map +1 -0
  189. package/dist/identity/broker.js +135 -0
  190. package/dist/identity/broker.js.map +1 -0
  191. package/dist/identity/claim-mapper.d.ts +84 -0
  192. package/dist/identity/claim-mapper.d.ts.map +1 -0
  193. package/dist/identity/claim-mapper.js +48 -0
  194. package/dist/identity/claim-mapper.js.map +1 -0
  195. package/dist/identity/index.d.ts +60 -0
  196. package/dist/identity/index.d.ts.map +1 -0
  197. package/dist/identity/index.js +24 -0
  198. package/dist/identity/index.js.map +1 -0
  199. package/dist/identity/internal-adapter.d.ts +54 -0
  200. package/dist/identity/internal-adapter.d.ts.map +1 -0
  201. package/dist/identity/internal-adapter.js +88 -0
  202. package/dist/identity/internal-adapter.js.map +1 -0
  203. package/dist/index.d.ts +43 -0
  204. package/dist/index.d.ts.map +1 -0
  205. package/dist/index.js +48 -0
  206. package/dist/index.js.map +1 -0
  207. package/dist/metadata/completeness.d.ts +136 -0
  208. package/dist/metadata/completeness.d.ts.map +1 -0
  209. package/dist/metadata/completeness.js +106 -0
  210. package/dist/metadata/completeness.js.map +1 -0
  211. package/dist/metadata/dependencies.d.ts +114 -0
  212. package/dist/metadata/dependencies.d.ts.map +1 -0
  213. package/dist/metadata/dependencies.js +105 -0
  214. package/dist/metadata/dependencies.js.map +1 -0
  215. package/dist/metadata/index.d.ts +153 -0
  216. package/dist/metadata/index.d.ts.map +1 -0
  217. package/dist/metadata/index.js +51 -0
  218. package/dist/metadata/index.js.map +1 -0
  219. package/dist/metadata/registry.d.ts +23 -0
  220. package/dist/metadata/registry.d.ts.map +1 -0
  221. package/dist/metadata/registry.js +204 -0
  222. package/dist/metadata/registry.js.map +1 -0
  223. package/dist/risk/evaluator.d.ts +76 -0
  224. package/dist/risk/evaluator.d.ts.map +1 -0
  225. package/dist/risk/evaluator.js +59 -0
  226. package/dist/risk/evaluator.js.map +1 -0
  227. package/dist/risk/index.d.ts +40 -0
  228. package/dist/risk/index.d.ts.map +1 -0
  229. package/dist/risk/index.js +20 -0
  230. package/dist/risk/index.js.map +1 -0
  231. package/dist/risk/risk-engine.d.ts +76 -0
  232. package/dist/risk/risk-engine.d.ts.map +1 -0
  233. package/dist/risk/risk-engine.js +287 -0
  234. package/dist/risk/risk-engine.js.map +1 -0
  235. package/dist/risk/signals.d.ts +60 -0
  236. package/dist/risk/signals.d.ts.map +1 -0
  237. package/dist/risk/signals.js +104 -0
  238. package/dist/risk/signals.js.map +1 -0
  239. package/dist/risk/thresholds.d.ts +54 -0
  240. package/dist/risk/thresholds.d.ts.map +1 -0
  241. package/dist/risk/thresholds.js +60 -0
  242. package/dist/risk/thresholds.js.map +1 -0
  243. package/dist/session/index.d.ts +47 -0
  244. package/dist/session/index.d.ts.map +1 -0
  245. package/dist/session/index.js +20 -0
  246. package/dist/session/index.js.map +1 -0
  247. package/dist/session/lifetimes.d.ts +50 -0
  248. package/dist/session/lifetimes.d.ts.map +1 -0
  249. package/dist/session/lifetimes.js +67 -0
  250. package/dist/session/lifetimes.js.map +1 -0
  251. package/dist/session/ports.d.ts +266 -0
  252. package/dist/session/ports.d.ts.map +1 -0
  253. package/dist/session/ports.js +23 -0
  254. package/dist/session/ports.js.map +1 -0
  255. package/dist/session/session-authority.d.ts +97 -0
  256. package/dist/session/session-authority.d.ts.map +1 -0
  257. package/dist/session/session-authority.js +393 -0
  258. package/dist/session/session-authority.js.map +1 -0
  259. package/package.json +32 -0
@@ -0,0 +1,393 @@
1
+ /**
2
+ * The Session **engine** — the body behind the FROZEN {@link SessionAuthority}
3
+ * seam (`./index.ts`). Establishes a session on login, ROTATES the refresh token
4
+ * on refresh (with THEFT DETECTION), and revokes on logout. Orchestrates the
5
+ * two-tier hybrid storage (ADR-0013): durable MariaDB records written ONLY at
6
+ * lifecycle events, hot Redis state (re)populated at those same events and served
7
+ * per-request WITHOUT ever touching the DB.
8
+ *
9
+ * Mirrors the Authentication engine (`../authentication/authenticator.ts`)
10
+ * EXACTLY: a pure `createSessionAuthority(...)` factory over INJECTED ports, a
11
+ * stateless impl, STRICT `=== true` gates over verdict-returning ports, and a
12
+ * top-level try/catch on every public method → a GENERIC fail-closed reject that
13
+ * NEVER leaks a token, a hash, or resource existence.
14
+ *
15
+ * ── THE SECURITY CORE — reuse detection → lineage kill (ADR-0013/0015):
16
+ * Every refresh rotates the token (mint a new pair, mark the old `rotated`, same
17
+ * lineage). A refresh token presented AFTER it was rotated out (or after the
18
+ * lineage was revoked) is a REPLAY — the sign of a stolen token. On that signal
19
+ * the engine calls `recordStore.revokeLineage(lineageId)`, killing EVERY refresh
20
+ * record AND the session in the chain (including the legitimate holder's live
21
+ * token), then rejects. Both the thief and the victim are logged out; the
22
+ * attacker cannot ride a stolen token forward, and the reuse is durably recorded.
23
+ *
24
+ * ── SILENT RECOVERY (ADR-0013): rotate re-populates Redis from the DURABLE record
25
+ * every time. A Redis loss (restart/eviction) is recovered at the user's next
26
+ * refresh with no forced re-login — the durable tier is the source of truth for
27
+ * rotation, and the hot tier is rebuilt from it.
28
+ *
29
+ * ── HOT PATH NEVER TOUCHES THE DB (ADR-0013): the per-request read path
30
+ * ({@link readHotSession}) calls ONLY the hot store; it makes ZERO durable-store
31
+ * calls, and fails CLOSED if the hot store cannot answer (never falls back to
32
+ * MariaDB, ADR-0013/0016).
33
+ *
34
+ * ── PERM-VERSION / FACTS SLOT (ADR-0011): establish seeds a hot record with
35
+ * `permissionsVersion: 0` and an OPAQUE `cachedFacts: null` slot; rotate carries
36
+ * the version forward. This layer only STORES/RE-POPULATES/INVALIDATES the slot —
37
+ * it does NOT project fact content, version-compare, or reload (that is
38
+ * Authorization, step 8).
39
+ *
40
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
41
+ */
42
+ import { resolveLifetimes } from './lifetimes.js';
43
+ /**
44
+ * A single GENERIC failure for every rejected session-lifecycle path (unknown
45
+ * token, replay, expiry, port outage). It NEVER distinguishes them and NEVER
46
+ * carries a token/hash — mirrors the Authentication engine's anti-enumeration
47
+ * reason discipline. Thrown as a typed error so a caller gets a uniform rejection
48
+ * rather than a raw 500 that could leak store internals.
49
+ */
50
+ export const SESSION_REJECTED_REASON = 'session_rejected';
51
+ /** The one error type the engine rejects with — always the generic reason. */
52
+ export class SessionRejectedError extends Error {
53
+ constructor() {
54
+ super(SESSION_REJECTED_REASON);
55
+ this.name = 'SessionRejectedError';
56
+ }
57
+ }
58
+ /** The initial ADR-0011 permission version for a freshly-established session. */
59
+ const INITIAL_PERMISSIONS_VERSION = 0;
60
+ /** The initial cached-facts slot value — not yet projected (Authorization fills it). */
61
+ const INITIAL_CACHED_FACTS = null;
62
+ /** The Redis hot-session key for a session id (tenant-scoped, opaque, no PII). */
63
+ function hotKey(sessionId) {
64
+ return `shield:sess:${sessionId}`;
65
+ }
66
+ /**
67
+ * The concrete engine. Stateless per call; holds only its injected capabilities +
68
+ * the resolved lifetime config. Instances come from {@link createSessionAuthority}.
69
+ */
70
+ class SessionAuthorityImpl {
71
+ recordStore;
72
+ hotStore;
73
+ tokenGenerator;
74
+ refreshHasher;
75
+ clock;
76
+ lifetimes;
77
+ deviceTrust;
78
+ constructor(recordStore, hotStore, tokenGenerator, refreshHasher, clock, lifetimes, deviceTrust) {
79
+ this.recordStore = recordStore;
80
+ this.hotStore = hotStore;
81
+ this.tokenGenerator = tokenGenerator;
82
+ this.refreshHasher = refreshHasher;
83
+ this.clock = clock;
84
+ this.lifetimes = lifetimes;
85
+ this.deviceTrust = deviceTrust;
86
+ }
87
+ // -- establish (login) ----------------------------------------------------
88
+ async establish(principal) {
89
+ try {
90
+ return await this.doEstablish(principal);
91
+ }
92
+ catch {
93
+ // FAIL-CLOSED: any port outage / unexpected throw → a generic rejection,
94
+ // never a raw throw that could leak store internals or a token. The error
95
+ // object is deliberately swallowed so nothing about it can leak.
96
+ throw new SessionRejectedError();
97
+ }
98
+ }
99
+ async doEstablish(principal) {
100
+ // Validate the principal shape (never mint a session for a malformed one).
101
+ if (principal === null ||
102
+ typeof principal !== 'object' ||
103
+ typeof principal.id !== 'string' ||
104
+ principal.id.length === 0 ||
105
+ typeof principal.tenantId !== 'string' ||
106
+ principal.tenantId.length === 0) {
107
+ throw new SessionRejectedError();
108
+ }
109
+ const nowMs = this.clock.nowMs();
110
+ // Opaque unguessable ids via the same crypto port that mints tokens.
111
+ const sessionId = this.tokenGenerator.mint();
112
+ const lineageId = this.tokenGenerator.mint();
113
+ const refreshId = this.tokenGenerator.mint();
114
+ const accessToken = this.tokenGenerator.mint();
115
+ const refreshToken = this.tokenGenerator.mint();
116
+ // ⛔ Hash the refresh token BEFORE it ever reaches the durable store.
117
+ const tokenHash = this.refreshHasher.hash(refreshToken);
118
+ const absoluteExpiresAtMs = nowMs + this.lifetimes.refreshAbsoluteCapMs;
119
+ const idleExpiresAtMs = nowMs + this.lifetimes.refreshIdleMs;
120
+ // Durable tier first (ADR-0013 write ordering: DB record, then hot cache).
121
+ await this.recordStore.createSession({
122
+ sessionId,
123
+ principalId: principal.id,
124
+ tenantId: principal.tenantId,
125
+ issuedAtMs: nowMs,
126
+ absoluteExpiresAtMs,
127
+ });
128
+ await this.recordStore.insertRefreshRecord({
129
+ refreshId,
130
+ sessionId,
131
+ lineageId,
132
+ prevRefreshId: null,
133
+ tokenHash,
134
+ issuedAtMs: nowMs,
135
+ idleExpiresAtMs,
136
+ });
137
+ // Advisory device-trust hook (no-op slot). Never gates establishment; its
138
+ // result is not consumed by this layer beyond being invoked for future hooks.
139
+ await this.runDeviceTrust(principal, sessionId);
140
+ // Hot tier: seed the per-request record with the ADR-0011 version + facts slot.
141
+ await this.putHot(sessionId, principal, INITIAL_PERMISSIONS_VERSION, INITIAL_CACHED_FACTS);
142
+ const session = this.freezeSession({
143
+ sessionId,
144
+ principalId: principal.id,
145
+ tenantId: principal.tenantId,
146
+ status: 'active',
147
+ issuedAtMs: nowMs,
148
+ // Session-level expiry = the access-token bound (hot state TTL). Absolute
149
+ // cap lives on the durable record; refresh sliding window on the refresh record.
150
+ expiresAtMs: nowMs + this.lifetimes.accessTtlMs,
151
+ });
152
+ // The raw refresh token leaves the engine EXACTLY ONCE, here. Never persisted.
153
+ return Object.freeze({
154
+ session,
155
+ tokens: Object.freeze({ accessToken, refreshToken }),
156
+ });
157
+ }
158
+ // -- rotate (refresh) -----------------------------------------------------
159
+ async rotate(refreshToken) {
160
+ try {
161
+ return await this.doRotate(refreshToken);
162
+ }
163
+ catch {
164
+ // FAIL-CLOSED (same discipline as establish). NOTE: a reuse-detected replay
165
+ // performs its lineage-kill INSIDE doRotate and then throws — that throw is
166
+ // caught here and re-surfaced as the SAME generic rejection, so the reason
167
+ // never distinguishes "replay" from "unknown token".
168
+ throw new SessionRejectedError();
169
+ }
170
+ }
171
+ async doRotate(refreshToken) {
172
+ if (typeof refreshToken !== 'string' || refreshToken.length === 0) {
173
+ throw new SessionRejectedError();
174
+ }
175
+ // Look up by HASH only — the raw token is never stored, never logged.
176
+ const tokenHash = this.refreshHasher.hash(refreshToken);
177
+ const record = await this.recordStore.findRefreshByHash(tokenHash);
178
+ // ABSENT ⇒ unknown / forged token ⇒ fail-closed reject (no lineage to kill).
179
+ if (record === null || record === undefined || typeof record !== 'object') {
180
+ throw new SessionRejectedError();
181
+ }
182
+ // ⛔ REUSE DETECTION (the security core): a FOUND token whose record is NOT
183
+ // `active` (already `rotated`, or `revoked`, or `expired`) is a REPLAY of a
184
+ // spent token — the signature of theft. Kill the ENTIRE lineage (every refresh
185
+ // record + the session), then reject. Both thief and victim are cut off.
186
+ if (record.status !== 'active') {
187
+ await this.recordStore.revokeLineage(record.lineageId);
188
+ throw new SessionRejectedError();
189
+ }
190
+ const nowMs = this.clock.nowMs();
191
+ // Fetch the durable session — the AUTHORITATIVE identity + absolute-cap anchor,
192
+ // and the silent-recovery source of truth. (Refresh IS a lifecycle event, so a
193
+ // durable read is allowed — unlike the per-request hot path.) A missing session
194
+ // (revoked / gone) ⇒ fail closed.
195
+ const session = await this.recordStore.findSessionById(record.sessionId);
196
+ if (session === null || session === undefined || typeof session !== 'object') {
197
+ throw new SessionRejectedError();
198
+ }
199
+ // A durably-revoked/expired session refuses refreshes (ADR-0013): even if the
200
+ // refresh record still read `active`, the session gate wins.
201
+ if (session.status !== 'active') {
202
+ throw new SessionRejectedError();
203
+ }
204
+ // (1) IDLE window (ADR-0015): the sliding window resets each rotation. If the
205
+ // presented refresh record's idle expiry has passed, the session is idle-dead.
206
+ if (typeof record.idleExpiresAtMs !== 'number' || nowMs >= record.idleExpiresAtMs) {
207
+ await this.recordStore.markRevoked(record.refreshId);
208
+ throw new SessionRejectedError();
209
+ }
210
+ // (2) ABSOLUTE cap (ADR-0015): bounded from LOGIN regardless of activity —
211
+ // enforced from the durable SESSION record's absolute expiry (never reset by
212
+ // rotation). A breach revokes the whole session so continuous rotation cannot
213
+ // outlive the cap.
214
+ if (typeof session.absoluteExpiresAtMs !== 'number' || nowMs >= session.absoluteExpiresAtMs) {
215
+ await this.recordStore.revokeSession(record.sessionId);
216
+ throw new SessionRejectedError();
217
+ }
218
+ // -- Active + within both windows ⇒ ATOMICALLY CLAIM, THEN ROTATE. -------
219
+ //
220
+ // ⛔ CONCURRENCY-SAFE REUSE DETECTION (the fix for the race the whole
221
+ // kill-switch exists to stop). The read above (`record.status === 'active'`)
222
+ // is NOT a safe basis to mint a successor: two near-simultaneous rotates of ONE
223
+ // token BOTH read `active` before either writes, and would BOTH mint valid
224
+ // pairs — the exact theft-vs-victim race. So we do NOT trust the read; we CLAIM
225
+ // the record with an ATOMIC compare-and-set and act on the RESULT:
226
+ // - claim === true ⇒ THIS caller flipped active→rotated; it WON → proceed.
227
+ // - claim !== true ⇒ LOST (a racing caller already rotated it, or it was
228
+ // spent) ⇒ a REPLAY of a now-spent token ⇒ kill the lineage + reject.
229
+ // STRICT `=== true` (defense-in-depth): a hostile/misbehaving store returning a
230
+ // truthy non-boolean must NOT be treated as a win (never fail open).
231
+ const won = (await this.recordStore.markRotatedIfActive(record.refreshId)) === true;
232
+ if (!won) {
233
+ // Lost the CAS ⇒ this token was already claimed/spent by another caller ⇒
234
+ // treat as reuse of a spent token: kill the ENTIRE lineage, then reject.
235
+ // Both the winner's live successor and this caller are cut off.
236
+ await this.recordStore.revokeLineage(record.lineageId);
237
+ throw new SessionRejectedError();
238
+ }
239
+ // ── WINNER ONLY past this point. ────────────────────────────────────────
240
+ const newRefreshId = this.tokenGenerator.mint();
241
+ const newAccessToken = this.tokenGenerator.mint();
242
+ const newRefreshToken = this.tokenGenerator.mint();
243
+ const newTokenHash = this.refreshHasher.hash(newRefreshToken);
244
+ const newIdleExpiresAtMs = nowMs + this.lifetimes.refreshIdleMs;
245
+ // Insert the successor in the SAME lineage, pointing back at the spent one.
246
+ // (The old record is ALREADY 'rotated' from the CAS above — so any later replay
247
+ // of it, sequential or concurrent, trips reuse detection and kills the lineage.)
248
+ await this.recordStore.insertRefreshRecord({
249
+ refreshId: newRefreshId,
250
+ sessionId: record.sessionId,
251
+ lineageId: record.lineageId,
252
+ prevRefreshId: record.refreshId,
253
+ tokenHash: newTokenHash,
254
+ issuedAtMs: nowMs,
255
+ idleExpiresAtMs: newIdleExpiresAtMs,
256
+ });
257
+ // SILENT RECOVERY: re-populate the hot tier from the durable identity. This
258
+ // runs every rotation, so a wiped Redis is rebuilt here with no re-login.
259
+ const { principalId, tenantId } = session;
260
+ if (typeof principalId !== 'string' ||
261
+ principalId.length === 0 ||
262
+ typeof tenantId !== 'string' ||
263
+ tenantId.length === 0) {
264
+ // Durable record is missing the identity needed to rebuild the hot record —
265
+ // fail closed rather than cache a half-formed session.
266
+ throw new SessionRejectedError();
267
+ }
268
+ await this.putHotRaw(record.sessionId, principalId, tenantId);
269
+ const rotatedSession = this.freezeSession({
270
+ sessionId: record.sessionId,
271
+ principalId,
272
+ tenantId,
273
+ status: 'active',
274
+ // `issuedAtMs` reflects the ORIGINAL login (from the durable record), so the
275
+ // session's identity + absolute-cap anchor stay stable across rotations. The
276
+ // freshly-minted access token's validity is the `expiresAtMs` bound below.
277
+ issuedAtMs: session.issuedAtMs,
278
+ expiresAtMs: nowMs + this.lifetimes.accessTtlMs,
279
+ });
280
+ return Object.freeze({
281
+ session: rotatedSession,
282
+ tokens: Object.freeze({ accessToken: newAccessToken, refreshToken: newRefreshToken }),
283
+ });
284
+ }
285
+ // -- revoke (logout / admin) ---------------------------------------------
286
+ async revoke(sessionId) {
287
+ try {
288
+ if (typeof sessionId !== 'string' || sessionId.length === 0) {
289
+ // Nothing to revoke; fail closed silently (revoke returns void either way).
290
+ return;
291
+ }
292
+ // Durable revoke (refuses all future refreshes of the lineage) + hot delete
293
+ // (drops it from the per-request path within the version-check bound).
294
+ await this.recordStore.revokeSession(sessionId);
295
+ await this.hotStore.deleteHotSession(hotKey(sessionId));
296
+ }
297
+ catch {
298
+ // Revoke is best-effort-idempotent; swallow to keep the contract void +
299
+ // never leak. A durable revoke that failed can be retried by the caller.
300
+ return;
301
+ }
302
+ }
303
+ // -- helpers --------------------------------------------------------------
304
+ freezeSession(s) {
305
+ return Object.freeze({ ...s });
306
+ }
307
+ async putHot(sessionId, principal, permissionsVersion, cachedFacts) {
308
+ const state = Object.freeze({
309
+ sessionId,
310
+ principalId: principal.id,
311
+ tenantId: principal.tenantId,
312
+ permissionsVersion,
313
+ cachedFacts,
314
+ });
315
+ await this.hotStore.putHotSession(hotKey(sessionId), state, this.lifetimes.accessTtlMs);
316
+ }
317
+ async putHotRaw(sessionId, principalId, tenantId) {
318
+ const state = Object.freeze({
319
+ sessionId,
320
+ principalId,
321
+ tenantId,
322
+ // Silent-recovery re-populate seeds the version/facts slot fresh; if a real
323
+ // version needs to survive a Redis loss it lives in the durable tier and is
324
+ // Authorization's concern to re-project. This layer only reserves the slot.
325
+ permissionsVersion: INITIAL_PERMISSIONS_VERSION,
326
+ cachedFacts: INITIAL_CACHED_FACTS,
327
+ });
328
+ await this.hotStore.putHotSession(hotKey(sessionId), state, this.lifetimes.accessTtlMs);
329
+ }
330
+ async runDeviceTrust(principal, sessionId) {
331
+ const hook = this.deviceTrust;
332
+ if (hook === undefined || typeof hook.isTrusted !== 'function') {
333
+ return; // no-op slot
334
+ }
335
+ try {
336
+ // Advisory only — the result is NOT allowed to grant/deny a session here.
337
+ await hook.isTrusted({
338
+ principalId: principal.id,
339
+ tenantId: principal.tenantId,
340
+ sessionId,
341
+ });
342
+ }
343
+ catch {
344
+ // A misbehaving hook must never fail-open OR break establishment; ignore.
345
+ return;
346
+ }
347
+ }
348
+ }
349
+ /**
350
+ * The per-request HOT READ path (ADR-0013). Deliberately a FREE function, NOT a
351
+ * SessionAuthority method — it is not a lifecycle event. It reads the hot store
352
+ * ALONE and makes ZERO durable-store calls. Fails CLOSED (returns `null`) when the
353
+ * hot store cannot answer (`unavailable`) — NEVER falls back to MariaDB
354
+ * (ADR-0013/0016). `absent` (a genuine miss) also returns `null` but is a distinct
355
+ * outcome the caller/enforcement can classify (ADR-0016 transient-vs-deny is
356
+ * Authorization's job; this only surfaces the fail-closed result).
357
+ *
358
+ * Returns the strict-`true` gate result: the {@link HotSessionState} ONLY on a
359
+ * genuine `found`; `null` on both `absent` and `unavailable` (fail-closed).
360
+ */
361
+ export async function readHotSession(hotStore, sessionId) {
362
+ try {
363
+ if (typeof sessionId !== 'string' || sessionId.length === 0)
364
+ return null;
365
+ const outcome = await hotStore.getHotSession(hotKey(sessionId));
366
+ // STRICT discriminant: only a well-formed `found` yields state. Anything else
367
+ // — absent, unavailable, or a malformed/hostile outcome — fails closed.
368
+ if (outcome !== null &&
369
+ typeof outcome === 'object' &&
370
+ outcome.kind === 'found') {
371
+ const state = outcome.state;
372
+ if (state !== null && typeof state === 'object') {
373
+ return state;
374
+ }
375
+ }
376
+ return null;
377
+ }
378
+ catch {
379
+ // Hot store threw ⇒ cannot answer ⇒ fail CLOSED (never serve from durable).
380
+ return null;
381
+ }
382
+ }
383
+ /**
384
+ * Wire the injected ports and return an object implementing the FROZEN
385
+ * {@link SessionAuthority}. The engine's public entry point (mirrors
386
+ * `createAuthenticator`). Validates the lifetime config eagerly at construction
387
+ * (throws LOUD on a nonsensical config — construction-time, not a hot path).
388
+ */
389
+ export function createSessionAuthority(options) {
390
+ const lifetimes = resolveLifetimes(options.lifetimes);
391
+ return new SessionAuthorityImpl(options.recordStore, options.hotStore, options.tokenGenerator, options.refreshHasher, options.clock, lifetimes, options.deviceTrust);
392
+ }
393
+ //# sourceMappingURL=session-authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-authority.js","sourceRoot":"","sources":["../../src/session/session-authority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAUH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWlD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAE1D,8EAA8E;AAC9E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAEtC,wFAAwF;AACxF,MAAM,oBAAoB,GAAY,IAAI,CAAC;AAE3C,kFAAkF;AAClF,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,eAAe,SAAS,EAAE,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,oBAAoB;IAEL;IACA;IACA;IACA;IACA;IACA;IACA;IAPnB,YACmB,WAA+B,EAC/B,QAAyB,EACzB,cAA8B,EAC9B,aAAiC,EACjC,KAAY,EACZ,SAAgC,EAChC,WAAwC;QANxC,gBAAW,GAAX,WAAW,CAAoB;QAC/B,aAAQ,GAAR,QAAQ,CAAiB;QACzB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,kBAAa,GAAb,aAAa,CAAoB;QACjC,UAAK,GAAL,KAAK,CAAO;QACZ,cAAS,GAAT,SAAS,CAAuB;QAChC,gBAAW,GAAX,WAAW,CAA6B;IACxD,CAAC;IAEJ,4EAA4E;IAE5E,KAAK,CAAC,SAAS,CAAC,SAAoB;QAClC,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC3C,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8E;QAC9E,wEAAwE;QACxE,IACE,OAAO,KAAK,IAAI;YAChB,OAAO,OAAO,KAAK,QAAQ;YAC1B,OAA8B,CAAC,IAAI,KAAK,OAAO,EAChD,CAAC;YACD,MAAM,KAAK,GAAI,OAA+B,CAAC,KAAK,CAAC;YACrD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAChD,OAAO,KAAwB,CAAC;YAClC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAuBD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAsC;IAEtC,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,IAAI,oBAAoB,CAC7B,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,KAAK,EACb,SAAS,EACT,OAAO,CAAC,WAAW,CACpB,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@astram/core",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Astram framework — sealed security core (Identity, Authentication, Session, Risk, Authorization, Audit). ZERO framework deps — the portable decision brain (ADR-0003). The frozen public contract consumers build against; installed, not edited (ADR-0023).",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.json",
24
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
25
+ "test": "vitest run"
26
+ },
27
+ "dependencies": {},
28
+ "devDependencies": {
29
+ "typescript": "^5.7.0",
30
+ "vitest": "^2.1.8"
31
+ }
32
+ }