@bli-cockpit/telemetry-core 0.1.55 → 0.1.57

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.
@@ -3,6 +3,7 @@ import { appendFile, mkdir, readFile, readdir, rename, writeFile } from "node:fs
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { homedir } from "node:os";
5
5
  import path from "node:path";
6
+ import { redactSecretLikeContent } from "./secret-guards-masking.js";
6
7
  export function validateExperience(store, verdict, reason) {
7
8
  if (!["bli", "supermemory", "both"].includes(store))
8
9
  throw new Error("store must be bli, supermemory or both");
@@ -29,6 +30,15 @@ async function saveReceipt(home, entry) {
29
30
  }
30
31
  export async function appendExperience(input, options) {
31
32
  validateExperience(input.store, input.verdict, input.reason);
33
+ // BLI-12187: the reason is free text an agent wrote and it is uploaded, so the
34
+ // value is masked before the receipt, the local log or the outbox sees it.
35
+ // Masking never refuses the entry; the cap is re-applied because a label can
36
+ // be longer than a short secret.
37
+ const guarded = redactSecretLikeContent(input.reason, { appliedBy: "local_collector", redactedFields: ["reason"] });
38
+ if (guarded.redacted) {
39
+ console.error("[memory experience] reason masked", JSON.stringify({ rule_counts: guarded.metadata?.rule_counts, match_count: guarded.metadata?.secret_like_match_count, reason_chars: [...input.reason].length }));
40
+ input = { ...input, reason: [...guarded.text].slice(0, 500).join("") };
41
+ }
32
42
  const home = options.homeDir ?? homedir();
33
43
  const entry = { ...input, id: randomUUID(), created_at: new Date().toISOString(), shipped: false };
34
44
  await mkdir(paths(home).queue, { recursive: true });
@@ -51,6 +51,23 @@ export declare const SECRET_NAME_MATCH_SOURCE: string;
51
51
  * in harvest-analysis (`study/prepare.ts`) already allowed it; this one did not.
52
52
  */
53
53
  export declare const SECRET_ASSIGNMENT_SOURCE = "[\"']?\\s*[:=]\\s*[\"']?";
54
+ /**
55
+ * The password family (BLI-12187). Humans pick these values, so they are short
56
+ * and low-entropy (`hunter2xyz`) and the 12-char opaque floor above never saw
57
+ * them. They get their own name list, a value floor of 6, and a value class that
58
+ * takes punctuation (`P@ssw0rd!2026`) but stops at whitespace, quotes and
59
+ * separators so the rest of the sentence survives.
60
+ *
61
+ * The tail is `[_-]word` only, not any letters: `passwordless: enabled` and
62
+ * `password-reset-flow` style prose must not be read as a name. A name with no
63
+ * assignment and a value ("password reset flow") never matches either.
64
+ * `pwd` is the shell's working directory too: a `pwd` assigned a value that
65
+ * starts with `/` or `~` is a path (`PWD=/Users/x/repo`) and is never masked,
66
+ * so env dumps keep their directories; `PWD=hunter2xyz` is still caught. Only
67
+ * `pwd` carries that exemption; a password that starts with `~` is masked.
68
+ */
69
+ export declare const PASSWORD_NAME_MATCH_SOURCE = "(?<![A-Za-z0-9])(?:password|passwd|passcode|pwd(?![A-Za-z0-9_-]{0,40}\\s*[\"']?\\s*[:=]\\s*[\"']?\\s*[/~]))(?:[_-][A-Za-z0-9_-]{0,40})?";
70
+ export declare const PASSWORD_VALUE_SOURCE = "[^\\s\"'`,;<>(){}\\[\\]]{6}[^\\s\"'`,;<>(){}\\[\\]]*";
54
71
  export declare const SECRET_LIKE_CONTENT_PATTERNS: RegExp[];
55
72
  /**
56
73
  * Does this text carry something the fleet must not upload as it stands? The
@@ -23,10 +23,12 @@ const PRIVILEGED_SUPABASE_KEY_NAME = ["SUPABASE", "SERVICE", "ROLE", "KEY"].join
23
23
  const SUPABASE_SERVICE_ROLE_NAME = ["SUPABASE", "SERVICE", "ROLE"].join("_");
24
24
  const OPENAI_KEY_NAME = ["OPENAI", "API", "KEY"].join("_");
25
25
  const MEM0_KEY_NAME = ["MEM0", "API", "KEY"].join("_");
26
+ const SUPABASE_SECRET_KEY_NAME = ["SUPABASE", "SECRET", "KEY"].join("_");
26
27
  const SECRET_NAME_PATTERN_SOURCE = [
27
28
  "(?:NEXT_PUBLIC_)?SUPABASE_ANON_KEY",
28
29
  PRIVILEGED_SUPABASE_KEY_NAME,
29
30
  SUPABASE_SERVICE_ROLE_NAME,
31
+ SUPABASE_SECRET_KEY_NAME,
30
32
  OPENAI_KEY_NAME,
31
33
  MEM0_KEY_NAME,
32
34
  "SERVICE[_\\s-]?ROLE(?:[_\\s-]?KEY)?",
@@ -73,6 +75,23 @@ export const SECRET_NAME_MATCH_SOURCE = `(?<![A-Za-z0-9])(?:${SECRET_NAME_PATTER
73
75
  * in harvest-analysis (`study/prepare.ts`) already allowed it; this one did not.
74
76
  */
75
77
  export const SECRET_ASSIGNMENT_SOURCE = `["']?\\s*[:=]\\s*["']?`;
78
+ /**
79
+ * The password family (BLI-12187). Humans pick these values, so they are short
80
+ * and low-entropy (`hunter2xyz`) and the 12-char opaque floor above never saw
81
+ * them. They get their own name list, a value floor of 6, and a value class that
82
+ * takes punctuation (`P@ssw0rd!2026`) but stops at whitespace, quotes and
83
+ * separators so the rest of the sentence survives.
84
+ *
85
+ * The tail is `[_-]word` only, not any letters: `passwordless: enabled` and
86
+ * `password-reset-flow` style prose must not be read as a name. A name with no
87
+ * assignment and a value ("password reset flow") never matches either.
88
+ * `pwd` is the shell's working directory too: a `pwd` assigned a value that
89
+ * starts with `/` or `~` is a path (`PWD=/Users/x/repo`) and is never masked,
90
+ * so env dumps keep their directories; `PWD=hunter2xyz` is still caught. Only
91
+ * `pwd` carries that exemption; a password that starts with `~` is masked.
92
+ */
93
+ export const PASSWORD_NAME_MATCH_SOURCE = "(?<![A-Za-z0-9])(?:password|passwd|passcode|pwd(?![A-Za-z0-9_-]{0,40}\\s*[\"']?\\s*[:=]\\s*[\"']?\\s*[/~]))(?:[_-][A-Za-z0-9_-]{0,40})?";
94
+ export const PASSWORD_VALUE_SOURCE = "[^\\s\"'`,;<>(){}\\[\\]]{6}[^\\s\"'`,;<>(){}\\[\\]]*";
76
95
  /**
77
96
  * Credential names that are only a leak when assigned a value (D13). The value
78
97
  * shape mirrors the long-standing generic pattern: an assignment operator
@@ -81,6 +100,7 @@ export const SECRET_ASSIGNMENT_SOURCE = `["']?\\s*[:=]\\s*["']?`;
81
100
  * an assigned value does.
82
101
  */
83
102
  const SECRET_NAME_WITH_VALUE_PATTERN = new RegExp(`${SECRET_NAME_MATCH_SOURCE}${SECRET_ASSIGNMENT_SOURCE}[A-Za-z0-9_./+=-]{12}[A-Za-z0-9_./+=-]*`, "i");
103
+ const PASSWORD_WITH_VALUE_PATTERN = new RegExp(`${PASSWORD_NAME_MATCH_SOURCE}${SECRET_ASSIGNMENT_SOURCE}${PASSWORD_VALUE_SOURCE}`, "i");
84
104
  /**
85
105
  * Self-identifying secret values — blocked regardless of context because the
86
106
  * token shape itself is the credential, with no benign reading.
@@ -105,7 +125,7 @@ const SECRET_VALUE_PATTERNS = [
105
125
  /\bgh[pousr]_[A-Za-z0-9_]{16}[A-Za-z0-9_]*/,
106
126
  /\bgithub_pat_[A-Za-z0-9_]{20}[A-Za-z0-9_]*/,
107
127
  /\blin_api_[A-Za-z0-9]{16}[A-Za-z0-9]*/,
108
- /\bsb_secret_[A-Za-z0-9_]{16}[A-Za-z0-9_]*/,
128
+ /\bsb_secret_[A-Za-z0-9_-]{16}[A-Za-z0-9_-]*/,
109
129
  /\bxox[baprs]-[A-Za-z0-9-]{16}[A-Za-z0-9-]*/,
110
130
  /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/,
111
131
  /\b(?:pk|sk)-lf-[A-Za-z0-9_-]{16}[A-Za-z0-9_-]*\b/i,
@@ -113,6 +133,7 @@ const SECRET_VALUE_PATTERNS = [
113
133
  ];
114
134
  export const SECRET_LIKE_CONTENT_PATTERNS = [
115
135
  SECRET_NAME_WITH_VALUE_PATTERN,
136
+ PASSWORD_WITH_VALUE_PATTERN,
116
137
  ...SECRET_VALUE_PATTERNS,
117
138
  ];
118
139
  /**
@@ -1,9 +1,12 @@
1
- import { SECRET_ASSIGNMENT_SOURCE, SECRET_LIKE_CONTENT_PATTERNS, SECRET_NAME_MATCH_SOURCE, } from "./secret-guards-content-rules.js";
1
+ import { PASSWORD_NAME_MATCH_SOURCE, PASSWORD_VALUE_SOURCE, SECRET_ASSIGNMENT_SOURCE, SECRET_LIKE_CONTENT_PATTERNS, SECRET_NAME_MATCH_SOURCE, } from "./secret-guards-content-rules.js";
2
2
  import { RawEvidenceRedactionMetadataSchema } from "./secret-guards-metadata.js";
3
3
  // Same fence as the detector (BLI-3116) — the two must agree or a prefixed
4
4
  // name would be detected and then left unredacted, which costs whole sessions
5
5
  // (see findSecretRedactionMatches).
6
6
  const SECRET_ASSIGNMENT_REDACTION_PATTERN = new RegExp(`(${SECRET_NAME_MATCH_SOURCE}${SECRET_ASSIGNMENT_SOURCE})([A-Za-z0-9_./+=-]{12}[A-Za-z0-9_./+=-]*)`, "gi");
7
+ // BLI-12187: the password family, own floor of 6. Appended to the table below so
8
+ // no existing rule's priority moves.
9
+ const PASSWORD_ASSIGNMENT_REDACTION_PATTERN = new RegExp(`(${PASSWORD_NAME_MATCH_SOURCE}${SECRET_ASSIGNMENT_SOURCE})(${PASSWORD_VALUE_SOURCE})`, "gi");
7
10
  // Exported for `secret-guards-long-runs.test.ts` alone and deliberately NOT
8
11
  // re-exported by `secret-guards.ts`: the test proves each rule answers exactly
9
12
  // what its pre-BLI-11094 spelling answered.
@@ -82,7 +85,7 @@ export const SECRET_REDACTION_RULES = [
82
85
  },
83
86
  {
84
87
  ruleId: "supabase_secret_token",
85
- pattern: /\bsb_secret_[A-Za-z0-9_]{16}[A-Za-z0-9_]*/g,
88
+ pattern: /\bsb_secret_[A-Za-z0-9_-]{16}[A-Za-z0-9_-]*/g,
86
89
  },
87
90
  {
88
91
  ruleId: "slack_token",
@@ -100,6 +103,11 @@ export const SECRET_REDACTION_RULES = [
100
103
  ruleId: "mem0_token",
101
104
  pattern: /\bm0[-_][A-Za-z0-9_-]{16}[A-Za-z0-9_-]*\b/gi,
102
105
  },
106
+ {
107
+ ruleId: "password_assignment",
108
+ pattern: PASSWORD_ASSIGNMENT_REDACTION_PATTERN,
109
+ secretGroup: 2,
110
+ },
103
111
  ];
104
112
  /**
105
113
  * Mask every secret-shaped span and keep the rest of the text, because a
@@ -25,7 +25,19 @@
25
25
  * the only honest discriminator.
26
26
  */
27
27
  export declare const TOWER_NATIVE_ISSUE_NUMBER_FLOOR = 10000;
28
+ /**
29
+ * The FIRST upper-case ticket identifier in free text, or null. Upper-case
30
+ * only on purpose: the dashboard rebind resolves lower-case branches through
31
+ * the mirrored-ticket `linear_branch` source, which checks the ticket exists.
32
+ */
28
33
  export declare function parseTicketIdFromText(value: string): string | null;
34
+ /**
35
+ * The FIRST ticket identifier in a git branch name (BLI-12189). Our own key
36
+ * binds in any case (`fix/bli-12189-x` is `BLI-12189`; 708 of 987 remote
37
+ * branches are lower-case); every other key must still be upper-case, so
38
+ * `codex/stop-controls-20260922` or `upgrade-node-22` is not a ticket.
39
+ */
40
+ export declare function parseTicketIdFromBranch(branch: string): string | null;
29
41
  /** Is this the shape either tracker uses for an identifier? */
30
42
  export declare function looksLikeIssueIdentifier(value: string): boolean;
31
43
  /** The one spelling of an identifier: trimmed and upper-cased, or null. */
package/dist/ticket-id.js CHANGED
@@ -27,10 +27,44 @@ const ISSUE_IDENTIFIER = /^[A-Z][A-Z0-9]{1,12}-\d+$/;
27
27
  * the only honest discriminator.
28
28
  */
29
29
  export const TOWER_NATIVE_ISSUE_NUMBER_FLOOR = 10_000;
30
+ /**
31
+ * Words that have the shape of a team key and the number after it but are not
32
+ * a tracker: "UTF-8", "ISO-8601", "SHA-256". Skipped by both parsers below.
33
+ */
34
+ const NON_TICKET_PREFIXES = new Set([
35
+ "UTF", "ISO", "SHA", "MD", "RFC", "GPT", "HTTP", "TLS", "SSL", "UTC", "GMT",
36
+ "CVE", "PNG", "JPEG", "WEBP", "AES", "RSA", "USB", "IPV", "ES", "TS", "OKLAB",
37
+ ]);
38
+ const TICKET_SHAPE = /(?<![A-Za-z0-9])([A-Za-z][A-Za-z0-9]{1,12})-(\d+)(?![A-Za-z0-9])/g;
39
+ function firstTicketId(value, caseInsensitiveKeys) {
40
+ for (const match of value.matchAll(TICKET_SHAPE)) {
41
+ const key = match[1].toUpperCase();
42
+ if (NON_TICKET_PREFIXES.has(key))
43
+ continue;
44
+ if (match[1] !== key && !caseInsensitiveKeys.has(key))
45
+ continue;
46
+ return `${key}-${match[2]}`;
47
+ }
48
+ return null;
49
+ }
50
+ /**
51
+ * The FIRST upper-case ticket identifier in free text, or null. Upper-case
52
+ * only on purpose: the dashboard rebind resolves lower-case branches through
53
+ * the mirrored-ticket `linear_branch` source, which checks the ticket exists.
54
+ */
30
55
  export function parseTicketIdFromText(value) {
31
- const match = value.match(/\b[A-Z][A-Z0-9]{1,12}-\d+\b/);
32
- return match?.[0] ?? null;
56
+ return firstTicketId(value, new Set());
57
+ }
58
+ /**
59
+ * The FIRST ticket identifier in a git branch name (BLI-12189). Our own key
60
+ * binds in any case (`fix/bli-12189-x` is `BLI-12189`; 708 of 987 remote
61
+ * branches are lower-case); every other key must still be upper-case, so
62
+ * `codex/stop-controls-20260922` or `upgrade-node-22` is not a ticket.
63
+ */
64
+ export function parseTicketIdFromBranch(branch) {
65
+ return firstTicketId(branch, BRANCH_CASE_INSENSITIVE_KEYS);
33
66
  }
67
+ const BRANCH_CASE_INSENSITIVE_KEYS = new Set(["BLI"]);
34
68
  /** Is this the shape either tracker uses for an identifier? */
35
69
  export function looksLikeIssueIdentifier(value) {
36
70
  return ISSUE_IDENTIFIER.test(value.trim().toUpperCase());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.55",
3
+ "version": "0.1.57",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,5 +60,10 @@
60
60
  "@types/node": "20.19.39",
61
61
  "typescript": "5.9.3",
62
62
  "vitest": "3.2.4"
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "git+https://github.com/BLI-INC/bli-cockpit.git",
67
+ "directory": "packages/cockpit-telemetry-core"
63
68
  }
64
69
  }