@dreamforgestudiollc/emet 0.2.4 → 0.3.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.
- package/.env.example +63 -0
- package/CHANGELOG.md +84 -3
- package/CHARTER.md +19 -7
- package/README.md +130 -21
- package/areas/emet.md +18 -0
- package/areas/garden.md +18 -0
- package/areas/health.md +18 -0
- package/areas/home.md +18 -0
- package/areas/learning.md +18 -0
- package/areas/state.md +18 -0
- package/docs/AUTHORSHIP.md +3 -3
- package/docs/BOTS.md +4 -0
- package/docs/COVERAGE.md +2 -2
- package/docs/DEPLOY.md +41 -5
- package/docs/ERROR-CODES-SPEC.md +43 -0
- package/docs/ERROR-CODES.md +332 -0
- package/docs/GUARDRAILS-AND-MONORAILS.md +2 -1
- package/docs/GUIDED-SETUP.md +24 -3
- package/docs/PERMISSIONS.md +13 -7
- package/docs/ROADMAP.md +18 -15
- package/docs/SETUP.md +123 -14
- package/docs/SUBKEYS.md +59 -0
- package/gems/artifact-index.json +12 -0
- package/gems/bot-team-backup/floor.json +15 -0
- package/gems/bot-team-backup/gem.json +43 -0
- package/gems/bot-team-backup/guides/BOT_TEAM_BACKUP.md +27 -0
- package/gems/bot-team-backup/guides/BOT_TEAM_RECOVERY.md +23 -0
- package/gems/fieldnote/floor.json +14 -0
- package/gems/fieldnote/gem.json +70 -0
- package/gems/fieldnote/runes/fieldnote.js +4 -0
- package/gems/lean-six-sigma/CHANGELOG.md +10 -0
- package/gems/lean-six-sigma/README.md +92 -0
- package/gems/lean-six-sigma/floor.json +31 -0
- package/gems/lean-six-sigma/gem.json +1296 -0
- package/gems/lean-six-sigma/guides/ASSUMPTIONS.md +45 -0
- package/gems/lean-six-sigma/guides/BELTS.md +52 -0
- package/gems/lean-six-sigma/guides/DMADV.md +56 -0
- package/gems/lean-six-sigma/guides/DMAIC.md +127 -0
- package/gems/lean-six-sigma/guides/FORMULAS.md +330 -0
- package/gems/lean-six-sigma/guides/LEAN.md +97 -0
- package/gems/lean-six-sigma/guides/TEMPLATES.md +279 -0
- package/gems/lean-six-sigma/runes/lss_capability.js +132 -0
- package/gems/lean-six-sigma/runes/lss_control_limits.js +240 -0
- package/gems/lean-six-sigma/runes/lss_dpmo_sigma.js +81 -0
- package/gems/lean-six-sigma/runes/lss_hypothesis.js +298 -0
- package/gems/lean-six-sigma/runes/lss_sample_size.js +81 -0
- package/gems/neurendipity/floor.json +65 -0
- package/gems/neurendipity/gem.json +42 -0
- package/gems/neurendipity/guides/AUTISTIC_BURNOUT.md +81 -0
- package/{guides → gems/neurendipity/guides}/NEURODIVERGENT_SUPPORT.md +17 -8
- package/guides/README.md +3 -0
- package/package.json +12 -5
- package/server.json +48 -4
- package/src/aleph.js +18 -12
- package/src/annotations.js +45 -5
- package/src/atlas-role.js +9 -4
- package/src/attribution.js +555 -0
- package/src/conformance.js +7 -5
- package/src/database.js +34 -17
- package/src/dispatch.js +136 -16
- package/src/env.js +54 -9
- package/src/error-codes.js +394 -0
- package/src/error-log.js +273 -0
- package/src/error-report.js +245 -0
- package/src/floor.js +84 -41
- package/src/gaps.js +41 -8
- package/src/gem-check.js +1360 -0
- package/src/guides.js +31 -4
- package/src/host-reach.js +23 -0
- package/src/http-remote.js +47 -2
- package/src/index.js +10 -2
- package/src/invites.js +6 -5
- package/src/layers.js +9 -8
- package/src/lessons-to-checks.js +3 -3
- package/src/logger.js +2 -1
- package/src/mongo-connect.js +50 -2
- package/src/oauth-provider.js +30 -29
- package/src/owner-approvals.js +281 -0
- package/src/pages.js +806 -0
- package/src/persons.js +22 -1
- package/src/provenance.js +10 -10
- package/src/redact.js +10 -4
- package/src/request-log.js +1 -1
- package/src/rune-dispatch.js +360 -0
- package/src/rune-registry.js +71 -0
- package/src/rune-scope.js +42 -0
- package/src/scopes.js +3 -0
- package/src/session-graph.js +15 -12
- package/src/session.js +10 -10
- package/src/setup.js +307 -36
- package/src/socket.js +545 -0
- package/src/startup-pages.js +26 -8
- package/src/startup-payload.js +12 -8
- package/src/subkey-store.js +358 -0
- package/src/subkeys.js +947 -0
- package/src/tools.js +518 -204
- package/src/transcript-session.js +1 -1
- package/src/validation.js +85 -52
- package/src/version.js +1 -1
- package/templates/AREA.md +35 -0
- package/templates/BOARD.md +2 -2
- package/templates/BOTHANDOFF.md +2 -2
- package/templates/CHARACTER.md +1 -1
- package/templates/HANDOFF.md +1 -1
- package/templates/IDENTITY.md +1 -1
- package/templates/INDEX.md +21 -20
- package/templates/INSTALL.md +1 -1
- package/templates/PROCEDURE.md +1 -1
- package/templates/ROSTER.md +2 -2
- package/templates/SEED.md +2 -2
- package/templates/STAGING.md +2 -2
- package/templates/STANDARD.md +5 -5
- package/templates/THREAD.md +1 -1
- package/templates/USER.md +4 -1
- package/verification/load-gate/corpus.json +1765 -0
- package/verification/load-gate/load-gate.mjs +1246 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner page for pending sub-key requests.
|
|
3
|
+
*
|
|
4
|
+
* Mounted only when EMET_SUBKEYS=1. The passphrase is the one the OAuth
|
|
5
|
+
* consent page already checks (MongoOAuthProvider.checkPassphrase against
|
|
6
|
+
* EMET_OAUTH_PASSPHRASE), and a wrong guess shares that form's per-address
|
|
7
|
+
* lockout. A correct passphrase opens a session that lasts 15 minutes.
|
|
8
|
+
* Approve and Deny post that session's CSRF token and call
|
|
9
|
+
* decideSubkeyIfPending for the posted key_id. The history event records
|
|
10
|
+
* the real owner id and via owner_page. emet_client_approve is unchanged.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import crypto from 'node:crypto';
|
|
14
|
+
import express from 'express';
|
|
15
|
+
import { timingSafeEqualStr } from './oauth-provider.js';
|
|
16
|
+
import { decideSubkeyIfPending, loadSubkeyRecords } from './subkeys.js';
|
|
17
|
+
|
|
18
|
+
const COOKIE_NAME = 'emet_owner';
|
|
19
|
+
export const SESSION_MS = 15 * 60 * 1000;
|
|
20
|
+
const SESSION_MAX = 200;
|
|
21
|
+
const REASON_MAX = 500;
|
|
22
|
+
const STORE_MESSAGE = 'The sub-key store is unavailable.';
|
|
23
|
+
const NOT_PENDING = 'That sub-key is not awaiting approval. Nothing was changed.';
|
|
24
|
+
|
|
25
|
+
function esc(s) {
|
|
26
|
+
return String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readCookie(req, name) {
|
|
30
|
+
const raw = req.headers.cookie;
|
|
31
|
+
if (!raw || typeof raw !== 'string') return null;
|
|
32
|
+
for (const part of raw.split(';')) {
|
|
33
|
+
const i = part.indexOf('=');
|
|
34
|
+
if (i < 0) continue;
|
|
35
|
+
if (part.slice(0, i).trim() !== name) continue;
|
|
36
|
+
return part.slice(i + 1).trim();
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ownerActor(personId) {
|
|
42
|
+
return {
|
|
43
|
+
transport: 'http',
|
|
44
|
+
authenticated: true,
|
|
45
|
+
personId,
|
|
46
|
+
ownerId: personId,
|
|
47
|
+
sourceTag: 'owner',
|
|
48
|
+
sourceBasis: 'login',
|
|
49
|
+
clientId: null,
|
|
50
|
+
grantId: null
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function page(body) {
|
|
55
|
+
return `<!DOCTYPE html>
|
|
56
|
+
<html lang="en">
|
|
57
|
+
<head>
|
|
58
|
+
<meta charset="utf-8">
|
|
59
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
60
|
+
<title>EMET owner approvals</title>
|
|
61
|
+
<style>
|
|
62
|
+
body { font-family: system-ui, sans-serif; background: #12141a; color: #e8e6e0; margin: 0; padding: 24px; }
|
|
63
|
+
button { font: inherit; margin-right: 8px; }
|
|
64
|
+
</style>
|
|
65
|
+
</head>
|
|
66
|
+
<body>
|
|
67
|
+
${body}
|
|
68
|
+
</body>
|
|
69
|
+
</html>`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function sendHtml(res, status, body) {
|
|
73
|
+
res.status(status);
|
|
74
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
75
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
76
|
+
res.setHeader('Content-Security-Policy', "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'");
|
|
77
|
+
res.send(page(body));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function pendingRows(data) {
|
|
81
|
+
return Object.values((data && data.keys) || {})
|
|
82
|
+
.filter((k) => k && k.status === 'pending' && k.key_id && k.tag)
|
|
83
|
+
.sort((a, b) => String(a.requested_at || '').localeCompare(String(b.requested_at || '')) || String(a.key_id).localeCompare(String(b.key_id)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function listHtml(rows, csrf, note) {
|
|
87
|
+
const noteHtml = note ? `<p>${esc(note)}</p>` : '';
|
|
88
|
+
if (!rows.length) return `${noteHtml}<h1>Pending sub-keys</h1><p>No pending sub-key requests.</p>`;
|
|
89
|
+
const body = rows.map((row) => {
|
|
90
|
+
const prefix = esc(String(row.key_id).slice(0, 8));
|
|
91
|
+
return `<tr><td>${esc(row.tag)}</td><td>${prefix}</td><td>${esc(row.requested_at || '')}</td><td>
|
|
92
|
+
<form method="post" action="/owner/approvals/decide">
|
|
93
|
+
<input type="hidden" name="csrf" value="${esc(csrf)}">
|
|
94
|
+
<input type="hidden" name="key_id" value="${esc(row.key_id)}">
|
|
95
|
+
<input type="text" name="reason" maxlength="${REASON_MAX}" placeholder="Reason (optional)">
|
|
96
|
+
<button type="submit" name="decision" value="approve">Approve</button>
|
|
97
|
+
<button type="submit" name="decision" value="deny">Deny</button>
|
|
98
|
+
</form>
|
|
99
|
+
</td></tr>`;
|
|
100
|
+
}).join('\n');
|
|
101
|
+
return `${noteHtml}<h1>Pending sub-keys</h1>
|
|
102
|
+
<table>
|
|
103
|
+
<thead><tr><th>Tag</th><th>Key</th><th>Requested</th><th></th></tr></thead>
|
|
104
|
+
<tbody>
|
|
105
|
+
${body}
|
|
106
|
+
</tbody>
|
|
107
|
+
</table>`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function notPending(res) {
|
|
111
|
+
res.locals.reason = 'not_pending';
|
|
112
|
+
sendHtml(res, 400, `<p>${NOT_PENDING}</p>`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {import('express').Express} app
|
|
117
|
+
* @param {{ checkPassphrase: (input: string) => boolean, throttle: { check: Function, recordFailure: Function, recordSuccess: Function }, deps: object | Function, ownerId: string | Function, now?: () => number }} options
|
|
118
|
+
*/
|
|
119
|
+
export function mountOwnerApprovals(app, options = {}) {
|
|
120
|
+
const checkPassphrase = options.checkPassphrase;
|
|
121
|
+
const throttle = options.throttle;
|
|
122
|
+
const now = options.now || Date.now;
|
|
123
|
+
const sessions = new Map();
|
|
124
|
+
const parseBody = express.urlencoded({ extended: false });
|
|
125
|
+
const depsOf = () => (typeof options.deps === 'function' ? options.deps() : options.deps);
|
|
126
|
+
|
|
127
|
+
async function resolveOwner() {
|
|
128
|
+
try { const id = await (typeof options.ownerId === 'function' ? options.ownerId() : options.ownerId); return (typeof id === 'string' && id.trim()) || null; }
|
|
129
|
+
catch { return null; }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function sweep() {
|
|
133
|
+
const t = now();
|
|
134
|
+
for (const [id, row] of sessions) if (!row || row.expires <= t) sessions.delete(id);
|
|
135
|
+
while (sessions.size > SESSION_MAX) sessions.delete(sessions.keys().next().value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function sessionOf(req) {
|
|
139
|
+
sweep();
|
|
140
|
+
const raw = readCookie(req, COOKIE_NAME);
|
|
141
|
+
if (!raw || !/^[0-9a-f]{64}$/.test(raw)) return null;
|
|
142
|
+
return sessions.get(raw) || null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function renderList(req, res, note) {
|
|
146
|
+
const session = sessionOf(req);
|
|
147
|
+
if (!session) {
|
|
148
|
+
sendHtml(res, 200, `<h1>Owner approvals</h1>
|
|
149
|
+
<p>Enter the owner passphrase.</p>
|
|
150
|
+
<form method="post" action="/owner/approvals/login">
|
|
151
|
+
<label>Passphrase <input type="password" name="passphrase" autocomplete="current-password"></label>
|
|
152
|
+
<button type="submit">Continue</button>
|
|
153
|
+
</form>`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
let rows = [];
|
|
157
|
+
try {
|
|
158
|
+
rows = pendingRows(await loadSubkeyRecords(depsOf()));
|
|
159
|
+
} catch {
|
|
160
|
+
res.locals.reason = 'subkey_store';
|
|
161
|
+
sendHtml(res, 503, `<p>${STORE_MESSAGE}</p>`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
sendHtml(res, 200, listHtml(rows, session.csrf, note));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
app.get('/owner/approvals', (req, res) => {
|
|
168
|
+
renderList(req, res).catch((e) => {
|
|
169
|
+
console.error('[emet] owner approvals', e && e.message ? e.message : e);
|
|
170
|
+
if (!res.headersSent) {
|
|
171
|
+
res.locals.reason = 'owner_approvals_error';
|
|
172
|
+
sendHtml(res, 500, '<p>Something went wrong.</p>');
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
app.post('/owner/approvals/login', parseBody, (req, res) => {
|
|
178
|
+
const limit = throttle.check(req.ip);
|
|
179
|
+
if (!limit.allowed) {
|
|
180
|
+
res.locals.reason = 'throttled';
|
|
181
|
+
res.setHeader('Retry-After', String(limit.retryAfterS));
|
|
182
|
+
sendHtml(res, 429, '<p>Too many attempts. Try again later.</p>');
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const passphrase = (req.body && req.body.passphrase) || '';
|
|
186
|
+
let ok = false;
|
|
187
|
+
try { ok = checkPassphrase(passphrase) === true; }
|
|
188
|
+
catch (e) {
|
|
189
|
+
console.error('[emet] owner passphrase check', e && e.message ? e.message : e);
|
|
190
|
+
res.locals.reason = 'passphrase_check_error';
|
|
191
|
+
sendHtml(res, 500, '<p>Something went wrong.</p>');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!ok) {
|
|
195
|
+
throttle.recordFailure(req.ip);
|
|
196
|
+
res.locals.reason = 'bad_passphrase';
|
|
197
|
+
sendHtml(res, 401, '<p>Incorrect passphrase.</p>');
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
throttle.recordSuccess(req.ip);
|
|
201
|
+
sweep();
|
|
202
|
+
const id = crypto.randomBytes(32).toString('hex');
|
|
203
|
+
const csrf = crypto.randomBytes(32).toString('hex');
|
|
204
|
+
sessions.set(id, { csrf, expires: now() + SESSION_MS });
|
|
205
|
+
res.cookie(COOKIE_NAME, id, {
|
|
206
|
+
httpOnly: true,
|
|
207
|
+
sameSite: 'strict',
|
|
208
|
+
path: '/owner',
|
|
209
|
+
maxAge: SESSION_MS,
|
|
210
|
+
secure: req.secure === true
|
|
211
|
+
});
|
|
212
|
+
res.locals.reason = 'owner_session';
|
|
213
|
+
res.redirect(303, '/owner/approvals');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
app.post('/owner/approvals/decide', parseBody, (req, res) => {
|
|
217
|
+
const session = sessionOf(req);
|
|
218
|
+
if (!session) {
|
|
219
|
+
res.locals.reason = 'no_owner_session';
|
|
220
|
+
sendHtml(res, 401, '<p>Sign in again.</p>');
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const posted = (req.body && req.body.csrf) || '';
|
|
224
|
+
if (!timingSafeEqualStr(posted, session.csrf)) {
|
|
225
|
+
res.locals.reason = 'bad_csrf';
|
|
226
|
+
sendHtml(res, 403, '<p>The form expired. Reload the page and try again.</p>');
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const decision = req.body && req.body.decision;
|
|
230
|
+
const keyId = typeof (req.body && req.body.key_id) === 'string' ? req.body.key_id.trim() : '';
|
|
231
|
+
const reason = typeof (req.body && req.body.reason) === 'string' ? req.body.reason.trim() : '';
|
|
232
|
+
if (decision !== 'approve' && decision !== 'deny') {
|
|
233
|
+
res.locals.reason = 'bad_decision';
|
|
234
|
+
sendHtml(res, 400, '<p>Decision must be approve or deny. Nothing was changed.</p>');
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (reason.length > REASON_MAX) {
|
|
238
|
+
res.locals.reason = 'reason_too_long';
|
|
239
|
+
sendHtml(res, 400, '<p>The reason is too long. Nothing was changed.</p>');
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
finishDecide(req, res, keyId, decision, reason).catch((e) => {
|
|
243
|
+
console.error('[emet] owner decide', e && e.message ? e.message : e);
|
|
244
|
+
if (!res.headersSent) {
|
|
245
|
+
res.locals.reason = 'owner_decide_error';
|
|
246
|
+
sendHtml(res, 500, '<p>Something went wrong. Nothing was changed.</p>');
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
async function finishDecide(req, res, keyId, decision, reason) {
|
|
252
|
+
const personId = await resolveOwner();
|
|
253
|
+
if (!personId) {
|
|
254
|
+
res.locals.reason = 'owner_unavailable';
|
|
255
|
+
sendHtml(res, 400, '<p>The owner id is unavailable. Nothing was changed.</p>');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
let result = null;
|
|
259
|
+
try {
|
|
260
|
+
result = await decideSubkeyIfPending(depsOf(), ownerActor(personId), personId, {
|
|
261
|
+
key_id: keyId, decision, reason, via: 'owner_page'
|
|
262
|
+
}, new Date(now()));
|
|
263
|
+
} catch (e) {
|
|
264
|
+
if (e && e.attributionRefusal && !/sub-key store/.test(String(e.message))) {
|
|
265
|
+
res.locals.reason = 'decide_refused';
|
|
266
|
+
sendHtml(res, 400, `<p>${esc(e.message)}</p>`);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
res.locals.reason = 'subkey_store';
|
|
270
|
+
sendHtml(res, 503, `<p>${STORE_MESSAGE}</p>`);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!result) {
|
|
274
|
+
notPending(res);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
res.locals.reason = decision === 'approve' ? 'subkey_approved' : 'subkey_denied';
|
|
278
|
+
const verb = decision === 'approve' ? 'Approved' : 'Denied';
|
|
279
|
+
await renderList(req, res, `${verb} ${result.tag}.`);
|
|
280
|
+
}
|
|
281
|
+
}
|