@jini-ai/diagnostics 0.5.0 → 0.5.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @jini-ai/diagnostics
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Tovu clean-up release (2026-10-08): code Tovu moved into Jini, plus the Jini clean-up (see the commit log since 0.5.0).
8
+
3
9
  ## 0.5.0 — 2026-10-05
4
10
 
5
11
  ### BREAKING (for hosts that implement the observability ports themselves)
@@ -0,0 +1,44 @@
1
+ /** Secret-only error-display policy. Preserves paths, network addresses, emails, timestamps,
2
+ * tool IDs and ordinary prose. Ordered rules are idempotent; product formats come from policy. */
3
+ /** One (text in, text + count out) redaction pass. `redactions` is the number of values blanked —
4
+ * zero for text with nothing secret-shaped in it. */
5
+ export interface SecretRedaction {
6
+ readonly text: string;
7
+ readonly redactions: number;
8
+ }
9
+ /** One ordered rule: a global pattern and how to rebuild its replacement from the match's capture
10
+ * groups. Private — callers only ever see {@link redactSecretShapes}'s aggregate result. */
11
+ export interface RedactionRule {
12
+ readonly kind: string;
13
+ readonly pattern: RegExp;
14
+ readonly replacement: (required: {
15
+ match: readonly (string | undefined)[];
16
+ }) => string;
17
+ }
18
+ /**
19
+ * Blanks every secret-shaped VALUE in `text`, leaving everything else — including IPs, absolute
20
+ * paths, emails, tool ids, and ordinary prose — untouched.
21
+ *
22
+ * @param required - Text and the caller's redaction policy. The text is arbitrary error text. Never re-interpreted as anything other than plain text (no
23
+ * parsing, no partial JSON awareness).
24
+ * @returns The redacted text plus how many values were blanked. `redactions: 0` means nothing
25
+ * secret-shaped was found — the returned `text` is then reference-identical in content (though
26
+ * not necessarily the same string instance) to the input.
27
+ * @complexity O(r*n): each of the fixed, small rule count `r` makes one linear pass over the
28
+ * (at most `n`-length) text. Rules only ever shrink or hold text length steady, so the total work
29
+ * is bounded by `r` passes over the original length.
30
+ * @example
31
+ * redactSecretShapes({ text: "password=hunter2hunter2", policy: {} }); // { text: "password=[REDACTED:labeled_secret]", redactions: 1 }
32
+ * @overallScore 100
33
+ */
34
+ export interface RedactionPolicy {
35
+ /** Rules for caller-owned formats, applied after vendor/JWT rules and before bearer/labeled rules. Must be idempotent. */
36
+ readonly additionalRules?: readonly RedactionRule[];
37
+ }
38
+ /** Redacts credential values with a required policy; returns text and replacement count. */
39
+ export declare function redactSecretShapes({ text, policy }: {
40
+ text: string;
41
+ policy: RedactionPolicy;
42
+ }): SecretRedaction;
43
+ export { SECRET_SHAPE_PATTERNS as SECRET_PATTERNS, PEM_PATTERN_NAME, type SecretShapePattern as SecretPattern } from "@jini-ai/core";
44
+ //# sourceMappingURL=secrets-only.d.ts.map
@@ -0,0 +1,179 @@
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";
179
+ //# sourceMappingURL=secrets-only.js.map
package/dist/index.d.ts CHANGED
@@ -1,48 +1,9 @@
1
1
  /**
2
2
  * @module @jini-ai/diagnostics
3
- *
4
- * Diagnostics-bundle tooling shared by any host application's HTTP and desktop
5
- * export surfaces: endpoint constants, JSON/text secret redaction, log-source
6
- * collection (incl. macOS crash reports and coding-agent CLI logs), a manifest
7
- * builder, and a zip packager. See `archived provenance ledger` for full provenance and
8
- * scope-decision notes (this package is NOT yet in extraction-plan.md's
9
- * locked §3 package set — see that file for details).
10
-
11
- * Archived provenance rationale:
12
- * ## Design decision: `agent-logs.ts` carries real agent-CLI vocabulary, ported anyway
13
- *
14
- * `r2-packages.md`'s coupling grade for this package ("LOW... daemon-endpoint
15
- * comments") was assessed at the whole-package level. Read in isolation,
16
- * `agent-logs.ts` carries more domain content than the other six files: it
17
- * hardcodes knowledge of four specific coding-agent CLIs — Claude Code, Codex,
18
- * OpenCode, and an "AMR"-style OpenCode runtime — including their default
19
- * config-home directory names (`.claude`, `.codex`, `opencode`) and env-var
20
- * override names (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `OPENCODE_TEST_HOME`,
21
- * `XDG_DATA_HOME`). "AMR" itself is OD's own internal name for an agent
22
- * orchestration layer, not a generic term.
23
- *
24
- * This was ported anyway, deliberately, not dropped or trimmed, for three
25
- * reasons: (1) the task brief explicitly lists `agent-logs` as one of the
26
- * seven modules that make up "diagnostics-bundle tooling" and does not flag it
27
- * for exclusion the way Target 2's task brief explicitly excluded
28
- * `project-storage.ts`; (2) every one of these CLI integrations is optional
29
- * and caller-parameterized (`homeDir`/`claudeConfigDir`/`codexHome`/
30
- * `amrOpenCodeHome`/`xdgDataHome` are all inputs, not hardcoded paths the
31
- * function reaches for on its own) — a Jini-based product that drives the same
32
- * external agent CLIs (Claude Code, Codex, OpenCode are all plausible
33
- * `@jini/agent-runtime` targets per extraction-plan.md's roadmap) can reuse
34
- * this verbatim, and one that doesn't simply never calls
35
- * `buildAgentCliLogSources`; (3) the "AMR" agent slot is additive-only (only
36
- * appended to `agentDirs` when `amrOpenCodeHome`/`dataDir` is supplied) so a
37
- * non-OD consumer never sees it activate. Flagged here explicitly rather than
38
- * silently ported, per this porting session's own standard: a future
39
- * Coordinator/Software-Architect review of this not-yet-locked package should
40
- * weigh whether the Claude/Codex/OpenCode/AMR-specific vocabulary belongs in a
41
- * neutral diagnostics package or should be generalized further (e.g. a
42
- * caller-supplied list of `{agent, dir}` pairs instead of the four names being
43
- * baked into the function body). Not resolved here — this is exactly the kind
44
- * of judgment call flagged for sign-off, not a decision this task should make
45
- * unilaterally.
3
+ * Host HTTP/desktop diagnostic exports: redaction, log collection, manifest building and ZIPs.
4
+ * Agent-CLI log integrations are optional and caller-parameterized. The AMR slot activates only
5
+ * when its home/data directory is supplied. Whether this named CLI vocabulary should become a
6
+ * generic {agent, dir} list remains an owner decision; it must not change silently during cleanup.
46
7
  */
