This commit is contained in:
lik
2026-09-01 22:34:36 +08:00
parent 98c9026485
commit 71aba287bf
14 changed files with 129 additions and 219 deletions
+6 -5
View File
@@ -13,21 +13,22 @@ export const getEnvTool = tool(
async (input) => {
const { name } = input || {};
const sensitiveKeys = ['API_KEY', 'SECRET', 'PASSWORD', 'TOKEN', 'CREDENTIAL'];
const isSensitive = (key) => sensitiveKeys.some(s => key.toUpperCase().includes(s));
if (name) {
const value = process.env[name];
if (value === undefined) {
return JSON.stringify({ error: `Environment variable '${name}' not found` });
}
return JSON.stringify({ name, value });
// 按名查询同样脱敏,防止 LLM 绕过读取密钥
return JSON.stringify({ name, value: isSensitive(name) ? '***REDACTED***' : value });
}
// 返回所有环境变量(过滤敏感信息)
const env = { ...process.env };
const sensitiveKeys = ['API_KEY', 'SECRET', 'PASSWORD', 'TOKEN', 'CREDENTIAL'];
for (const key of Object.keys(env)) {
const upperKey = key.toUpperCase();
if (sensitiveKeys.some(s => upperKey.includes(s))) {
if (isSensitive(key)) {
env[key] = '***REDACTED***';
}
}