refactor(config): normalize whitelist suffixes once

This commit is contained in:
Gustavo Madeira Santana
2026-02-15 10:18:19 -05:00
parent bfa9229c6e
commit a32a240d40

View File

@@ -101,14 +101,19 @@ const SENSITIVE_KEY_WHITELIST_SUFFIXES = [
"tokencount",
"tokenlimit",
"tokenbudget",
"passwordfile",
"passwordFile",
] as const;
const NORMALIZED_SENSITIVE_KEY_WHITELIST_SUFFIXES = SENSITIVE_KEY_WHITELIST_SUFFIXES.map((suffix) =>
suffix.toLowerCase(),
);
const SENSITIVE_PATTERNS = [/token$/i, /password/i, /secret/i, /api.?key/i];
export function isSensitiveConfigPath(path: string): boolean {
const lowerPath = path.toLowerCase();
const whitelisted = SENSITIVE_KEY_WHITELIST_SUFFIXES.some((suffix) => lowerPath.endsWith(suffix));
const whitelisted = NORMALIZED_SENSITIVE_KEY_WHITELIST_SUFFIXES.some((suffix) =>
lowerPath.endsWith(suffix),
);
return !whitelisted && SENSITIVE_PATTERNS.some((pattern) => pattern.test(path));
}