@vincemakes/kiso-secrets 0.0.0-stage → 0.57.0
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/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/content.d.ts +18 -0
- package/dist/content.js +42 -0
- package/dist/credential-files.d.ts +12 -0
- package/dist/credential-files.js +61 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/locations.d.ts +9 -0
- package/dist/locations.js +79 -0
- package/dist/secret-env.d.ts +28 -0
- package/dist/secret-env.js +49 -0
- package/package.json +36 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kiso contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vincemakes/kiso-secrets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One secret detector for kiso. It has zero dependencies and zero imports, so tools-node, the runtime and the MCP
|
|
4
|
+
extension's bundle all use the same rules.
|
|
5
|
+
|
|
6
|
+
- `isCredentialName(name)` and `isCredentialPath(path, separator?)`: the credential-file set (files whose
|
|
7
|
+
conventional purpose is to hold credentials).
|
|
8
|
+
- `SHELL_STRIP_EXACT` and `strippedShellEnv(env, secretNames)`: the child-environment strip.
|
|
9
|
+
- `isSecretLocation(path, { home, kisoHome, separator? })`: the secret-location deny list (the SSH directory,
|
|
10
|
+
GnuPG, the OS keychain and credential stores, browser profile roots, known password-manager stores, the
|
|
11
|
+
credential-file set, kiso's own credentials), by name only.
|
|
12
|
+
- `findSecret(text)`: the first secret by shape (private-key blocks, provider and cloud key formats, JWTs,
|
|
13
|
+
credentials in URLs, secret assignments with real-looking values), or `null`. It matches by shape only, never by
|
|
14
|
+
entropy alone.
|
|
15
|
+
|
|
16
|
+
The package answers whether something is a secret; what to do with a hit is the caller's policy.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape-only secret patterns (M2; the kiso-secrets spec § 4). A match must be
|
|
3
|
+
* a credential BY SHAPE — a key format, a private-key block, credentials in a
|
|
4
|
+
* URL, a secret assignment with a real-looking value — never by entropy
|
|
5
|
+
* alone: precision over recall. A new shape is added by evidence (a named
|
|
6
|
+
* format), never by widening a pattern.
|
|
7
|
+
*
|
|
8
|
+
* `findSecret` answers where the first secret is; callers decide what to do
|
|
9
|
+
* (M2's admission drops the record and never writes the match anywhere).
|
|
10
|
+
*/
|
|
11
|
+
export type SecretKind = "pem-private-key" | "aws-access-key" | "github-token" | "slack-token" | "provider-key" | "google-api-key" | "jwt" | "url-credentials" | "assignment";
|
|
12
|
+
export interface SecretMatch {
|
|
13
|
+
readonly kind: SecretKind;
|
|
14
|
+
readonly start: number;
|
|
15
|
+
readonly end: number;
|
|
16
|
+
}
|
|
17
|
+
/** The first secret in `text` by position, or null. */
|
|
18
|
+
export declare function findSecret(text: string): SecretMatch | null;
|
package/dist/content.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape-only secret patterns (M2; the kiso-secrets spec § 4). A match must be
|
|
3
|
+
* a credential BY SHAPE — a key format, a private-key block, credentials in a
|
|
4
|
+
* URL, a secret assignment with a real-looking value — never by entropy
|
|
5
|
+
* alone: precision over recall. A new shape is added by evidence (a named
|
|
6
|
+
* format), never by widening a pattern.
|
|
7
|
+
*
|
|
8
|
+
* `findSecret` answers where the first secret is; callers decide what to do
|
|
9
|
+
* (M2's admission drops the record and never writes the match anywhere).
|
|
10
|
+
*/
|
|
11
|
+
/** A value that names a secret without being one. */
|
|
12
|
+
const PLACEHOLDER = /^(?:\$\{.*\}|\$[A-Z_][A-Z0-9_]*|<.*>|\{\{.*\}\}|x+|\*+|\.+|changeme|example|placeholder|redacted|your[_-].*|process\.env\..*)$/i;
|
|
13
|
+
const PATTERNS = [
|
|
14
|
+
{ kind: "pem-private-key", re: /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----/g },
|
|
15
|
+
{ kind: "aws-access-key", re: /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g },
|
|
16
|
+
{ kind: "github-token", re: /\b(?:gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{82})\b/g },
|
|
17
|
+
{ kind: "slack-token", re: /\bxox[abprs]-[A-Za-z0-9]+(?:-[A-Za-z0-9]+){2,}/g },
|
|
18
|
+
// the current provider forms: Anthropic, OpenAI project keys, and the plain
|
|
19
|
+
// sk- keys of OpenAI-compatible routes (DeepSeek and others)
|
|
20
|
+
{ kind: "provider-key", re: /\bsk-(?:ant-[A-Za-z0-9_-]{20,}|proj-[A-Za-z0-9_-]{20,}|[A-Za-z0-9]{32,})/g },
|
|
21
|
+
{ kind: "google-api-key", re: /\bAIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])/g },
|
|
22
|
+
{ kind: "jwt", re: /\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g },
|
|
23
|
+
{ kind: "url-credentials", re: /\b[a-z][a-z0-9+.-]*:\/\/[^\s/:@"'`]+:([^\s/@"'`]+)@[^\s/"'`]+/gi, value: 1 },
|
|
24
|
+
// a secret-named key assigned a value that mixes letters and digits
|
|
25
|
+
{ kind: "assignment", re: /\b(?:password|passwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token)\s*[:=]\s*(["']?)([^\s"'`,;)]{8,})\1/gi, value: 2 },
|
|
26
|
+
];
|
|
27
|
+
const realValue = (v) => !PLACEHOLDER.test(v) && /[A-Za-z]/.test(v) && /[0-9]/.test(v);
|
|
28
|
+
/** The first secret in `text` by position, or null. */
|
|
29
|
+
export function findSecret(text) {
|
|
30
|
+
let best = null;
|
|
31
|
+
for (const { kind, re, value } of PATTERNS) {
|
|
32
|
+
re.lastIndex = 0;
|
|
33
|
+
for (let m = re.exec(text); m !== null; m = re.exec(text)) {
|
|
34
|
+
if (value !== undefined && !realValue(m[value] ?? ""))
|
|
35
|
+
continue;
|
|
36
|
+
if (best === null || m.index < best.start)
|
|
37
|
+
best = { kind, start: m.index, end: m.index + m[0].length };
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return best;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The credential-file set, moved verbatim from tools-node's corpus.ts
|
|
3
|
+
* (the kiso-secrets leaf, spec 2026-11-27). Its rulings are unchanged; only
|
|
4
|
+
* the path separator became a parameter, since this package imports nothing.
|
|
5
|
+
*/
|
|
6
|
+
/** RO-F4: the credential files named by their DIRECTORY as well — a path
|
|
7
|
+
* (absolute or root-relative), folded to lower case as a case-insensitive
|
|
8
|
+
* disk would. The read-only shell rule asks this same question.
|
|
9
|
+
* `separator` is the host's path separator: this package imports nothing,
|
|
10
|
+
* so the caller passes it (tools-node passes node:path's `sep`). */
|
|
11
|
+
export declare function isCredentialPath(path: string, separator?: string): boolean;
|
|
12
|
+
export declare function isCredentialName(name: string): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The credential-file set, moved verbatim from tools-node's corpus.ts
|
|
3
|
+
* (the kiso-secrets leaf, spec 2026-11-27). Its rulings are unchanged; only
|
|
4
|
+
* the path separator became a parameter, since this package imports nothing.
|
|
5
|
+
*/
|
|
6
|
+
/** THE CREDENTIAL SET — files whose CONVENTIONAL PURPOSE is to hold
|
|
7
|
+
* credentials. That class is the rule; the list is its application, and
|
|
8
|
+
* the next candidate is judged by the class rather than by resemblance.
|
|
9
|
+
* Changes to this list are RULINGS, not edits.
|
|
10
|
+
*
|
|
11
|
+
* Enumerated rather than matched by prefix: `.env*` as a prefix would
|
|
12
|
+
* also swallow `.environment` and `.envoy.yaml`, which are ordinary
|
|
13
|
+
* files that happen to start the same way.
|
|
14
|
+
*
|
|
15
|
+
* IN, and why:
|
|
16
|
+
* `.env`, `.env.*` the convention itself
|
|
17
|
+
* `.envrc` direnv — routinely `export AWS_SECRET_...`
|
|
18
|
+
* `.netrc` machine credentials, by definition
|
|
19
|
+
* id_rsa, id_dsa, private keys, by name. Their `.pub` counterparts
|
|
20
|
+
* id_ecdsa, are different names and stay searchable, which is
|
|
21
|
+
* id_ed25519 correct: a public key is public.
|
|
22
|
+
* *.pem the same, by extension
|
|
23
|
+
* `.npmrc`, `.pypirc`, `.git-credentials`, `.htpasswd` — RO-F4, the
|
|
24
|
+
* owner's 0.40.7 ruling. `.npmrc` was OUT here ("tokens
|
|
25
|
+
* in it are normally `${VAR}` placeholders") while the
|
|
26
|
+
* read-only shell rule (0.40.0, B4) already called it a
|
|
27
|
+
* credential: two lists that disagreed, so a search
|
|
28
|
+
* exposed what `cat` asked about. One set now, used by
|
|
29
|
+
* both; a literal `_authToken=` is common enough.
|
|
30
|
+
* and, by PATH (a name alone would be too broad — `config`,
|
|
31
|
+
* `credentials`): `.aws/credentials`, `.config/gh/hosts.yml`,
|
|
32
|
+
* `.docker/config.json`, `.kube/config` (isCredentialPath)
|
|
33
|
+
*
|
|
34
|
+
* OUT, deliberately, so the omissions are decisions and not oversights:
|
|
35
|
+
* `*.key` too many non-secret uses to be a credential by name
|
|
36
|
+
*
|
|
37
|
+
* An explicit `read_file` of ANY of these is unchanged. Reading on
|
|
38
|
+
* purpose is the user's model doing what it was told; an incidental hit
|
|
39
|
+
* from a search for "KEY" is exposure without intent, and only the
|
|
40
|
+
* second is what this prevents. */
|
|
41
|
+
const ENV_TEMPLATES = new Set([".env.example", ".env.sample", ".env.template"]);
|
|
42
|
+
const CREDENTIAL_NAMES = new Set([".envrc", ".netrc", "id_rsa", "id_dsa", "id_ecdsa", "id_ed25519", ".npmrc", ".pypirc", ".git-credentials", ".htpasswd"]);
|
|
43
|
+
const CREDENTIAL_PATHS = ["/.aws/credentials", "/.config/gh/hosts.yml", "/.docker/config.json", "/.kube/config"];
|
|
44
|
+
/** RO-F4: the credential files named by their DIRECTORY as well — a path
|
|
45
|
+
* (absolute or root-relative), folded to lower case as a case-insensitive
|
|
46
|
+
* disk would. The read-only shell rule asks this same question.
|
|
47
|
+
* `separator` is the host's path separator: this package imports nothing,
|
|
48
|
+
* so the caller passes it (tools-node passes node:path's `sep`). */
|
|
49
|
+
export function isCredentialPath(path, separator = "/") {
|
|
50
|
+
const folded = `/${path.split(separator).join("/")}`.toLowerCase();
|
|
51
|
+
return CREDENTIAL_PATHS.some((s) => folded.endsWith(s));
|
|
52
|
+
}
|
|
53
|
+
export function isCredentialName(name) {
|
|
54
|
+
if (ENV_TEMPLATES.has(name))
|
|
55
|
+
return false;
|
|
56
|
+
if (name === ".env" || name.startsWith(".env."))
|
|
57
|
+
return true;
|
|
58
|
+
if (CREDENTIAL_NAMES.has(name))
|
|
59
|
+
return true;
|
|
60
|
+
return name.endsWith(".pem");
|
|
61
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vincemakes/kiso-secrets — one secret detector for kiso. Zero dependencies
|
|
3
|
+
* and zero imports: tools-node, the runtime and the MCP extension's bundle
|
|
4
|
+
* all use it, and a shared rule must not drag a package graph across.
|
|
5
|
+
*/
|
|
6
|
+
export { isCredentialName, isCredentialPath } from "./credential-files.js";
|
|
7
|
+
export { SHELL_STRIP_EXACT, strippedShellEnv } from "./secret-env.js";
|
|
8
|
+
export { isSecretLocation, type SecretLocationContext } from "./locations.js";
|
|
9
|
+
export { findSecret, type SecretKind, type SecretMatch } from "./content.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vincemakes/kiso-secrets — one secret detector for kiso. Zero dependencies
|
|
3
|
+
* and zero imports: tools-node, the runtime and the MCP extension's bundle
|
|
4
|
+
* all use it, and a shared rule must not drag a package graph across.
|
|
5
|
+
*/
|
|
6
|
+
export { isCredentialName, isCredentialPath } from "./credential-files.js";
|
|
7
|
+
export { SHELL_STRIP_EXACT, strippedShellEnv } from "./secret-env.js";
|
|
8
|
+
export { isSecretLocation } from "./locations.js";
|
|
9
|
+
export { findSecret } from "./content.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SecretLocationContext {
|
|
2
|
+
/** The person's home directory, canonical. */
|
|
3
|
+
readonly home: string;
|
|
4
|
+
/** kiso's own home (`~/.kiso` unless overridden), canonical. */
|
|
5
|
+
readonly kisoHome: string;
|
|
6
|
+
/** The host's path separator; "/" when absent. */
|
|
7
|
+
readonly separator?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function isSecretLocation(path: string, ctx: SecretLocationContext): boolean;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The secret-location deny list (#31; the kiso-secrets spec § 3). True for a
|
|
3
|
+
* path that holds secrets by location: the person's SSH directory, GnuPG,
|
|
4
|
+
* the OS keychain and credential stores, browser profile roots, known
|
|
5
|
+
* password-manager stores, the credential-file set, and kiso's own
|
|
6
|
+
* credentials.
|
|
7
|
+
* The list is the owner's to confirm (ledger D12); changes are rulings.
|
|
8
|
+
*
|
|
9
|
+
* This answers "is this a secret location" and nothing else: what a read
|
|
10
|
+
* tool does with a hit is its caller's policy. The caller passes a
|
|
11
|
+
* CANONICAL path (symlinks resolved, so a link into ~/.ssh is judged by
|
|
12
|
+
* where it leads) and the host's separator; nothing is imported.
|
|
13
|
+
*/
|
|
14
|
+
import { isCredentialName, isCredentialPath } from "./credential-files.js";
|
|
15
|
+
const fold = (path, separator) => path.split(separator).join("/").replace(/\/+$/, "").toLowerCase();
|
|
16
|
+
const under = (path, dir) => path === dir || path.startsWith(`${dir}/`);
|
|
17
|
+
/**
|
|
18
|
+
* The directories under home whose whole content is secret, BY NAME ONLY (no
|
|
19
|
+
* fuzzy matching: a path that merely resembles a store is not one). Grouped
|
|
20
|
+
* by class; a new entry is a ruling, judged by its class.
|
|
21
|
+
*/
|
|
22
|
+
const SECRET_DIRS = [
|
|
23
|
+
// SSH, GnuPG and the OS keychain / credential stores
|
|
24
|
+
".ssh",
|
|
25
|
+
".gnupg",
|
|
26
|
+
"Library/Keychains",
|
|
27
|
+
".local/share/keyrings",
|
|
28
|
+
"AppData/Roaming/Microsoft/Credentials",
|
|
29
|
+
"AppData/Local/Microsoft/Credentials",
|
|
30
|
+
"AppData/Roaming/Microsoft/Protect",
|
|
31
|
+
// browser profile roots (cookies, Login Data, history), macOS / Linux / Windows
|
|
32
|
+
"Library/Application Support/Google/Chrome",
|
|
33
|
+
"Library/Application Support/Chromium",
|
|
34
|
+
"Library/Application Support/Microsoft Edge",
|
|
35
|
+
"Library/Application Support/BraveSoftware/Brave-Browser",
|
|
36
|
+
"Library/Application Support/Firefox/Profiles",
|
|
37
|
+
"Library/Cookies",
|
|
38
|
+
"Library/Safari",
|
|
39
|
+
".config/google-chrome",
|
|
40
|
+
".config/chromium",
|
|
41
|
+
".config/microsoft-edge",
|
|
42
|
+
".config/BraveSoftware/Brave-Browser",
|
|
43
|
+
".mozilla/firefox",
|
|
44
|
+
"AppData/Local/Google/Chrome/User Data",
|
|
45
|
+
"AppData/Local/Chromium/User Data",
|
|
46
|
+
"AppData/Local/Microsoft/Edge/User Data",
|
|
47
|
+
"AppData/Local/BraveSoftware/Brave-Browser/User Data",
|
|
48
|
+
"AppData/Roaming/Mozilla/Firefox/Profiles",
|
|
49
|
+
// password-manager stores
|
|
50
|
+
"Library/Group Containers/2BUA8C4S2C.com.1password",
|
|
51
|
+
"Library/Application Support/1Password",
|
|
52
|
+
".config/1Password",
|
|
53
|
+
"AppData/Local/1Password",
|
|
54
|
+
"Library/Application Support/Bitwarden",
|
|
55
|
+
".config/Bitwarden",
|
|
56
|
+
"AppData/Roaming/Bitwarden",
|
|
57
|
+
".config/keepassxc",
|
|
58
|
+
"AppData/Roaming/KeePassXC",
|
|
59
|
+
".password-store",
|
|
60
|
+
".lpass",
|
|
61
|
+
];
|
|
62
|
+
/** Password-manager databases, by extension, anywhere. */
|
|
63
|
+
const SECRET_EXTENSIONS = [".kdbx"];
|
|
64
|
+
export function isSecretLocation(path, ctx) {
|
|
65
|
+
const sep = ctx.separator ?? "/";
|
|
66
|
+
const p = fold(path, sep);
|
|
67
|
+
const home = fold(ctx.home, sep);
|
|
68
|
+
const kiso = fold(ctx.kisoHome, sep);
|
|
69
|
+
if (SECRET_DIRS.some((d) => under(p, `${home}/${d.toLowerCase()}`)))
|
|
70
|
+
return true;
|
|
71
|
+
const base = p.slice(p.lastIndexOf("/") + 1);
|
|
72
|
+
if (isCredentialName(base) || isCredentialPath(p))
|
|
73
|
+
return true;
|
|
74
|
+
if (SECRET_EXTENSIONS.some((x) => base.endsWith(x)))
|
|
75
|
+
return true;
|
|
76
|
+
if (under(p, kiso) && (base === "auth.json" || base.startsWith("credentials")))
|
|
77
|
+
return true;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE child-environment strip — ONE implementation, both children.
|
|
3
|
+
* (Moved verbatim from tools-node, the kiso-secrets leaf, 2026-11-27.)
|
|
4
|
+
*
|
|
5
|
+
* bootstrap #3 (finding #7) established the rule for shell children: the
|
|
6
|
+
* agent's own provider surface (both families' keys, base URLs and model
|
|
7
|
+
* choices) plus the generic API-key / auth-token patterns that cover other
|
|
8
|
+
* providers. Everything else passes through untouched.
|
|
9
|
+
*
|
|
10
|
+
* Astra F7 then showed the rule was incomplete AND duplicated. Incomplete:
|
|
11
|
+
* a profile's `apiKeyEnv` can be ANY name — `REVIEW_PROVIDER_TOKEN` ends in
|
|
12
|
+
* neither suffix — so the key a profile authenticates with survived into
|
|
13
|
+
* the child. Duplicated: the MCP extension carried its own copy of the list
|
|
14
|
+
* with a "keep in sync" comment, and a comment is not a mechanism; the copy
|
|
15
|
+
* did not learn the declared names and MCP stdio children kept leaking.
|
|
16
|
+
*
|
|
17
|
+
* The names must come from the caller because only the config knows which
|
|
18
|
+
* env vars are secrets. No names declared = exactly the pre-F7 behaviour,
|
|
19
|
+
* which is what a standalone extension load gets.
|
|
20
|
+
*
|
|
21
|
+
* This module imports NOTHING on purpose: the MCP extension is an esbuild
|
|
22
|
+
* bundle, and a shared rule must not drag a package graph across with it.
|
|
23
|
+
*/
|
|
24
|
+
/** The explicit credential list stripped from every child. */
|
|
25
|
+
export declare const SHELL_STRIP_EXACT: ReadonlySet<string>;
|
|
26
|
+
/** The environment a child process may see: `env` minus the exact list,
|
|
27
|
+
* minus every DECLARED secret name, minus the two suffix families. */
|
|
28
|
+
export declare function strippedShellEnv(env: Record<string, string | undefined>, secretNames?: readonly string[]): Record<string, string | undefined>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE child-environment strip — ONE implementation, both children.
|
|
3
|
+
* (Moved verbatim from tools-node, the kiso-secrets leaf, 2026-11-27.)
|
|
4
|
+
*
|
|
5
|
+
* bootstrap #3 (finding #7) established the rule for shell children: the
|
|
6
|
+
* agent's own provider surface (both families' keys, base URLs and model
|
|
7
|
+
* choices) plus the generic API-key / auth-token patterns that cover other
|
|
8
|
+
* providers. Everything else passes through untouched.
|
|
9
|
+
*
|
|
10
|
+
* Astra F7 then showed the rule was incomplete AND duplicated. Incomplete:
|
|
11
|
+
* a profile's `apiKeyEnv` can be ANY name — `REVIEW_PROVIDER_TOKEN` ends in
|
|
12
|
+
* neither suffix — so the key a profile authenticates with survived into
|
|
13
|
+
* the child. Duplicated: the MCP extension carried its own copy of the list
|
|
14
|
+
* with a "keep in sync" comment, and a comment is not a mechanism; the copy
|
|
15
|
+
* did not learn the declared names and MCP stdio children kept leaking.
|
|
16
|
+
*
|
|
17
|
+
* The names must come from the caller because only the config knows which
|
|
18
|
+
* env vars are secrets. No names declared = exactly the pre-F7 behaviour,
|
|
19
|
+
* which is what a standalone extension load gets.
|
|
20
|
+
*
|
|
21
|
+
* This module imports NOTHING on purpose: the MCP extension is an esbuild
|
|
22
|
+
* bundle, and a shared rule must not drag a package graph across with it.
|
|
23
|
+
*/
|
|
24
|
+
/** The explicit credential list stripped from every child. */
|
|
25
|
+
export const SHELL_STRIP_EXACT = new Set([
|
|
26
|
+
"ANTHROPIC_API_KEY",
|
|
27
|
+
"OPENAI_API_KEY",
|
|
28
|
+
"ANTHROPIC_BASE_URL",
|
|
29
|
+
"OPENAI_BASE_URL",
|
|
30
|
+
"ANTHROPIC_MODEL",
|
|
31
|
+
"OPENAI_MODEL",
|
|
32
|
+
]);
|
|
33
|
+
/** The environment a child process may see: `env` minus the exact list,
|
|
34
|
+
* minus every DECLARED secret name, minus the two suffix families. */
|
|
35
|
+
export function strippedShellEnv(env, secretNames = []) {
|
|
36
|
+
const declared = new Set(secretNames);
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const [key, value] of Object.entries(env)) {
|
|
39
|
+
if (SHELL_STRIP_EXACT.has(key))
|
|
40
|
+
continue;
|
|
41
|
+
if (declared.has(key))
|
|
42
|
+
continue;
|
|
43
|
+
if (key.endsWith("_API_KEY") || key.endsWith("_AUTH_TOKEN"))
|
|
44
|
+
continue;
|
|
45
|
+
if (value !== undefined)
|
|
46
|
+
out[key] = value;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@vincemakes/kiso-secrets",
|
|
3
|
+
"version": "0.57.0",
|
|
4
|
+
"description": "kiso secrets — one secret detector for kiso: the credential-file set, the child-environment strip, the secret-location deny list and shape-only content patterns. Zero dependencies and zero imports, so it bundles anywhere.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.build.json",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^26.1.2",
|
|
25
|
+
"typescript": "^5.7.2",
|
|
26
|
+
"vitest": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/vincemakes/kiso.git",
|
|
31
|
+
"directory": "packages/secrets"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/vincemakes/kiso/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/vincemakes/kiso/tree/main/packages/secrets#readme"
|
|
37
|
+
}
|