Skip to content

[P1] 严重度误报:已被 .gitignore 屏蔽的密钥文件被标记为 CRITICAL #53

@nnn228085-star

Description

@nnn228085-star

问题描述
AgentGuard 对明文私钥一律报告为 CRITICAL,不考虑 git 上下文。当密钥文件满足以下条件时,实际风险应为 MEDIUM 而非 CRITICAL

  • 已在 .gitignore 中精准列出
  • 从未被 git commit
  • 文件权限为 600

将其报告为 CRITICAL 会导致告警疲劳,并可能触发不必要的应急响应(密钥轮换、CI/CD 变更等)。

建议修复方案
在 secrets 检测中加入 git 上下文感知:

async function classifyKeyExposure(keyPath: string) {
  const inGitRepo = await isInGitRepo(keyPath);
  if (!inGitRepo) return 'MEDIUM';
  const inGitignore = await checkGitignore(keyPath);
  const everCommitted = await checkGitHistory(keyPath);

  if (everCommitted) return 'CRITICAL';   // 真的泄露过
  if (!inGitignore) return 'HIGH';        // 随时可能被 commit 进去
  if (inGitignore) return 'MEDIUM';       // 防御已就位,但 key 仍在工作区
}

对所有 secrets 类型(webhook URL、API key、数据库连接串)统一应用".env / .gitignore / git history"三维分级。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions