mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 21:10:54 +00:00
refactor(config): split sensitive path matching helpers
This commit is contained in:
@@ -8,10 +8,22 @@ const { mapSensitivePaths } = __test__;
|
||||
|
||||
describe("isSensitiveConfigPath", () => {
|
||||
it("matches whitelist suffixes case-insensitively", () => {
|
||||
expect(isSensitiveConfigPath("maxTokens")).toBe(false);
|
||||
expect(isSensitiveConfigPath("MAXTOKENS")).toBe(false);
|
||||
expect(isSensitiveConfigPath("channels.irc.nickserv.passwordFile")).toBe(false);
|
||||
expect(isSensitiveConfigPath("channels.irc.nickserv.PASSWORDFILE")).toBe(false);
|
||||
const whitelistedPaths = [
|
||||
"maxTokens",
|
||||
"maxOutputTokens",
|
||||
"maxInputTokens",
|
||||
"maxCompletionTokens",
|
||||
"contextTokens",
|
||||
"totalTokens",
|
||||
"tokenCount",
|
||||
"tokenLimit",
|
||||
"tokenBudget",
|
||||
"channels.irc.nickserv.passwordFile",
|
||||
];
|
||||
for (const path of whitelistedPaths) {
|
||||
expect(isSensitiveConfigPath(path)).toBe(false);
|
||||
expect(isSensitiveConfigPath(path.toUpperCase())).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps true sensitive keys redacted", () => {
|
||||
|
||||
@@ -109,12 +109,17 @@ const NORMALIZED_SENSITIVE_KEY_WHITELIST_SUFFIXES = SENSITIVE_KEY_WHITELIST_SUFF
|
||||
|
||||
const SENSITIVE_PATTERNS = [/token$/i, /password/i, /secret/i, /api.?key/i];
|
||||
|
||||
export function isSensitiveConfigPath(path: string): boolean {
|
||||
function isWhitelistedSensitivePath(path: string): boolean {
|
||||
const lowerPath = path.toLowerCase();
|
||||
const whitelisted = NORMALIZED_SENSITIVE_KEY_WHITELIST_SUFFIXES.some((suffix) =>
|
||||
lowerPath.endsWith(suffix),
|
||||
);
|
||||
return !whitelisted && SENSITIVE_PATTERNS.some((pattern) => pattern.test(path));
|
||||
return NORMALIZED_SENSITIVE_KEY_WHITELIST_SUFFIXES.some((suffix) => lowerPath.endsWith(suffix));
|
||||
}
|
||||
|
||||
function matchesSensitivePattern(path: string): boolean {
|
||||
return SENSITIVE_PATTERNS.some((pattern) => pattern.test(path));
|
||||
}
|
||||
|
||||
export function isSensitiveConfigPath(path: string): boolean {
|
||||
return !isWhitelistedSensitivePath(path) && matchesSensitivePattern(path);
|
||||
}
|
||||
|
||||
export function buildBaseHints(): ConfigUiHints {
|
||||
|
||||
Reference in New Issue
Block a user