MCPcopy Create free account
hub / github.com/cortexkit/magic-context / isSecretKey

Function isSecretKey

packages/plugin/src/shared/redaction.ts:74–108  ·  view source on GitHub ↗
(key: string)

Source from the content-addressed store, hash-verified

72]);
73
74export function isSecretKey(key: string): boolean {
75 const segments = key
76 .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
77 .toLowerCase()
78 .split(/[._-]+/)
79 .filter(Boolean);
80 if (segments.length === 0) return false;
81
82 if (segments.length === 1) {
83 const first = segments[0];
84 return Boolean(first && SECRET_SEGMENT_PATTERN.test(first));
85 }
86
87 for (let i = 0; i < segments.length; i++) {
88 const seg = segments[i];
89 if (!seg || !SECRET_SEGMENT_PATTERN.test(seg)) continue;
90
91 let trailingOk = true;
92 for (let j = i + 1; j < segments.length; j++) {
93 const tail = segments[j];
94 if (!tail) continue;
95 if (TRAILING_DESCRIPTORS.has(tail)) continue;
96 if (SECRET_SEGMENT_PATTERN.test(tail)) continue;
97 trailingOk = false;
98 break;
99 }
100 if (!trailingOk) continue;
101
102 for (let k = i - 1; k >= 0; k--) {
103 const lead = segments[k];
104 if (lead && SECRET_QUALIFIERS.has(lead)) return true;
105 }
106 }
107 return false;
108}
109
110export function sanitizePathString(value: string): string {
111 const home = homedir();

Callers 2

redaction.test.tsFile · 0.90
sanitizeConfigValueFunction · 0.85

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected