@volter/teams 0.2.41 → 0.2.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.2.41",
3
+ "version": "0.2.43",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",
package/redact.mjs CHANGED
@@ -170,6 +170,11 @@ let custodyBasis = null;
170
170
  /** What a redaction was made under (the rule set and the custody values), as a digest: text found clean under one
171
171
  * basis is clean under it again, and needs another look only when it changes. */
172
172
  export function redactionBasis(env = process.env) { custodyValues(env); return custodyBasis; }
173
+ /** One custody observation and its basis, for a batch that must not change policy between its values. */
174
+ export function redactionSnapshot(env = process.env) {
175
+ const values = custodyValues(env);
176
+ return { values, basis: custodyBasis };
177
+ }
173
178
 
174
179
  // Text this far either side of a keyword is searched by a bounded rule, beyond its longest match.
175
180
  const WINDOW_MARGIN = 256;
@@ -184,12 +189,12 @@ function keywordSpans(hits, length, keywords, reach) {
184
189
  }
185
190
 
186
191
  /** `text` with every secret replaced by its marker. */
187
- export function redactText(text, env = process.env) {
192
+ export function redactText(text, env = process.env, custody) {
188
193
  if (typeof text !== 'string' || text.length < 8) return text;
189
194
  let out = text;
190
195
  // Custody values are random, so one alternation of them gives the regex engine nothing to skip on: each is looked
191
196
  // for on its own, which reads a 5 MB text in a few dozen milliseconds.
192
- for (const { value, name } of custodyValues(env)) if (out.includes(value)) out = out.split(value).join(`[redacted:${name}]`);
197
+ for (const { value, name } of custody ?? custodyValues(env)) if (out.includes(value)) out = out.split(value).join(`[redacted:${name}]`);
193
198
  if (/(?:sct|sci|sca|sat|whsec)_/.test(out)) out = out.replace(TEAM_TOKENS, (_, kind, hook) => `[redacted:teams-${kind ?? hook}-token]`);
194
199
  // Every rule has keywords, so a text holding none of them is done (the one test is cheap; finding where each keyword
195
200
  // occurs is not, and most texts are short and hold none).
@@ -220,9 +225,9 @@ export function redactText(text, env = process.env) {
220
225
  }
221
226
 
222
227
  /** A JSON value with every string in it redacted (keys kept). */
223
- export function redactValue(value, env = process.env) {
224
- if (typeof value === 'string') return redactText(value, env);
225
- if (Array.isArray(value)) return value.map((item) => redactValue(item, env));
226
- if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactValue(item, env)]));
228
+ export function redactValue(value, env = process.env, custody) {
229
+ if (typeof value === 'string') return redactText(value, env, custody);
230
+ if (Array.isArray(value)) return value.map((item) => redactValue(item, env, custody));
231
+ if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactValue(item, env, custody)]));
227
232
  return value;
228
233
  }
package/server/auth.mjs CHANGED
@@ -26,13 +26,19 @@ const LINEAGE_ROWS = `FROM lineage l JOIN credentials c ON c.id=l.id
26
26
  LEFT JOIN apps a ON a.id=i.app_id
27
27
  LEFT JOIN memberships installer ON installer.team_id=i.team_id AND installer.principal_id=i.installer_id
28
28
  LEFT JOIN memberships service ON service.team_id=i.team_id AND service.principal_id=i.principal_id`;
29
- export const APP_LINEAGE_REVOKED = `${APP_LINEAGE}, lineage_actors(team,id) AS (
29
+ // Materialize only this credential lineage's actors before checking their
30
+ // agency. When json_each was flattened, the hosted planner checked every
31
+ // agent in the team before matching actor.value (20,794 reads per event).
32
+ // CROSS JOIN keeps the small actor list on the left of the indexed agent
33
+ // lookup. Authority stays live: no predicate or result is cached.
34
+ export const APP_LINEAGE_REVOKED = `${APP_LINEAGE}, lineage_actors(team,id) AS MATERIALIZED (
30
35
  SELECT c.team_id,actor.value FROM lineage l JOIN credentials c ON c.id=l.id JOIN principals p ON p.id=c.principal_id
31
36
  JOIN app_credentials ac ON ac.credential_id=c.id, json_each(COALESCE(ac.actor_json,'[]')) actor WHERE actor.type='text')
32
37
  SELECT 1 FROM lineage l JOIN credentials c ON c.id=l.id JOIN principals p ON p.id=c.principal_id
33
38
  WHERE p.kind='agent' AND NOT EXISTS (${AGENT_ACTIVE.replace('VALUES(?,?)','SELECT c.team_id,c.principal_id')})
34
- UNION ALL SELECT 1 FROM lineage_actors x JOIN agents named ON named.team_id=x.team AND named.id=x.id
35
- WHERE NOT EXISTS (${AGENT_ACTIVE.replace('VALUES(?,?)','SELECT named.team_id,named.id')})
39
+ UNION ALL SELECT 1 FROM lineage_actors x CROSS JOIN agents named
40
+ WHERE named.team_id=x.team AND named.id=x.id
41
+ AND NOT EXISTS (${AGENT_ACTIVE.replace('VALUES(?,?)','SELECT named.team_id,named.id')})
36
42
  UNION ALL SELECT 1 ${LINEAGE_ROWS}
37
43
  WHERE EXISTS(SELECT 1 FROM agent_credentials d LEFT JOIN memberships dm ON dm.team_id=d.team_id AND dm.principal_id=c.principal_id WHERE d.parent_credential_id=c.id AND d.credential_id IN(SELECT id FROM lineage) AND COALESCE(dm.active,0)!=1)
38
44
  OR c.revoked_at IS NOT NULL OR (c.expires_at IS NOT NULL AND c.expires_at<=?)