MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / isSensitiveFile

Function isSensitiveFile

packages/agent-core/src/tools/policies/sensitive.ts:48–82  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

46}
47
48export function isSensitiveFile(path: string): boolean {
49 const name = basename(path);
50 const comparableName = comparable(name);
51 const comparablePath = comparable(path);
52
53 if (ENV_EXEMPTIONS.has(comparableName)) return false;
54 if (PUBLIC_KEY_BASENAMES.has(comparableName)) return false;
55 if (SENSITIVE_BASENAMES.has(comparableName)) return true;
56 if (comparableName.startsWith(ENV_PREFIX)) return true;
57
58 for (const prefix of SENSITIVE_BASENAME_PREFIXES) {
59 if (comparableName === prefix) return true;
60 // Catch rename-shielded variants without flagging unrelated filenames
61 // like `id_rsafoo` or ordinary JSON files like `credentials.json`.
62 if (comparableName.length > prefix.length && comparableName.startsWith(prefix)) {
63 const suffix = comparableName.slice(prefix.length);
64 const next = suffix[0];
65 if (next === '-' || next === '_') return true;
66 if (next === '.' && SENSITIVE_DOT_VARIANT_SUFFIX_SET.has(suffix)) return true;
67 }
68 }
69
70 for (const suffixParts of SENSITIVE_PATH_SUFFIXES) {
71 const suffix = suffixParts.join('/');
72 const comparableSuffix = comparable(suffix);
73 if (
74 comparablePath.endsWith(`/${comparableSuffix}`) ||
75 comparablePath.includes(`/${comparableSuffix}/`)
76 ) {
77 return true;
78 }
79 }
80
81 return false;
82}

Callers 6

path-guard.test.tsFile · 0.90
sensitive.test.tsFile · 0.90
resolvePathAccessFunction · 0.90
filterSensitiveLinesFunction · 0.90
executionMethod · 0.90
evaluateMethod · 0.90

Calls 3

basenameFunction · 0.85
comparableFunction · 0.85
hasMethod · 0.65

Tested by

no test coverage detected