@bli-cockpit/telemetry-core 0.1.80 → 0.1.81

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.
@@ -0,0 +1,2 @@
1
+ /** sha256 hex of the stable description of the secret rules, the image detector and the marker format. */
2
+ export declare function evidenceRulesFingerprint(): string;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * A fingerprint of the rules that decide the BYTES of a prepared transcript on the collector
3
+ * (BLI-22794): the secret-guard rule tables (names, order, regex sources and flags), the image
4
+ * detector and the image marker format.
5
+ *
6
+ * The local prepare memo keys what a transcript became on this fingerprint instead of on the CLI
7
+ * version, so an upgrade that changes none of these rules keeps the memo warm and one that does
8
+ * rebuilds every transcript once. CHANGING A SECRET RULE, THE IMAGE DETECTOR OR THE MARKER FORMAT
9
+ * CHANGES THIS VALUE, WHICH REBUILDS EVERY MEMO ON THE FLEET. That is intended: the old bytes may
10
+ * no longer be what the new rules would produce.
11
+ *
12
+ * Computed once per process. Not a secret-guards sibling on purpose: `secret-guards-lock.test.ts`
13
+ * locks the literal multiset of every `secret-guards*.ts` file.
14
+ */
15
+ import { createHash } from "node:crypto";
16
+ import { formatImageMarker, imageMarkerPattern, IMAGE_MIN_BASE64_CHARS } from "./image-descriptions.js";
17
+ import { SECRET_LIKE_CONTENT_PATTERNS } from "./secret-guards-content-rules.js";
18
+ import { SECRET_REDACTION_RULES } from "./secret-guards-masking.js";
19
+ import { SECRET_FILE_SEGMENT_PATTERN } from "./secret-guards-path-rules.js";
20
+ import { findEmbeddedImages } from "./transcript-images.js";
21
+ let cached;
22
+ /** The probe: a tiny PNG header padded past the detector's minimum, in both shapes the detector knows. */
23
+ function imageDetectorProbe() {
24
+ const png = Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), Buffer.alloc(IMAGE_MIN_BASE64_CHARS, 7)]).toString("base64");
25
+ return JSON.stringify({ a: png, b: `data:image/png;base64,${png}` });
26
+ }
27
+ function describe(pattern) {
28
+ return `${pattern.source}/${pattern.flags}`;
29
+ }
30
+ /** sha256 hex of the stable description of the secret rules, the image detector and the marker format. */
31
+ export function evidenceRulesFingerprint() {
32
+ if (cached)
33
+ return cached;
34
+ const probe = imageDetectorProbe();
35
+ const parts = {
36
+ redaction_rules: SECRET_REDACTION_RULES.map((rule) => [rule.ruleId, describe(rule.pattern), rule.secretGroup ?? null]),
37
+ content_patterns: SECRET_LIKE_CONTENT_PATTERNS.map(describe),
38
+ file_segment_pattern: describe(SECRET_FILE_SEGMENT_PATTERN),
39
+ image_min_base64_chars: IMAGE_MIN_BASE64_CHARS,
40
+ image_marker_pattern: describe(imageMarkerPattern()),
41
+ image_marker_sample: formatImageMarker({ sha256: "0123456789abcdef".repeat(4), mediaType: "image/png", byteSize: 412 * 1024 }),
42
+ image_detector_probe: findEmbeddedImages(probe).map((image) => [image.replaceStart, image.replaceEnd, image.mediaType, image.byteSize]),
43
+ };
44
+ cached = createHash("sha256").update(JSON.stringify(parts)).digest("hex");
45
+ return cached;
46
+ }
@@ -78,6 +78,8 @@ export function imageSizeLabel(byteSize) {
78
78
  /** What every marker starts with: a cheap `includes` check before anyone runs the marker regex. */
79
79
  export const IMAGE_MARKER_START = "[image sha256:";
80
80
  /** `[image sha256:ab12cd34ef567890… png 412KB]`: what replaces the base64 in an uploaded transcript. */
81
+ // BLI-22794: changing these rules changes `evidenceRulesFingerprint()` (evidence-rules-fingerprint.ts), which
82
+ // rebuilds every collector's prepare memo once. That is intended; update the pin in its test.
81
83
  export function formatImageMarker(image) {
82
84
  const hash = image.sha256.slice(0, IMAGE_MARKER_HASH_CHARS);
83
85
  return `[image sha256:${hash}… ${EXTENSION_BY_TYPE[image.mediaType]} ${imageSizeLabel(image.byteSize)}]`;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./decision-event.js";
7
7
  export * from "./decision-event-id.js";
8
8
  export * from "./evidence-completeness.js";
9
9
  export * from "./evidence-reconcile.js";
10
+ export * from "./evidence-rules-fingerprint.js";
10
11
  export * from "./evidence-stubs.js";
11
12
  export * from "./evidence-transcripts.js";
12
13
  export * from "./evidence-upload.js";
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from "./decision-event.js";
7
7
  export * from "./decision-event-id.js";
8
8
  export * from "./evidence-completeness.js";
9
9
  export * from "./evidence-reconcile.js";
10
+ export * from "./evidence-rules-fingerprint.js";
10
11
  export * from "./evidence-stubs.js";
11
12
  export * from "./evidence-transcripts.js";
12
13
  export * from "./evidence-upload.js";
@@ -131,6 +131,8 @@ const SECRET_VALUE_PATTERNS = [
131
131
  /\b(?:pk|sk)-lf-[A-Za-z0-9_-]{16}[A-Za-z0-9_-]*\b/i,
132
132
  /\bm0[-_][A-Za-z0-9_-]{16}[A-Za-z0-9_-]*\b/i,
133
133
  ];
134
+ // BLI-22794: changing these rules changes `evidenceRulesFingerprint()` (evidence-rules-fingerprint.ts), which
135
+ // rebuilds every collector's prepare memo once. That is intended; update the pin in its test.
134
136
  export const SECRET_LIKE_CONTENT_PATTERNS = [
135
137
  SECRET_NAME_WITH_VALUE_PATTERN,
136
138
  PASSWORD_WITH_VALUE_PATTERN,
@@ -10,6 +10,8 @@ const PASSWORD_ASSIGNMENT_REDACTION_PATTERN = new RegExp(`(${PASSWORD_NAME_MATCH
10
10
  // Exported for `secret-guards-long-runs.test.ts` alone and deliberately NOT
11
11
  // re-exported by `secret-guards.ts`: the test proves each rule answers exactly
12
12
  // what its pre-BLI-11094 spelling answered.
13
+ // BLI-22794: changing these rules changes `evidenceRulesFingerprint()` (evidence-rules-fingerprint.ts), which
14
+ // rebuilds every collector's prepare memo once. That is intended; update the pin in its test.
13
15
  export const SECRET_REDACTION_RULES = [
14
16
  {
15
17
  ruleId: "credential_assignment",
@@ -14,6 +14,8 @@
14
14
  * collector imports this instead of re-declaring it, so attribution,
15
15
  * collection, and the path walk share one definition.
16
16
  */
17
+ // BLI-22794: changing these rules changes `evidenceRulesFingerprint()` (evidence-rules-fingerprint.ts), which
18
+ // rebuilds every collector's prepare memo once. That is intended; update the pin in its test.
17
19
  export const SECRET_FILE_SEGMENT_PATTERN = /(^|[/\\])(?:\.env(?:\..*)?|.*(?:secret|credential|private[_-]?key|service[_-]?role).*)$/i;
18
20
  /**
19
21
  * Does this path segment name a file the collector must not open? One place
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.80",
3
+ "version": "0.1.81",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",