47
8
  export { DIAGNOSTICS_CONTENT_TYPE, DIAGNOSTICS_EXPORT_PATH, DIAGNOSTICS_FILENAME_PREFIX, } from "./contract.js";
48
9
  export { redactJsonValue, redactJsonText, redactText, type RedactionOptions, } from "./redaction.js";
package/dist/index.js CHANGED
@@ -1,48 +1,9 @@
1
1
  /**
2
2
  * @module @jini-ai/diagnostics
3
- *
4
- * Diagnostics-bundle tooling shared by any host application's HTTP and desktop
5
- * export surfaces: endpoint constants, JSON/text secret redaction, log-source
6
- * collection (incl. macOS crash reports and coding-agent CLI logs), a manifest
7
- * builder, and a zip packager. See `archived provenance ledger` for full provenance and
8
- * scope-decision notes (this package is NOT yet in extraction-plan.md's
9
- * locked §3 package set — see that file for details).
10
-
11
- * Archived provenance rationale:
12
- * ## Design decision: `agent-logs.ts` carries real agent-CLI vocabulary, ported anyway
13
- *
14
- * `r2-packages.md`'s coupling grade for this package ("LOW... daemon-endpoint
15
- * comments") was assessed at the whole-package level. Read in isolation,
16
- * `agent-logs.ts` carries more domain content than the other six files: it
17
- * hardcodes knowledge of four specific coding-agent CLIs — Claude Code, Codex,
18
- * OpenCode, and an "AMR"-style OpenCode runtime — including their default
19
- * config-home directory names (`.claude`, `.codex`, `opencode`) and env-var
20
- * override names (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `OPENCODE_TEST_HOME`,
21
- * `XDG_DATA_HOME`). "AMR" itself is OD's own internal name for an agent
22
- * orchestration layer, not a generic term.
23
- *
24
- * This was ported anyway, deliberately, not dropped or trimmed, for three
25
- * reasons: (1) the task brief explicitly lists `agent-logs` as one of the
26
- * seven modules that make up "diagnostics-bundle tooling" and does not flag it
27
- * for exclusion the way Target 2's task brief explicitly excluded
28
- * `project-storage.ts`; (2) every one of these CLI integrations is optional
29
- * and caller-parameterized (`homeDir`/`claudeConfigDir`/`codexHome`/
30
- * `amrOpenCodeHome`/`xdgDataHome` are all inputs, not hardcoded paths the
31
- * function reaches for on its own) — a Jini-based product that drives the same
32
- * external agent CLIs (Claude Code, Codex, OpenCode are all plausible
33
- * `@jini/agent-runtime` targets per extraction-plan.md's roadmap) can reuse
34
- * this verbatim, and one that doesn't simply never calls
35
- * `buildAgentCliLogSources`; (3) the "AMR" agent slot is additive-only (only
36
- * appended to `agentDirs` when `amrOpenCodeHome`/`dataDir` is supplied) so a
37
- * non-OD consumer never sees it activate. Flagged here explicitly rather than
38
- * silently ported, per this porting session's own standard: a future
39
- * Coordinator/Software-Architect review of this not-yet-locked package should
40
- * weigh whether the Claude/Codex/OpenCode/AMR-specific vocabulary belongs in a
41
- * neutral diagnostics package or should be generalized further (e.g. a
42
- * caller-supplied list of `{agent, dir}` pairs instead of the four names being
43
- * baked into the function body). Not resolved here — this is exactly the kind
44
- * of judgment call flagged for sign-off, not a decision this task should make
45
- * unilaterally.
3
+ * Host HTTP/desktop diagnostic exports: redaction, log collection, manifest building and ZIPs.
4
+ * Agent-CLI log integrations are optional and caller-parameterized. The AMR slot activates only
5
+ * when its home/data directory is supplied. Whether this named CLI vocabulary should become a
6
+ * generic {agent, dir} list remains an owner decision; it must not change silently during cleanup.
46
7
  */
