@jini-ai/diagnostics 0.4.0 → 0.5.1

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.
@@ -1,179 +1,3 @@
1
- import { SECRET_SHAPE_PATTERNS } from "@jini-ai/core";
2
- /** Adds the `g` flag when a source pattern (e.g. one of {@link SECRET_SHAPE_PATTERNS}, authored for a
3
- * single `RegExp.exec` caller) does not already carry it — `String.replace` only replaces every
4
- * match when the pattern is global. Mirrors `secret-scan-guard.ts`'s own `scanTextForSecrets`. */
5
- function withGlobalFlag(flags) {
6
- return flags.includes("g") ? flags : `${flags}g`;
7
- }
8
- /** {@link SECRET_SHAPE_PATTERNS} reused for redaction — see this file's header. Each vendor pattern is
9
- * wrapped in the same `RedactionRule` shape as every rule below, so the loop in
10
- * {@link redactSecretShapes} treats them identically. */
11
- const REUSED_CREDENTIAL_RULES = SECRET_SHAPE_PATTERNS.map((vendor) => ({
12
- kind: "credential",
13
- pattern: new RegExp(vendor.pattern.source, withGlobalFlag(vendor.pattern.flags)),
14
- replacement: () => "[REDACTED:credential]",
15
- }));
16
- /** Labels a bare `label=value`, `"label":"value"`, or `?label=value` assignment may carry — see
17
- * this file's header's Must NOT change list for why a bare prose colon (`password: must be...`)
18
- * is deliberately excluded from all three shapes below. */
19
- const LABELED_SECRET_LABELS = "password|passwd|pwd|secret|client_secret|api_key|apikey|access_token|refresh_token|id_token|auth_token|token|private_key|secret_access_key|signing_secret|webhook_secret";
20
- /**
21
- * Every rule this module applies, in order. Order matters: `private_key` must run before the
22
- * reused header-only PEM pattern (inside {@link REUSED_CREDENTIAL_RULES}) so a full block is
23
- * blanked as one unit rather than leaving its header re-matched separately; `auth_header` must run
24
- * before the bare `bearer_token` rule so a header's own scheme+token is not ALSO caught by the
25
- * looser bare-token rule.
26
- */
27
- const REDACTION_RULES = [
28
- {
29
- kind: "private_key",
30
- // Matches a full PEM block, including a truncated one with no `-----END-----` line (the
31
- // `$` alternative). `\1` backreferences the captured key type (e.g. "RSA ") so a
32
- // "BEGIN RSA PRIVATE KEY" block cannot be closed by an unrelated "END EC PRIVATE KEY" line.
33
- pattern: /-----BEGIN ([A-Z ]*)PRIVATE KEY-----[\s\S]*?(?:-----END \1PRIVATE KEY-----|$)/g,
34
- replacement: () => "[REDACTED:private_key]",
35
- },
36
- {
37
- kind: "auth_header",
38
- // The value is ONE token after an optional known scheme, never the rest of the line — a
39
- // rest-of-line value would eat a trailing IP/cause in a message like `request failed
40
- // (Authorization: Bearer <tok>): connect ECONNREFUSED 10.0.4.7:443`.
41
- //
42
- // Split into two non-overlapping alternatives (scheme+value vs. no-scheme+value) rather than
43
- // one optional scheme group, for idempotency: with a single optional group, a second pass over
44
- // already-redacted text (`Authorization: Bearer [REDACTED:auth_header]`) would fail the
45
- // `(?!\[REDACTED)` lookahead on the "with scheme" attempt, backtrack the optional group away,
46
- // and then match the bare word "Bearer" itself as the "value" — corrupting already-redacted
47
- // text. The second alternative's own `(?!(?:Bearer|...)\s)` explicitly refuses to start on a
48
- // scheme keyword, so when the first alternative's lookahead fails there is no fallback left to
49
- // backtrack into, and the whole rule correctly finds no match on a second pass.
50
- pattern: /(?<![A-Za-z0-9-])((?:proxy-)?authorization|x-api-key|api-key|x-goog-api-key|x-auth-token)(\s*["']?\s*[:=]\s*["']?)(?:((?:Bearer|Basic|Token|Digest|ApiKey)\s+)(?!\[REDACTED)[^\s"'),;]+|(?!\[REDACTED)(?!(?:Bearer|Basic|Token|Digest|ApiKey)\s)[^\s"'),;]+)/gi,
51
- replacement: ({ match: m }) => `${m[1]}${m[2]}${m[3] ?? ""}[REDACTED:auth_header]`,
52
- },
53
- {
54
- kind: "auth_header",
55
- pattern: /(?<![A-Za-z0-9-])((?:set-)?cookie)(\s*[:=]\s*)(?!\[REDACTED)[^\s"'),;]+(?:;\s*[^\s"'),;]+)*/gi,
56
- replacement: ({ match: m }) => `${m[1]}${m[2]}[REDACTED:auth_header]`,
57
- },
58
- {
59
- kind: "url_credentials",
60
- // Host, port, IP and path all stay — only the `user:pass@` half is replaced. The password class
61
- // ADMITS `@` and backtracks to the LAST one before the authority ends (2026-09-16 security
62
- // review): a password that was never percent-encoded — `postgres://u:p@ss4@host/db` — otherwise
63
- // matched only up to its FIRST `@`, leaving the tail (`ss4`) of the password in the output.
64
- // `?` is excluded so a query string's own `@` cannot drag the match past the authority.
65
- pattern: /\b([a-z][a-z0-9+.-]*:\/\/)(?!\[REDACTED)[^\s/@:]+:[^\s/?]+@/gi,
66
- replacement: ({ match: m }) => `${m[1]}[REDACTED:url_credentials]@`,
67
- },
68
- ...REUSED_CREDENTIAL_RULES,
69
- {
70
- kind: "stripe_key",
71
- pattern: /(?<![A-Za-z0-9_])(?:sk|rk)_(?:live|test)_[0-9A-Za-z]{16,}/g,
72
- replacement: () => "[REDACTED:stripe_key]",
73
- },
74
- {
75
- kind: "stripe_key",
76
- pattern: /(?<![A-Za-z0-9_])whsec_[A-Za-z0-9]{24,}/g,
77
- replacement: () => "[REDACTED:stripe_key]",
78
- },
79
- {
80
- kind: "github_token",
81
- // Covers `ghs_`/`ghu_`/`ghr_` and lengths the exact-length SECRET_SHAPE_PATTERNS entries miss.
82
- pattern: /(?<![A-Za-z0-9_])gh[pousr]_[A-Za-z0-9]{30,}/g,
83
- replacement: () => "[REDACTED:github_token]",
84
- },
85
- {
86
- kind: "openai_key",
87
- pattern: /(?<![A-Za-z0-9_-])sk-(?:proj|svcacct|admin)-[A-Za-z0-9_-]{20,}/g,
88
- replacement: () => "[REDACTED:openai_key]",
89
- },
90
- {
91
- kind: "anthropic_key",
92
- // SECRET_SHAPE_PATTERNS' own `sk-ant-` entry needs 90+ trailing characters, which is right for the
93
- // repo-wide static check (a committed key is whole) but wrong here (2026-09-16 security review):
94
- // an upstream 401 often echoes a TRUNCATED key, and `sk-[A-Za-z0-9]{40,}` cannot cover it either
95
- // because `sk-ant-api03-` carries hyphens. The prefix alone is specific enough at this length.
96
- pattern: /(?<![A-Za-z0-9_-])sk-ant-[A-Za-z0-9_-]{20,}/g,
97
- replacement: () => "[REDACTED:anthropic_key]",
98
- },
99
- {
100
- kind: "google_api_key",
101
- pattern: /(?<![A-Za-z0-9_.-])AQ\.[A-Za-z0-9_-]{20,}/g,
102
- replacement: () => "[REDACTED:google_api_key]",
103
- },
104
- {
105
- kind: "aws_access_key",
106
- pattern: /(?<![0-9A-Z])ASIA[0-9A-Z]{16}(?![0-9A-Z])/g,
107
- replacement: () => "[REDACTED:aws_access_key]",
108
- },
109
- {
110
- kind: "jwt",
111
- pattern: /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,
112
- replacement: () => "[REDACTED:jwt]",
113
- },
114
- {
115
- kind: "bearer_token",
116
- // Bare scheme outside a header line. The value must be at least 16 characters AND contain a
117
- // digit, so ordinary prose ("Bearer token", "Basic authentication is not supported") is
118
- // untouched.
119
- pattern: /\b(Bearer|Basic|Token)\s+(?!\[REDACTED)(?=[A-Za-z0-9._~+/=:-]*\d)[A-Za-z0-9._~+/=:-]{16,}/g,
120
- replacement: ({ match: m }) => `${m[1]} [REDACTED:bearer_token]`,
121
- },
122
- {
123
- kind: "labeled_secret",
124
- // Assignment form only — never a bare prose colon (`password: must be...` is untouched).
125
- pattern: new RegExp(`(?<![A-Za-z0-9])(${LABELED_SECRET_LABELS})(\\s*=\\s*)(?!\\[REDACTED)([^\\s"'&,;})]+)`, "gi"),
126
- replacement: ({ match: m }) => `${m[1]}${m[2]}[REDACTED:labeled_secret]`,
127
- },
128
- {
129
- kind: "labeled_secret",
130
- // JSON form: `"label":"value"`.
131
- pattern: new RegExp(`"(${LABELED_SECRET_LABELS})"(\\s*:\\s*)"(?!\\[REDACTED)[^"]+"`, "gi"),
132
- replacement: ({ match: m }) => `"${m[1]}"${m[2]}"[REDACTED:labeled_secret]"`,
133
- },
134
- {
135
- kind: "labeled_secret",
136
- // Colon form: `api_key: <value>`, `{ api_key: 'value' }`, `\"api_key\":\"value\"` (2026-09-16
137
- // security review). The `=` and double-quoted-JSON rules above miss every one of these, and they
138
- // are the shapes a real failure arrives in most often — `util.inspect` of a request config, a
139
- // YAML/pretty-printed body, or a JSON error body embedded inside ANOTHER JSON string, where the
140
- // escaped `\"` defeats the plain JSON rule.
141
- //
142
- // Prose is kept out by the VALUE's own shape rather than by banning the colon: a quoted value is
143
- // always taken, an unquoted one only when it is a single ≥12-character token. That is what keeps
144
- // this file's Must NOT change list intact — `password: must be at least 8 characters` stops at
145
- // the 4-character `must`, and `token expired at ...` has no colon at all.
146
- pattern: new RegExp(`(?<![A-Za-z0-9])(${LABELED_SECRET_LABELS})(\\\\?["']?\\s*:\\s*)(?:(\\\\?["'])(?!\\[REDACTED)[^"'\\\\\\r\\n]+\\3|(?!\\[REDACTED)[^\\s"',;}]{12,})`, "gi"),
147
- replacement: ({ match: m }) => `${m[1]}${m[2]}${m[3] ?? ""}[REDACTED:labeled_secret]${m[3] ?? ""}`,
148
- },
149
- {
150
- kind: "labeled_secret",
151
- // Query-string form: `?key=value` / `&token=value`.
152
- pattern: /([?&](?:key|api_key|api-key|token|access_token|sig|signature)=)(?!\[REDACTED)[^&#\s"']+/gi,
153
- replacement: ({ match: m }) => `${m[1]}[REDACTED:labeled_secret]`,
154
- },
155
- ];
156
- /** Redacts credential values with a required policy; returns text and replacement count. */
157
- export function redactSecretShapes({ text, policy }) {
158
- if (text.length === 0)
159
- return { text, redactions: 0 };
160
- let redactions = 0;
161
- let result = text;
162
- // Preserve the original policy slot: vendor/JWT matches take precedence over host formats.
163
- const applicationRuleSlot = REDACTION_RULES.findIndex(rule => rule.kind === "bearer_token");
164
- const rules = [
165
- ...REDACTION_RULES.slice(0, applicationRuleSlot),
166
- ...(policy.additionalRules ?? []),
167
- ...REDACTION_RULES.slice(applicationRuleSlot),
168
- ];
169
- for (const rule of rules) {
170
- result = result.replace(new RegExp(rule.pattern.source, withGlobalFlag(rule.pattern.flags)), (...args) => {
171
- redactions += 1;
172
- return rule.replacement({ match: args });
173
- });
174
- }
175
- return { text: result, redactions };
176
- }
177
- // Preserve the public scanner vocabulary while core owns the single pattern catalog.
178
- export { SECRET_SHAPE_PATTERNS as SECRET_PATTERNS, PEM_PATTERN_NAME } from "@jini-ai/core";
1
+ // Compatibility path; the shared implementation lives in core.
2
+ export * from '../core/secrets-only.js';
179
3
  //# sourceMappingURL=secrets-only.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/diagnostics",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Diagnostics-bundle tooling: JSON/text secret redaction, log-source collection, manifest building, and zip packaging for support exports.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -15,6 +15,7 @@
15
15
  ".": "node",
16
16
  "./redaction/secrets-only": "universal",
17
17
  "./observability": "universal",
18
+ "./observability/node": "node",
18
19
  "./web-evidence": "universal",
19
20
  "./web-evidence/playwright": "node",
20
21
  "./domain-dns": "node"
@@ -41,6 +42,11 @@
41
42
  "import": "./dist/observability/index.js",
42
43
  "default": "./dist/observability/index.js"
43
44
  },
45
+ "./observability/node": {
46
+ "types": "./dist/observability/node.d.ts",
47
+ "import": "./dist/observability/node.js",
48
+ "default": "./dist/observability/node.js"
49
+ },
44
50
  "./web-evidence": {
45
51
  "types": "./dist/web-evidence/index.d.ts",
46
52
  "import": "./dist/web-evidence/index.js",
@@ -73,12 +79,21 @@
73
79
  "access": "public",
74
80
  "registry": "https://registry.npmjs.org"
75
81
  },
76
- "dependencies": {
82
+ "devDependencies": {
83
+ "@vitest/coverage-v8": "^2.1.9",
77
84
  "jszip": "^3.10.1",
78
- "@jini-ai/core": "0.4.0"
85
+ "@jini-ai/core": "^0.4.2"
79
86
  },
80
- "devDependencies": {
81
- "@vitest/coverage-v8": "^2.1.9"
87
+ "dependencies": {
88
+ "@jini-ai/core": "^0.4.2"
89
+ },
90
+ "peerDependencies": {
91
+ "jszip": "^3.10.1"
92
+ },
93
+ "peerDependenciesMeta": {
94
+ "jszip": {
95
+ "optional": true
96
+ }
82
97
  },
83
98
  "scripts": {
84
99
  "build": "tsc -p tsconfig.json",
@@ -1,8 +0,0 @@
1
- /** Credential-shape vocabulary for secret-only redaction; no I/O or host dependencies. */
2
- export interface SecretPattern {
3
- readonly name: string;
4
- readonly pattern: RegExp;
5
- }
6
- export declare const PEM_PATTERN_NAME = "PEM private key block";
7
- export declare const SECRET_PATTERNS: readonly SecretPattern[];
8
- //# sourceMappingURL=secret-patterns.d.ts.map
@@ -1,18 +0,0 @@
1
- /** Credential-shape vocabulary for secret-only redaction; no I/O or host dependencies. */
2
- // Named once and reused (by SECRET_PATTERNS here and by the guard's ALLOWLIST) rather than repeated
3
- // as a literal in multiple places.
4
- export const PEM_PATTERN_NAME = "PEM private key block";
5
- export const SECRET_PATTERNS = [
6
- { name: "Google API key (AIza)", pattern: /(?<![A-Za-z0-9_-])AIza[0-9A-Za-z_-]{35}(?![A-Za-z0-9_-])/ },
7
- { name: "Anthropic API key (sk-ant-)", pattern: /(?<![A-Za-z0-9_-])sk-ant-[A-Za-z0-9_-]{90,}/ },
8
- { name: "generic sk- secret key (OpenAI-shaped)", pattern: /(?<![A-Za-z0-9_-])sk-[A-Za-z0-9]{40,}/ },
9
- { name: "GitHub personal access token (classic, ghp_)", pattern: /(?<!\w)ghp_\w{36}(?!\w)/ },
10
- { name: "GitHub OAuth token (gho_)", pattern: /(?<!\w)gho_\w{36}(?!\w)/ },
11
- { name: "GitHub fine-grained PAT", pattern: /(?<!\w)github_pat_\w{80,}/ },
12
- { name: "npm access token", pattern: /(?<!\w)npm_\w{36}(?!\w)/ },
13
- { name: "Slack token", pattern: /(?<![A-Za-z0-9-])xox[baprs]-[A-Za-z0-9-]{12,}/ },
14
- { name: "AWS access key ID", pattern: /(?<![0-9A-Z])AKIA[0-9A-Z]{16}(?![0-9A-Z])/ },
15
- { name: "Fastmail app password (fm2_)", pattern: /(?<![A-Za-z0-9+/=])fm2_[A-Za-z0-9+/=]{20,}/ },
16
- { name: PEM_PATTERN_NAME, pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
17
- ];
18
- //# sourceMappingURL=secret-patterns.js.map