agent-recall-mcp 3.5.2 → 3.5.4
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 +254 -143
- package/dist/build-server.d.ts +28 -0
- package/dist/build-server.d.ts.map +1 -0
- package/dist/build-server.js +55 -0
- package/dist/build-server.js.map +1 -0
- package/dist/http/activity.d.ts +60 -0
- package/dist/http/activity.d.ts.map +1 -0
- package/dist/http/activity.js +254 -0
- package/dist/http/activity.js.map +1 -0
- package/dist/http/alerts.d.ts +84 -0
- package/dist/http/alerts.d.ts.map +1 -0
- package/dist/http/alerts.js +213 -0
- package/dist/http/alerts.js.map +1 -0
- package/dist/http/cli.d.ts +3 -0
- package/dist/http/cli.d.ts.map +1 -0
- package/dist/http/cli.js +515 -0
- package/dist/http/cli.js.map +1 -0
- package/dist/http/export-tar.d.ts +23 -0
- package/dist/http/export-tar.d.ts.map +1 -0
- package/dist/http/export-tar.js +264 -0
- package/dist/http/export-tar.js.map +1 -0
- package/dist/http/federation.d.ts +45 -0
- package/dist/http/federation.d.ts.map +1 -0
- package/dist/http/federation.js +185 -0
- package/dist/http/federation.js.map +1 -0
- package/dist/http/film/film.css +80 -0
- package/dist/http/film/film.js +446 -0
- package/dist/http/film/human.jpg +0 -0
- package/dist/http/film/m0.jpg +0 -0
- package/dist/http/film/m2.jpg +0 -0
- package/dist/http/film/m3.jpg +0 -0
- package/dist/http/film/wrong.jpg +0 -0
- package/dist/http/film.d.ts +16 -0
- package/dist/http/film.d.ts.map +1 -0
- package/dist/http/film.js +119 -0
- package/dist/http/film.js.map +1 -0
- package/dist/http/home/cabinet.svg +1 -0
- package/dist/http/home/drawer-project.svg +1 -0
- package/dist/http/home/drawer-rules.svg +1 -0
- package/dist/http/home/drawer-you.svg +1 -0
- package/dist/http/home/fig1.svg +242 -0
- package/dist/http/home/fig2-1.svg +61 -0
- package/dist/http/home/fig2-2.svg +92 -0
- package/dist/http/home/fig3.svg +1 -0
- package/dist/http/home/home.css +509 -0
- package/dist/http/home/home.html +517 -0
- package/dist/http/home/icons.svg +15 -0
- package/dist/http/home.d.ts +23 -0
- package/dist/http/home.d.ts.map +1 -0
- package/dist/http/home.js +295 -0
- package/dist/http/home.js.map +1 -0
- package/dist/http/identities.d.ts +29 -0
- package/dist/http/identities.d.ts.map +1 -0
- package/dist/http/identities.js +91 -0
- package/dist/http/identities.js.map +1 -0
- package/dist/http/import-memory.d.ts +161 -0
- package/dist/http/import-memory.d.ts.map +1 -0
- package/dist/http/import-memory.js +718 -0
- package/dist/http/import-memory.js.map +1 -0
- package/dist/http/jsonfile.d.ts +6 -0
- package/dist/http/jsonfile.d.ts.map +1 -0
- package/dist/http/jsonfile.js +60 -0
- package/dist/http/jsonfile.js.map +1 -0
- package/dist/http/legal/PRIVACY.md +70 -0
- package/dist/http/legal.d.ts +10 -0
- package/dist/http/legal.d.ts.map +1 -0
- package/dist/http/legal.js +35 -0
- package/dist/http/legal.js.map +1 -0
- package/dist/http/limits.d.ts +59 -0
- package/dist/http/limits.d.ts.map +1 -0
- package/dist/http/limits.js +163 -0
- package/dist/http/limits.js.map +1 -0
- package/dist/http/markdown-lite.d.ts +2 -0
- package/dist/http/markdown-lite.d.ts.map +1 -0
- package/dist/http/markdown-lite.js +86 -0
- package/dist/http/markdown-lite.js.map +1 -0
- package/dist/http/multipart.d.ts +43 -0
- package/dist/http/multipart.d.ts.map +1 -0
- package/dist/http/multipart.js +152 -0
- package/dist/http/multipart.js.map +1 -0
- package/dist/http/oauth-app.d.ts +75 -0
- package/dist/http/oauth-app.d.ts.map +1 -0
- package/dist/http/oauth-app.js +259 -0
- package/dist/http/oauth-app.js.map +1 -0
- package/dist/http/oauth-config.d.ts +46 -0
- package/dist/http/oauth-config.d.ts.map +1 -0
- package/dist/http/oauth-config.js +122 -0
- package/dist/http/oauth-config.js.map +1 -0
- package/dist/http/oauth-pages.d.ts +40 -0
- package/dist/http/oauth-pages.d.ts.map +1 -0
- package/dist/http/oauth-pages.js +97 -0
- package/dist/http/oauth-pages.js.map +1 -0
- package/dist/http/oauth-provider.d.ts +124 -0
- package/dist/http/oauth-provider.d.ts.map +1 -0
- package/dist/http/oauth-provider.js +486 -0
- package/dist/http/oauth-provider.js.map +1 -0
- package/dist/http/oauth-store.d.ts +128 -0
- package/dist/http/oauth-store.d.ts.map +1 -0
- package/dist/http/oauth-store.js +317 -0
- package/dist/http/oauth-store.js.map +1 -0
- package/dist/http/redirect-policy.d.ts +16 -0
- package/dist/http/redirect-policy.d.ts.map +1 -0
- package/dist/http/redirect-policy.js +83 -0
- package/dist/http/redirect-policy.js.map +1 -0
- package/dist/http/review-pages.d.ts +39 -0
- package/dist/http/review-pages.d.ts.map +1 -0
- package/dist/http/review-pages.js +78 -0
- package/dist/http/review-pages.js.map +1 -0
- package/dist/http/review.d.ts +36 -0
- package/dist/http/review.d.ts.map +1 -0
- package/dist/http/review.js +220 -0
- package/dist/http/review.js.map +1 -0
- package/dist/http/serve.d.ts +58 -0
- package/dist/http/serve.d.ts.map +1 -0
- package/dist/http/serve.js +324 -0
- package/dist/http/serve.js.map +1 -0
- package/dist/http/site-pages.d.ts +110 -0
- package/dist/http/site-pages.d.ts.map +1 -0
- package/dist/http/site-pages.js +630 -0
- package/dist/http/site-pages.js.map +1 -0
- package/dist/http/site-theme.d.ts +13 -0
- package/dist/http/site-theme.d.ts.map +1 -0
- package/dist/http/site-theme.js +22 -0
- package/dist/http/site-theme.js.map +1 -0
- package/dist/http/site.d.ts +52 -0
- package/dist/http/site.d.ts.map +1 -0
- package/dist/http/site.js +353 -0
- package/dist/http/site.js.map +1 -0
- package/dist/http/stats.d.ts +139 -0
- package/dist/http/stats.d.ts.map +1 -0
- package/dist/http/stats.js +599 -0
- package/dist/http/stats.js.map +1 -0
- package/dist/http/tar-import.d.ts +69 -0
- package/dist/http/tar-import.d.ts.map +1 -0
- package/dist/http/tar-import.js +234 -0
- package/dist/http/tar-import.js.map +1 -0
- package/dist/http/tenant-paths.d.ts +14 -0
- package/dist/http/tenant-paths.d.ts.map +1 -0
- package/dist/http/tenant-paths.js +42 -0
- package/dist/http/tenant-paths.js.map +1 -0
- package/dist/http/tokens.d.ts +32 -0
- package/dist/http/tokens.d.ts.map +1 -0
- package/dist/http/tokens.js +137 -0
- package/dist/http/tokens.js.map +1 -0
- package/dist/http/trial.d.ts +55 -0
- package/dist/http/trial.d.ts.map +1 -0
- package/dist/http/trial.js +218 -0
- package/dist/http/trial.js.map +1 -0
- package/dist/http/web-session.d.ts +108 -0
- package/dist/http/web-session.d.ts.map +1 -0
- package/dist/http/web-session.js +267 -0
- package/dist/http/web-session.js.map +1 -0
- package/dist/index.js +12 -65
- package/dist/index.js.map +1 -1
- package/dist/lib/ambient-capture.d.ts.map +1 -1
- package/dist/lib/ambient-capture.js +4 -1
- package/dist/lib/ambient-capture.js.map +1 -1
- package/dist/lib/bookkeeping.d.ts +26 -0
- package/dist/lib/bookkeeping.d.ts.map +1 -0
- package/dist/lib/bookkeeping.js +31 -0
- package/dist/lib/bookkeeping.js.map +1 -0
- package/dist/lib/hosted-redact.d.ts +17 -0
- package/dist/lib/hosted-redact.d.ts.map +1 -0
- package/dist/lib/hosted-redact.js +57 -0
- package/dist/lib/hosted-redact.js.map +1 -0
- package/dist/lib/lifecycle-exit.d.ts +5 -13
- package/dist/lib/lifecycle-exit.d.ts.map +1 -1
- package/dist/lib/lifecycle-exit.js +38 -16
- package/dist/lib/lifecycle-exit.js.map +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -3
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.d.ts +65 -0
- package/dist/tools/annotations.d.ts.map +1 -0
- package/dist/tools/annotations.js +4 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/check-action.d.ts.map +1 -1
- package/dist/tools/check-action.js +2 -0
- package/dist/tools/check-action.js.map +1 -1
- package/dist/tools/check.d.ts.map +1 -1
- package/dist/tools/check.js +6 -2
- package/dist/tools/check.js.map +1 -1
- package/dist/tools/digest.d.ts.map +1 -1
- package/dist/tools/digest.js +2 -0
- package/dist/tools/digest.js.map +1 -1
- package/dist/tools/pipeline-close.d.ts.map +1 -1
- package/dist/tools/pipeline-close.js +2 -0
- package/dist/tools/pipeline-close.js.map +1 -1
- package/dist/tools/pipeline-current.d.ts.map +1 -1
- package/dist/tools/pipeline-current.js +2 -0
- package/dist/tools/pipeline-current.js.map +1 -1
- package/dist/tools/pipeline-list.d.ts.map +1 -1
- package/dist/tools/pipeline-list.js +2 -0
- package/dist/tools/pipeline-list.js.map +1 -1
- package/dist/tools/pipeline-open.d.ts.map +1 -1
- package/dist/tools/pipeline-open.js +2 -0
- package/dist/tools/pipeline-open.js.map +1 -1
- package/dist/tools/pipeline-show.d.ts.map +1 -1
- package/dist/tools/pipeline-show.js +2 -0
- package/dist/tools/pipeline-show.js.map +1 -1
- package/dist/tools/recall.d.ts.map +1 -1
- package/dist/tools/recall.js +4 -1
- package/dist/tools/recall.js.map +1 -1
- package/dist/tools/register-rule.d.ts.map +1 -1
- package/dist/tools/register-rule.js +2 -0
- package/dist/tools/register-rule.js.map +1 -1
- package/dist/tools/remember.d.ts.map +1 -1
- package/dist/tools/remember.js +10 -1
- package/dist/tools/remember.js.map +1 -1
- package/dist/tools/session-end.d.ts +15 -0
- package/dist/tools/session-end.d.ts.map +1 -1
- package/dist/tools/session-end.js +13 -1
- package/dist/tools/session-end.js.map +1 -1
- package/dist/tools/session-start.d.ts +6 -1
- package/dist/tools/session-start.d.ts.map +1 -1
- package/dist/tools/session-start.js +24 -212
- package/dist/tools/session-start.js.map +1 -1
- package/package.json +11 -8
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* trial.ts: the "See it work" card on /connect. Three steps, each decided from
|
|
3
|
+
* SERVER RECORDS of one account (never from anything a client says).
|
|
4
|
+
*
|
|
5
|
+
* 1. Connect an agent a live credential of this account has recorded activity (activity.ts)
|
|
6
|
+
* 2. Teach it one rule the account has an ACTIVE rule (one only waiting for approval is not done, not counted)
|
|
7
|
+
* 3. A second agent a credential that did not teach the rule has made a tool call since it went live
|
|
8
|
+
*
|
|
9
|
+
* What the stores can and cannot tell (so the card never claims more):
|
|
10
|
+
* - Step 2 counts active corrections only. READY proposals (the ones /review can approve) are reported as
|
|
11
|
+
* `waiting` so the card can ask the owner to approve; they are not a rule yet.
|
|
12
|
+
* - A rule proposed through the hosted server records `authored_by`: the credential id activity.ts
|
|
13
|
+
* keys its rows by (never a token), stamped on the staged proposal and carried onto the active
|
|
14
|
+
* correction when the owner approves it. A proposal or rule restated by a second credential
|
|
15
|
+
* loses it (the stores drop it on that merge), and rules with the same text are one rule here:
|
|
16
|
+
* the credentials that taught it are the union of their authors, and one unattributed copy makes
|
|
17
|
+
* the whole group unattributed. Step 3 is PROVEN when a credential outside that union has made a
|
|
18
|
+
* tool call after the rule went live. "Different credential" is all the records can say: an agent
|
|
19
|
+
* that signed in again gets a new credential, so a re-sign-in of the author counts as another
|
|
20
|
+
* one. The card words it that way and never claims the rule was read or loaded.
|
|
21
|
+
* Not covered: a proposal still waiting for approval (it is not scanned), so a credential that
|
|
22
|
+
* has proposed the same text but is not yet approved is excluded only once it is.
|
|
23
|
+
* - A rule with no attributable author (written before the field existed, imported, or restated by
|
|
24
|
+
* another credential) keeps the weaker signal: two distinct credentials with tool calls after it
|
|
25
|
+
* went live. That completes the step but is never called proven.
|
|
26
|
+
* - "Active" is a tool call (activity.ts last_call, which initialize and tools/list never move),
|
|
27
|
+
* not proof the rule was read. Entries saved before last_call existed have none and so never
|
|
28
|
+
* count, which can only under-claim.
|
|
29
|
+
* - A rule's go-live time is its promotion row (the owner's approval, matched by correction id) when
|
|
30
|
+
* one exists, else its file's modification time (imported rules; only ever later than the truth).
|
|
31
|
+
* Only rules that are still active are listed, so a retracted or replaced rule never counts.
|
|
32
|
+
*
|
|
33
|
+
* Bounded reads. Worst case per scan (cached 10 s per account, see RuleScanCache): at most
|
|
34
|
+
* MAX_DIR_ENTRIES (64) project-directory entries, then per project (at most MAX_PROJECTS = 8):
|
|
35
|
+
* at most MAX_DIR_ENTRIES_FILES (500) directory entries listed, MAX_FILES (20) correction files
|
|
36
|
+
* lstat-ed and read at 64 KB each, and one log lstat plus a 64 KB tail read. That is about
|
|
37
|
+
* 8 x (500 + 21 lstat, 21 x 64 KB) = about 11 MB and about 4,400 cheap directory/stat calls. When a cap
|
|
38
|
+
* cuts the scan the result says `capped`, and the card says rules were "not found among your most
|
|
39
|
+
* recent rules" instead of claiming there are none. Symlinks and non-regular files are never read.
|
|
40
|
+
* Everything is scoped to one uid via tenantRoot; nothing is created. A failure to read throws from
|
|
41
|
+
* scanRules; the dashboard shows the card degraded, not a 500.
|
|
42
|
+
*/
|
|
43
|
+
import * as fs from "node:fs";
|
|
44
|
+
import * as path from "node:path";
|
|
45
|
+
import { credentialKeyOf, decodeTextFile } from "agent-recall-core";
|
|
46
|
+
import { tenantRoot } from "./tenant-paths.js";
|
|
47
|
+
export const MAX_PROJECTS = 8;
|
|
48
|
+
export const MAX_FILES = 20;
|
|
49
|
+
const MAX_DIR_ENTRIES = 64;
|
|
50
|
+
const MAX_DIR_ENTRIES_FILES = 500;
|
|
51
|
+
const MAX_FILE_BYTES = 64 * 1024;
|
|
52
|
+
const LOG_TAIL_BYTES = 64 * 1024;
|
|
53
|
+
const PROJECT_NAME_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
54
|
+
export const SCAN_TTL_MS = 10_000;
|
|
55
|
+
const CACHE_MAX = 1000;
|
|
56
|
+
const ms = (iso) => (iso === undefined ? NaN : Date.parse(iso));
|
|
57
|
+
const sameRule = (rule) => rule.toLowerCase().replace(/\s+/g, " ").trim();
|
|
58
|
+
/** Pure: the trial state from the account's credentials and rule signals (null = rules unreadable). */
|
|
59
|
+
export function computeTrial(credentials, rules) {
|
|
60
|
+
const s1 = credentials.some((c) => Number.isFinite(ms(c.lastSeen)));
|
|
61
|
+
// A proposal that only waits is not a rule: nothing is active until the owner approves it.
|
|
62
|
+
const s2 = rules !== null && rules.rules.length > 0;
|
|
63
|
+
const calledAfter = (r) => credentials.filter((c) => ms(c.lastCall) > r.at);
|
|
64
|
+
const proven = rules !== null && rules.rules.some((r) => r.authors.length > 0 && calledAfter(r).some((c) => !r.authors.includes(c.key)));
|
|
65
|
+
const s3 = proven || (rules !== null && rules.rules.some((r) => r.authors.length === 0 && calledAfter(r).length >= 2));
|
|
66
|
+
const done = [s1, s2, s3];
|
|
67
|
+
const first = done.indexOf(false);
|
|
68
|
+
return {
|
|
69
|
+
done,
|
|
70
|
+
proven,
|
|
71
|
+
count: done.filter(Boolean).length,
|
|
72
|
+
next: first < 0 ? null : (first + 1),
|
|
73
|
+
waiting: rules !== null && rules.ready > 0 && rules.rules.length === 0,
|
|
74
|
+
degraded: rules === null,
|
|
75
|
+
capped: rules?.capped === true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Up to `cap` entries of a directory without reading the rest (opendir, not readdir). null = absent. Symlinks are neither file nor dir. */
|
|
79
|
+
function listDir(dir, cap) {
|
|
80
|
+
let st;
|
|
81
|
+
try {
|
|
82
|
+
st = fs.lstatSync(dir);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (err?.code === "ENOENT")
|
|
86
|
+
return null;
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
if (st.isSymbolicLink())
|
|
90
|
+
return null; // never followed
|
|
91
|
+
if (!st.isDirectory())
|
|
92
|
+
throw new Error("not a directory"); // the store is unreadable: degrade, do not say "none"
|
|
93
|
+
const d = fs.opendirSync(dir);
|
|
94
|
+
try {
|
|
95
|
+
const entries = [];
|
|
96
|
+
for (let e = d.readSync(); e !== null; e = d.readSync()) {
|
|
97
|
+
if (entries.length >= cap)
|
|
98
|
+
return { entries, more: true };
|
|
99
|
+
entries.push({ name: e.name, file: e.isFile(), dir: e.isDirectory() });
|
|
100
|
+
}
|
|
101
|
+
return { entries, more: false };
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
d.closeSync();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function isActive(r) {
|
|
108
|
+
const o = r;
|
|
109
|
+
return o !== null && typeof o === "object" && typeof o.rule === "string" && o.active !== false && !o.retracted_at && !o.superseded_by;
|
|
110
|
+
}
|
|
111
|
+
/** correction id -> latest `promoted` timestamp in the tail of a project's promotion log. Only a regular file is opened. */
|
|
112
|
+
function promotions(file) {
|
|
113
|
+
const out = new Map();
|
|
114
|
+
let st;
|
|
115
|
+
try {
|
|
116
|
+
st = fs.lstatSync(file);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
if (err?.code === "ENOENT")
|
|
120
|
+
return out;
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
if (!st.isFile())
|
|
124
|
+
return out;
|
|
125
|
+
const fd = fs.openSync(file, "r");
|
|
126
|
+
try {
|
|
127
|
+
const len = Math.min(st.size, LOG_TAIL_BYTES);
|
|
128
|
+
const buf = Buffer.alloc(len);
|
|
129
|
+
fs.readSync(fd, buf, 0, len, st.size - len);
|
|
130
|
+
for (const line of buf.toString("utf-8").split("\n")) {
|
|
131
|
+
try {
|
|
132
|
+
const row = JSON.parse(line);
|
|
133
|
+
const t = typeof row.ts === "string" ? Date.parse(row.ts) : NaN;
|
|
134
|
+
if (row.action === "promoted" && typeof row.correction_id === "string" && Number.isFinite(t) && t > (out.get(row.correction_id) ?? -Infinity))
|
|
135
|
+
out.set(row.correction_id, t);
|
|
136
|
+
}
|
|
137
|
+
catch { /* a cut first line or a bad line */ }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
fs.closeSync(fd);
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* This account's active corrections (bounded): when each went live and who proposed it. Throws on an
|
|
147
|
+
* unreadable store (e.g. a corrections path that is not a directory); the caller degrades the
|
|
148
|
+
* card. A missing tenant or corrections directory is simply "none". Never creates anything.
|
|
149
|
+
*/
|
|
150
|
+
export function scanRules(dataDir, uid) {
|
|
151
|
+
const root = tenantRoot(dataDir, uid);
|
|
152
|
+
let capped = false;
|
|
153
|
+
const found = [];
|
|
154
|
+
const projects = listDir(path.join(root, "projects"), MAX_DIR_ENTRIES);
|
|
155
|
+
if (projects === null)
|
|
156
|
+
return { rules: [], capped: false };
|
|
157
|
+
const names = projects.entries.filter((e) => e.dir && PROJECT_NAME_RE.test(e.name)).map((e) => e.name).sort();
|
|
158
|
+
if (projects.more || names.length > MAX_PROJECTS)
|
|
159
|
+
capped = true;
|
|
160
|
+
for (const project of names.slice(0, MAX_PROJECTS)) {
|
|
161
|
+
const dir = path.join(root, "projects", project, "corrections");
|
|
162
|
+
const listing = listDir(dir, MAX_DIR_ENTRIES_FILES);
|
|
163
|
+
if (listing === null)
|
|
164
|
+
continue;
|
|
165
|
+
if (listing.more)
|
|
166
|
+
capped = true;
|
|
167
|
+
const files = listing.entries.filter((e) => e.file && e.name.endsWith(".json") && !e.name.startsWith("_")).map((e) => e.name).sort().reverse();
|
|
168
|
+
if (files.length > MAX_FILES)
|
|
169
|
+
capped = true;
|
|
170
|
+
const promoted = promotions(path.join(dir, "_pending", "_resolved.jsonl"));
|
|
171
|
+
for (const f of files.slice(0, MAX_FILES)) {
|
|
172
|
+
const p = path.join(dir, f);
|
|
173
|
+
try {
|
|
174
|
+
const st = fs.lstatSync(p);
|
|
175
|
+
if (!st.isFile() || st.size > MAX_FILE_BYTES)
|
|
176
|
+
continue; // symlink, directory, oversized: not read
|
|
177
|
+
const rec = JSON.parse(decodeTextFile(fs.readFileSync(p)));
|
|
178
|
+
if (!isActive(rec))
|
|
179
|
+
continue;
|
|
180
|
+
found.push({ at: (typeof rec.id === "string" ? promoted.get(rec.id) : undefined) ?? st.mtimeMs, text: sameRule(rec.rule), author: credentialKeyOf(rec.authored_by) });
|
|
181
|
+
}
|
|
182
|
+
catch { /* a malformed correction file is skipped, as readCorrections does */ }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const taught = new Map(); // rule text -> its authors; null once any copy has none
|
|
186
|
+
for (const f of found) {
|
|
187
|
+
const so = taught.get(f.text);
|
|
188
|
+
taught.set(f.text, f.author === undefined || so === null ? null : (so ?? new Set()).add(f.author));
|
|
189
|
+
}
|
|
190
|
+
return { rules: found.map((f) => ({ at: f.at, authors: [...(taught.get(f.text) ?? [])].sort() })), capped };
|
|
191
|
+
}
|
|
192
|
+
/** Per-account cache of scanRules for SCAN_TTL_MS. Bounded; expired entries are dropped when it fills. Only successes are kept. */
|
|
193
|
+
export class RuleScanCache {
|
|
194
|
+
now;
|
|
195
|
+
ttlMs;
|
|
196
|
+
hits = new Map();
|
|
197
|
+
constructor(now, ttlMs = SCAN_TTL_MS) {
|
|
198
|
+
this.now = now;
|
|
199
|
+
this.ttlMs = ttlMs;
|
|
200
|
+
}
|
|
201
|
+
get(dataDir, uid) {
|
|
202
|
+
const t = this.now();
|
|
203
|
+
const hit = this.hits.get(uid);
|
|
204
|
+
if (hit && t - hit.at < this.ttlMs)
|
|
205
|
+
return hit.scan;
|
|
206
|
+
if (this.hits.size >= CACHE_MAX) {
|
|
207
|
+
for (const [k, v] of this.hits)
|
|
208
|
+
if (t - v.at >= this.ttlMs)
|
|
209
|
+
this.hits.delete(k);
|
|
210
|
+
if (this.hits.size >= CACHE_MAX)
|
|
211
|
+
this.hits.clear();
|
|
212
|
+
}
|
|
213
|
+
const scan = scanRules(dataDir, uid);
|
|
214
|
+
this.hits.set(uid, { at: t, scan });
|
|
215
|
+
return scan;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=trial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trial.js","sourceRoot":"","sources":["../../src/http/trial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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I,CAAC,IAAI,IAAI,SAAS;gBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACrD,CAAC;QACD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { OAuthConfig, ProviderName } from "./oauth-config.js";
|
|
2
|
+
import { Federation } from "./federation.js";
|
|
3
|
+
export type Surface = "review" | "connect";
|
|
4
|
+
/** Where each surface lives and what to call it in messages. */
|
|
5
|
+
export declare const SURFACES: Record<Surface, {
|
|
6
|
+
path: string;
|
|
7
|
+
page: string;
|
|
8
|
+
noun: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const REVIEW_SESSION_COOKIE = "ar_review";
|
|
11
|
+
export declare const SITE_SESSION_COOKIE = "ar_site";
|
|
12
|
+
export declare const REVIEW_SESSION_TTL_MS: number;
|
|
13
|
+
export declare const REVIEW_LOGIN_TTL_MS: number;
|
|
14
|
+
export declare const notInvited: (provider: ProviderName, subject: string) => string;
|
|
15
|
+
export interface Session {
|
|
16
|
+
uid: string;
|
|
17
|
+
provider: ProviderName;
|
|
18
|
+
subject: string;
|
|
19
|
+
csrf: string;
|
|
20
|
+
created: number;
|
|
21
|
+
actions: number;
|
|
22
|
+
actionsReset: number;
|
|
23
|
+
/** One-shot notice for the next GET of a page (never taken from the URL, so a link cannot fake it). */
|
|
24
|
+
flash?: string;
|
|
25
|
+
}
|
|
26
|
+
export type WebResult = {
|
|
27
|
+
kind: "redirect";
|
|
28
|
+
status: 302 | 303;
|
|
29
|
+
location: string;
|
|
30
|
+
cookies: string[];
|
|
31
|
+
} | {
|
|
32
|
+
kind: "page";
|
|
33
|
+
status: number;
|
|
34
|
+
html: string;
|
|
35
|
+
cookies: string[]; /** Page posts to a /…/start route (form-action must allow the providers). */
|
|
36
|
+
signIn: boolean; /** Which surface rendered it: decides the page headers. */
|
|
37
|
+
surface?: Surface;
|
|
38
|
+
};
|
|
39
|
+
/** The HTML the flow needs; supplied by the surfaces so this module stays free of page code. */
|
|
40
|
+
export interface WebPages {
|
|
41
|
+
signIn(surface: Surface, v: {
|
|
42
|
+
providers: Array<{
|
|
43
|
+
name: string;
|
|
44
|
+
label: string;
|
|
45
|
+
}>;
|
|
46
|
+
error?: string;
|
|
47
|
+
privacyUrl?: string;
|
|
48
|
+
}): string;
|
|
49
|
+
/** `surface` undefined: the sign-in could not be tied to a page. */
|
|
50
|
+
message(surface: Surface | undefined, title: string, message: string): string;
|
|
51
|
+
}
|
|
52
|
+
export interface WebSessionDeps {
|
|
53
|
+
config: OAuthConfig;
|
|
54
|
+
dataDir: string;
|
|
55
|
+
federation: Federation;
|
|
56
|
+
log: (line: string) => void;
|
|
57
|
+
now: () => number;
|
|
58
|
+
pages: WebPages;
|
|
59
|
+
/** A federated account signed in on the website (after the invite check). serve.ts counts first sign-ins; must not throw. */
|
|
60
|
+
onSignIn?: (uid: string) => void;
|
|
61
|
+
}
|
|
62
|
+
export declare const str: (v: unknown, max: number) => string | null;
|
|
63
|
+
export declare function hashEq(a: string, bHex: string): boolean;
|
|
64
|
+
export declare function readCookie(header: string | undefined, name: string): string | undefined;
|
|
65
|
+
export declare const page: (status: number, html: string, cookies?: string[], signIn?: boolean, surface?: Surface) => WebResult;
|
|
66
|
+
export declare class WebSession {
|
|
67
|
+
private readonly d;
|
|
68
|
+
private readonly logins;
|
|
69
|
+
private readonly sessions;
|
|
70
|
+
private readonly providers;
|
|
71
|
+
constructor(d: WebSessionDeps);
|
|
72
|
+
private get secure();
|
|
73
|
+
private loginCookieName;
|
|
74
|
+
/** The sign-in's browser binding: sent only to the provider callback. */
|
|
75
|
+
private loginCookie;
|
|
76
|
+
/** The session, as one cookie per surface: each is sent only to its own pages, never to /mcp or the OAuth routes. */
|
|
77
|
+
sessionCookies(value: string | null): string[];
|
|
78
|
+
signInPage(surface: Surface, status?: number, error?: string, cookies?: string[]): WebResult;
|
|
79
|
+
message(surface: Surface | undefined, status: number, title: string, msg: string, cookies?: string[]): WebResult;
|
|
80
|
+
private evictExpiredLogins;
|
|
81
|
+
private evictExpiredSessions;
|
|
82
|
+
/** Is this provider state a live web sign-in? (The shared callback route dispatches on it.) */
|
|
83
|
+
hasState(state: unknown): boolean;
|
|
84
|
+
start(providerRaw: unknown, surface: Surface): WebResult;
|
|
85
|
+
callback(f: {
|
|
86
|
+
provider: string;
|
|
87
|
+
state: unknown;
|
|
88
|
+
code: unknown;
|
|
89
|
+
error: unknown;
|
|
90
|
+
cookies: string | undefined;
|
|
91
|
+
}): Promise<WebResult>;
|
|
92
|
+
private tokenOf;
|
|
93
|
+
/**
|
|
94
|
+
* The live session this browser holds, or null. The account is re-resolved on every
|
|
95
|
+
* request, so an operator's unlink (or re-link elsewhere) ends the session at once.
|
|
96
|
+
*/
|
|
97
|
+
session(cookieHeader: string | undefined): {
|
|
98
|
+
key: string;
|
|
99
|
+
s: Session;
|
|
100
|
+
} | null;
|
|
101
|
+
hasSessionCookie(cookieHeader: string | undefined): boolean;
|
|
102
|
+
end(key: string): void;
|
|
103
|
+
csrfOk(s: Session, given: unknown): boolean;
|
|
104
|
+
/** Counts one state-changing post; false when the session is over its budget. */
|
|
105
|
+
spendAction(s: Session): boolean;
|
|
106
|
+
accountLabel(s: Session): string;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=web-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-session.d.ts","sourceRoot":"","sources":["../../src/http/web-session.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAoD,MAAM,iBAAiB,CAAC;AAI/F,M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AS,GAAG,OAAO;IAI3D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAItB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAK3C,iFAAiF;IACjF,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAShC,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;CAGjC"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-session.ts — browser sign-in and sessions for the hosted website. Shared by the
|
|
3
|
+
* owner's /review page and the /connect dashboard: one in-memory session table, one
|
|
4
|
+
* sign-in flow, one CSRF scheme. A "surface" is the page a sign-in started from and
|
|
5
|
+
* returns to.
|
|
6
|
+
*
|
|
7
|
+
* Why a browser session and not an MCP token: since the owner gate (#51) whoever holds
|
|
8
|
+
* a tenant's ar_/aro_ token is treated as an AGENT, and an agent must never activate a
|
|
9
|
+
* rule or manage connections. Here the owner proves who they are with a GitHub/Google
|
|
10
|
+
* sign-in in a browser (re-authentication is not forced: GitHub skips its prompt for an
|
|
11
|
+
* app the user already authorized). Every site route refuses a request carrying an
|
|
12
|
+
* Authorization header, so a token holder never gets in.
|
|
13
|
+
*
|
|
14
|
+
* Cookies: one session token, sent as two HttpOnly SameSite=Lax cookies, each scoped to
|
|
15
|
+
* the only paths that need it (`ar_review` → /review, `ar_site` → /connect). Neither is
|
|
16
|
+
* ever sent to /mcp or the OAuth routes. Sign-in: state is 32 random bytes, single use,
|
|
17
|
+
* 10 min, bound to a cookie of the browser that started it; PKCE (S256) and, for
|
|
18
|
+
* Google, a nonce.
|
|
19
|
+
*
|
|
20
|
+
* CSRF: SameSite=Lax + a per-session synchronizer token in every form + Sec-Fetch-Site
|
|
21
|
+
* must be same-origin when the browser sends it + Origin (when it is a real origin) must
|
|
22
|
+
* be ours. `Origin: null` is let through on purpose: these pages send Referrer-Policy
|
|
23
|
+
* no-referrer, and browsers then send `null` on same-origin form posts (Fetch spec); the
|
|
24
|
+
* CSRF token still gates every state change.
|
|
25
|
+
*
|
|
26
|
+
* In memory only: a restart signs everyone out (they sign in again).
|
|
27
|
+
*/
|
|
28
|
+
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
29
|
+
import { FederationError, PROVIDER_LABEL, b64url, newPkce } from "./federation.js";
|
|
30
|
+
import { resolveIdentity, IdentityLinkError } from "./identities.js";
|
|
31
|
+
import { sha256Hex } from "./oauth-store.js";
|
|
32
|
+
/** Where each surface lives and what to call it in messages. */
|
|
33
|
+
export const SURFACES = {
|
|
34
|
+
review: { path: "/review", page: "review page", noun: "review" },
|
|
35
|
+
connect: { path: "/connect", page: "connect page", noun: "connect" },
|
|
36
|
+
};
|
|
37
|
+
export const REVIEW_SESSION_COOKIE = "ar_review";
|
|
38
|
+
export const SITE_SESSION_COOKIE = "ar_site";
|
|
39
|
+
export const REVIEW_SESSION_TTL_MS = 30 * 60 * 1000;
|
|
40
|
+
export const REVIEW_LOGIN_TTL_MS = 10 * 60 * 1000;
|
|
41
|
+
const LOGIN_COOKIE_PREFIX = "ar_review_login_";
|
|
42
|
+
const MAX_LOGINS = 10_000;
|
|
43
|
+
const MAX_SESSIONS = 10_000;
|
|
44
|
+
/** State-changing posts per session per window. */
|
|
45
|
+
const ACTIONS_PER_WINDOW = 120;
|
|
46
|
+
const ACTION_WINDOW_MS = 10 * 60 * 1000;
|
|
47
|
+
const msgState = (s) => `This sign-in was not recognized (it may have expired or been used already). Start again from the ${SURFACES[s].page}.`;
|
|
48
|
+
const msgBrowser = (s) => `This sign-in must finish in the same browser where it started. Start again from the ${SURFACES[s].page}.`;
|
|
49
|
+
const MSG_CANCELLED = "Sign-in was cancelled.";
|
|
50
|
+
const MSG_REJECTED = "Sign-in failed. Please try again, or use another account.";
|
|
51
|
+
const MSG_UNAVAILABLE = "Sign-in is temporarily unavailable. Please try again in a few minutes.";
|
|
52
|
+
const msgBusy = (s) => `The ${SURFACES[s].noun} service is busy right now. Please retry in a few seconds.`;
|
|
53
|
+
const MSG_LINK = "This account cannot sign in because of a server configuration problem. Ask the server operator to check its identity link.";
|
|
54
|
+
export const notInvited = (provider, subject) => `This ${PROVIDER_LABEL[provider]} account is not invited to this AgentRecall server. ` +
|
|
55
|
+
`To get access, send this id to the server operator: ${provider} ${subject}`;
|
|
56
|
+
export const str = (v, max) => typeof v === "string" && v.length > 0 && v.length <= max ? v : null;
|
|
57
|
+
export function hashEq(a, bHex) {
|
|
58
|
+
const x = Buffer.from(sha256Hex(a), "hex");
|
|
59
|
+
const y = Buffer.from(bHex, "hex");
|
|
60
|
+
return x.length === y.length && timingSafeEqual(x, y);
|
|
61
|
+
}
|
|
62
|
+
export function readCookie(header, name) {
|
|
63
|
+
if (!header || header.length > 4096)
|
|
64
|
+
return undefined;
|
|
65
|
+
for (const part of header.split(";")) {
|
|
66
|
+
const i = part.indexOf("=");
|
|
67
|
+
if (i > 0 && part.slice(0, i).trim() === name)
|
|
68
|
+
return part.slice(i + 1).trim();
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
export const page = (status, html, cookies = [], signIn = false, surface) => ({ kind: "page", status, html, cookies, signIn, surface });
|
|
73
|
+
export class WebSession {
|
|
74
|
+
d;
|
|
75
|
+
logins = new Map();
|
|
76
|
+
sessions = new Map();
|
|
77
|
+
providers;
|
|
78
|
+
constructor(d) {
|
|
79
|
+
this.d = d;
|
|
80
|
+
this.providers = d.federation.enabledProviders();
|
|
81
|
+
}
|
|
82
|
+
get secure() {
|
|
83
|
+
return this.d.config.publicUrl.protocol === "https:" ? "; Secure" : "";
|
|
84
|
+
}
|
|
85
|
+
loginCookieName(state) {
|
|
86
|
+
return LOGIN_COOKIE_PREFIX + sha256Hex(state).slice(0, 12);
|
|
87
|
+
}
|
|
88
|
+
/** The sign-in's browser binding: sent only to the provider callback. */
|
|
89
|
+
loginCookie(state, value) {
|
|
90
|
+
return `${this.loginCookieName(state)}=${value ?? ""}; HttpOnly; SameSite=Lax; Path=/authorize/callback; Max-Age=${value === null ? 0 : REVIEW_LOGIN_TTL_MS / 1000}${this.secure}`;
|
|
91
|
+
}
|
|
92
|
+
/** The session, as one cookie per surface: each is sent only to its own pages, never to /mcp or the OAuth routes. */
|
|
93
|
+
sessionCookies(value) {
|
|
94
|
+
const age = value === null ? 0 : REVIEW_SESSION_TTL_MS / 1000;
|
|
95
|
+
const one = (name, p) => `${name}=${value ?? ""}; HttpOnly; SameSite=Lax; Path=${p}; Max-Age=${age}${this.secure}`;
|
|
96
|
+
return [one(REVIEW_SESSION_COOKIE, SURFACES.review.path), one(SITE_SESSION_COOKIE, SURFACES.connect.path)];
|
|
97
|
+
}
|
|
98
|
+
signInPage(surface, status = 200, error, cookies = []) {
|
|
99
|
+
return page(status, this.d.pages.signIn(surface, {
|
|
100
|
+
providers: this.providers.map((p) => ({ name: p, label: PROVIDER_LABEL[p] })),
|
|
101
|
+
error, privacyUrl: this.d.config.privacyUrl?.href,
|
|
102
|
+
}), cookies, true, surface);
|
|
103
|
+
}
|
|
104
|
+
message(surface, status, title, msg, cookies = []) {
|
|
105
|
+
return page(status, this.d.pages.message(surface, title, msg), cookies, false, surface);
|
|
106
|
+
}
|
|
107
|
+
// ---- sign-in -------------------------------------------------------------
|
|
108
|
+
evictExpiredLogins() {
|
|
109
|
+
const t = this.d.now();
|
|
110
|
+
for (const [k, v] of this.logins)
|
|
111
|
+
if (t - v.created >= REVIEW_LOGIN_TTL_MS)
|
|
112
|
+
this.logins.delete(k);
|
|
113
|
+
}
|
|
114
|
+
evictExpiredSessions() {
|
|
115
|
+
const t = this.d.now();
|
|
116
|
+
for (const [k, v] of this.sessions)
|
|
117
|
+
if (t - v.created >= REVIEW_SESSION_TTL_MS)
|
|
118
|
+
this.sessions.delete(k);
|
|
119
|
+
}
|
|
120
|
+
/** Is this provider state a live web sign-in? (The shared callback route dispatches on it.) */
|
|
121
|
+
hasState(state) {
|
|
122
|
+
const s = str(state, 200);
|
|
123
|
+
if (s === null)
|
|
124
|
+
return false;
|
|
125
|
+
const l = this.logins.get(sha256Hex(s));
|
|
126
|
+
return l !== undefined && this.d.now() - l.created < REVIEW_LOGIN_TTL_MS;
|
|
127
|
+
}
|
|
128
|
+
start(providerRaw, surface) {
|
|
129
|
+
const provider = this.providers.find((p) => p === providerRaw);
|
|
130
|
+
if (!provider)
|
|
131
|
+
return this.signInPage(surface, 400, "Choose one of the sign-in options below.");
|
|
132
|
+
this.evictExpiredLogins(); // every time: an unauthenticated caller must not hold the table full of dead entries
|
|
133
|
+
if (this.logins.size >= MAX_LOGINS)
|
|
134
|
+
return this.message(surface, 503, "Busy", msgBusy(surface));
|
|
135
|
+
const state = b64url(randomBytes(32));
|
|
136
|
+
const nonce = b64url(randomBytes(24));
|
|
137
|
+
const cookie = b64url(randomBytes(32));
|
|
138
|
+
const pkce = newPkce();
|
|
139
|
+
this.logins.set(sha256Hex(state), { provider, verifier: pkce.verifier, nonce, cookieHash: sha256Hex(cookie), created: this.d.now(), next: surface });
|
|
140
|
+
return {
|
|
141
|
+
kind: "redirect", status: 302, cookies: [this.loginCookie(state, cookie)],
|
|
142
|
+
location: this.d.federation.authorizeUrl(provider, { state, challenge: pkce.challenge, nonce }),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async callback(f) {
|
|
146
|
+
const state = str(f.state, 200);
|
|
147
|
+
const key = state === null ? null : sha256Hex(state);
|
|
148
|
+
const login = key === null ? undefined : this.logins.get(key);
|
|
149
|
+
if (state === null || key === null || !login)
|
|
150
|
+
return this.message("review", 400, "Sign-in problem", msgState("review"));
|
|
151
|
+
const sf = login.next;
|
|
152
|
+
this.logins.delete(key); // single use, whatever happens next
|
|
153
|
+
const clear = [this.loginCookie(state, null)];
|
|
154
|
+
if (this.d.now() - login.created >= REVIEW_LOGIN_TTL_MS)
|
|
155
|
+
return this.message(sf, 400, "Sign-in problem", msgState(sf), clear);
|
|
156
|
+
const bound = readCookie(f.cookies, this.loginCookieName(state));
|
|
157
|
+
if (!bound || bound.length > 200 || !hashEq(bound, login.cookieHash))
|
|
158
|
+
return this.message(sf, 400, "Sign-in problem", msgBrowser(sf), clear);
|
|
159
|
+
if (login.provider !== f.provider)
|
|
160
|
+
return this.message(sf, 400, "Sign-in problem", msgState(sf), clear);
|
|
161
|
+
if (f.error !== undefined)
|
|
162
|
+
return this.signInPage(sf, 400, MSG_CANCELLED, clear);
|
|
163
|
+
const code = str(f.code, 2048);
|
|
164
|
+
if (code === null)
|
|
165
|
+
return this.signInPage(sf, 400, MSG_REJECTED, clear);
|
|
166
|
+
let subject;
|
|
167
|
+
try {
|
|
168
|
+
subject = await this.d.federation.identify(login.provider, code, login.verifier, login.nonce);
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
if (!(err instanceof FederationError)) {
|
|
172
|
+
// Never echo the message (it could carry provider data); the state is spent and the binding cookie cleared.
|
|
173
|
+
this.d.log(`[${sf}] ${login.provider}: unexpected ${err?.name ?? "error"}`);
|
|
174
|
+
return this.signInPage(sf, 500, MSG_UNAVAILABLE, clear);
|
|
175
|
+
}
|
|
176
|
+
this.d.log(`[${sf}] ${login.provider}: ${err.message}`);
|
|
177
|
+
return err.kind === "unavailable" ? this.signInPage(sf, 503, MSG_UNAVAILABLE, clear) : this.signInPage(sf, 401, MSG_REJECTED, clear);
|
|
178
|
+
}
|
|
179
|
+
let uid;
|
|
180
|
+
try {
|
|
181
|
+
const who = resolveIdentity(this.d.dataDir, login.provider, subject);
|
|
182
|
+
if (!who.linked && this.d.config.signup === "invite") {
|
|
183
|
+
this.d.log(`[${sf}] sign-in refused (not invited) ${login.provider}=${subject}`);
|
|
184
|
+
return this.message(sf, 403, "Not invited", notInvited(login.provider, subject), clear);
|
|
185
|
+
}
|
|
186
|
+
uid = who.uid;
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
this.d.log(`[${sf}] identity resolution failed: ${err.message}`);
|
|
190
|
+
return err instanceof IdentityLinkError
|
|
191
|
+
? this.message(sf, 403, "Sign-in problem", MSG_LINK, clear)
|
|
192
|
+
: this.signInPage(sf, 503, MSG_UNAVAILABLE, clear);
|
|
193
|
+
}
|
|
194
|
+
if (this.sessions.size >= MAX_SESSIONS) {
|
|
195
|
+
this.evictExpiredSessions();
|
|
196
|
+
if (this.sessions.size >= MAX_SESSIONS)
|
|
197
|
+
return this.message(sf, 503, "Busy", msgBusy(sf), clear);
|
|
198
|
+
}
|
|
199
|
+
const token = b64url(randomBytes(32));
|
|
200
|
+
const t = this.d.now();
|
|
201
|
+
this.sessions.set(sha256Hex(token), {
|
|
202
|
+
uid, provider: login.provider, subject, csrf: b64url(randomBytes(32)), created: t, actions: 0, actionsReset: t + ACTION_WINDOW_MS,
|
|
203
|
+
});
|
|
204
|
+
this.d.log(`[${sf}] signed in ${login.provider}=${subject} uid=${uid}`);
|
|
205
|
+
try {
|
|
206
|
+
this.d.onSignIn?.(uid);
|
|
207
|
+
}
|
|
208
|
+
catch { /* a counter never fails a sign-in */ }
|
|
209
|
+
return { kind: "redirect", status: 302, location: SURFACES[sf].path, cookies: [...this.sessionCookies(token), ...clear] };
|
|
210
|
+
}
|
|
211
|
+
// ---- sessions --------------------------------------------------------------
|
|
212
|
+
tokenOf(cookieHeader) {
|
|
213
|
+
return readCookie(cookieHeader, REVIEW_SESSION_COOKIE) ?? readCookie(cookieHeader, SITE_SESSION_COOKIE);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The live session this browser holds, or null. The account is re-resolved on every
|
|
217
|
+
* request, so an operator's unlink (or re-link elsewhere) ends the session at once.
|
|
218
|
+
*/
|
|
219
|
+
session(cookieHeader) {
|
|
220
|
+
const token = this.tokenOf(cookieHeader);
|
|
221
|
+
if (!token || token.length > 200)
|
|
222
|
+
return null;
|
|
223
|
+
const key = sha256Hex(token);
|
|
224
|
+
const s = this.sessions.get(key);
|
|
225
|
+
if (!s)
|
|
226
|
+
return null;
|
|
227
|
+
if (this.d.now() - s.created >= REVIEW_SESSION_TTL_MS) {
|
|
228
|
+
this.sessions.delete(key);
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
const who = resolveIdentity(this.d.dataDir, s.provider, s.subject);
|
|
233
|
+
if (who.uid !== s.uid || (!who.linked && this.d.config.signup === "invite")) {
|
|
234
|
+
this.sessions.delete(key);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
this.sessions.delete(key);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return { key, s };
|
|
243
|
+
}
|
|
244
|
+
hasSessionCookie(cookieHeader) {
|
|
245
|
+
return this.tokenOf(cookieHeader) !== undefined;
|
|
246
|
+
}
|
|
247
|
+
end(key) {
|
|
248
|
+
this.sessions.delete(key);
|
|
249
|
+
}
|
|
250
|
+
csrfOk(s, given) {
|
|
251
|
+
const g = str(given, 200);
|
|
252
|
+
return g !== null && hashEq(g, sha256Hex(s.csrf));
|
|
253
|
+
}
|
|
254
|
+
/** Counts one state-changing post; false when the session is over its budget. */
|
|
255
|
+
spendAction(s) {
|
|
256
|
+
const t = this.d.now();
|
|
257
|
+
if (s.actionsReset <= t) {
|
|
258
|
+
s.actions = 0;
|
|
259
|
+
s.actionsReset = t + ACTION_WINDOW_MS;
|
|
260
|
+
}
|
|
261
|
+
return ++s.actions <= ACTIONS_PER_WINDOW;
|
|
262
|
+
}
|
|
263
|
+
accountLabel(s) {
|
|
264
|
+
return `${PROVIDER_LABEL[s.provider]} account ${s.subject}`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=web-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-session.js","sourceRoot":"","sources":["../../src/http/web-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA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