47
8
  export { DIAGNOSTICS_CONTENT_TYPE, DIAGNOSTICS_EXPORT_PATH, DIAGNOSTICS_FILENAME_PREFIX, } from "./contract.js";
48
9
  export { redactJsonValue, redactJsonText, redactText, } from "./redaction.js";
@@ -1,4 +1,4 @@
1
- import { redactSecretShapes } from '../redaction/secrets-only.js';
1
+ import { redactSecretShapes } from '../core/secrets-only.js';
2
2
  /** A low-cardinality error label: a SCREAMING_CASE code (ECONNREFUSED, SQLITE_BUSY), else the class
3
3
  * name. Messages are never exported: they carry SQL fragments, hostnames, emails, even credentials. */
4
4
  export function errorType(error) {
@@ -1,44 +1,2 @@
1
- /** Secret-only error-display policy. Preserves paths, network addresses, emails, timestamps,
2
- * tool IDs and ordinary prose. Ordered rules are idempotent; product formats come from policy. */
3
- /** One (text in, text + count out) redaction pass. `redactions` is the number of values blanked —
4
- * zero for text with nothing secret-shaped in it. */
5
- export interface SecretRedaction {
6
- readonly text: string;
7
- readonly redactions: number;
8
- }
9
- /** One ordered rule: a global pattern and how to rebuild its replacement from the match's capture
10
- * groups. Private — callers only ever see {@link redactSecretShapes}'s aggregate result. */
11
- export interface RedactionRule {
12
- readonly kind: string;
13
- readonly pattern: RegExp;
14
- readonly replacement: (required: {
15
- match: readonly (string | undefined)[];
16
- }) => string;
17
- }
18
- /**
19
- * Blanks every secret-shaped VALUE in `text`, leaving everything else — including IPs, absolute
20
- * paths, emails, tool ids, and ordinary prose — untouched.
21
- *
22
- * @param required - Text and the caller's redaction policy. The text is arbitrary error text. Never re-interpreted as anything other than plain text (no
23
- * parsing, no partial JSON awareness).
24
- * @returns The redacted text plus how many values were blanked. `redactions: 0` means nothing
25
- * secret-shaped was found — the returned `text` is then reference-identical in content (though
26
- * not necessarily the same string instance) to the input.
27
- * @complexity O(r*n): each of the fixed, small rule count `r` makes one linear pass over the
28
- * (at most `n`-length) text. Rules only ever shrink or hold text length steady, so the total work
29
- * is bounded by `r` passes over the original length.
30
- * @example
31
- * redactSecretShapes({ text: "password=hunter2hunter2", policy: {} }); // { text: "password=[REDACTED:labeled_secret]", redactions: 1 }
32
- * @overallScore 100
33
- */
34
- export interface RedactionPolicy {
35
- /** Rules for caller-owned formats, applied after vendor/JWT rules and before bearer/labeled rules. Must be idempotent. */
36
- readonly additionalRules?: readonly RedactionRule[];
37
- }
38
- /** Redacts credential values with a required policy; returns text and replacement count. */
39
- export declare function redactSecretShapes({ text, policy }: {
40
- text: string;
41
- policy: RedactionPolicy;
42
- }): SecretRedaction;
43
- export { SECRET_SHAPE_PATTERNS as SECRET_PATTERNS, PEM_PATTERN_NAME, type SecretShapePattern as SecretPattern } from "@jini-ai/core";
1
+ export * from '../core/secrets-only.js';
44
2
  //# sourceMappingURL=secrets-only.d.ts.map
@@ -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
@@ -140,6 +140,7 @@ export type ObservePageResult = {
140
140
  } | {
141
141
  readonly ok: false;
142
142
  readonly reason: string;
143
+ readonly offOriginUrl?: string;
143
144
  };
144
145
  /** A supplied consent selector triggers one click and a second observation; absence means no
145
146
  * interaction. This belongs to call options rather than the required page/limit contract. */
@@ -140,6 +140,9 @@ async function observeOnePage(browser, originBaseUrl, path, input, timeoutMs) {
140
140
  maxContrastSamples: SITE_EVIDENCE_LIMITS.maxContrastSamples,
141
141
  }, input.consentAcceptSelector === undefined ? {} : { consentAcceptSelector: input.consentAcceptSelector });
142
142
  if (!result.ok) {
143
+ if (result.offOriginUrl && !isSameOriginUrl({ baseUrl: originBaseUrl, candidateUrl: result.offOriginUrl })) {
144
+ return { kind: "skipped", skipped: skip(path, "off-origin-redirect", `redirected off the inspected origin to '${redactToOrigin(result.offOriginUrl)}' — not inspected; this tool only observes ${originBaseUrl}`) };
145
+ }
143
146
  return { kind: "skipped", skipped: skip(path, "navigation-failed", result.reason) };
144
147
  }
145
148
  // Second same-origin layer (`same-origin.ts`'s header, layer 2): the path could not name