Communitygithub.com

安全扫描技能

使用 AgentShield 扫描你的 Claude Code 配置(.claude/ 目录)中的安全漏洞、配置错误和注入风险。审计 CLAUDE.md、settings.json、MCP 服务器、钩子和代理定义时使用。

安全扫描技能 是什么?

该技能提供了一种系统化的方法,用于审计 Claude Code 项目的安全健康状况。它扫描关键的配置文件,如 CLAUDE.md 中的硬编码密钥、settings.json 中的宽松权限、mcp.json 中的风险 MCP 服务器、hooks/ 中的命令注入以及 agents/*.md 中的不受限制的工具访问。它使用 AgentShield 库,支持通过 npx 或全局 npm 安装运行,并提供终端、JSON、Markdown 和 HTML 格式的输出。该技能还包括自动修复能力、一个可选的“Opus 4.6 深度分析”模式,该模式使用红蓝对抗 AI 管道进行高级威胁检测,以及一个用于创建安全默认配置的初始化命令。它适用于 macOS、Linux 和 Windows 系统,可以集成到 GitHub Actions 等 CI/CD 管道中,通过严重性筛选和失败条件来确保配置更改在部署前经过审核。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/security-scan

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

安全扫描技能 是做什么的?

使用 AgentShield 审计你的 Claude Code 配置是否存在安全问题。

何时激活

  • 设置新的 Claude Code 项目时
  • 修改 .claude/settings.json、CLAUDE.md 或 MCP 配置后
  • 提交配置更改之前
  • 接入已有 Claude Code 配置的新仓库时
  • 定期进行安全卫生检查时

扫描内容

文件检查项
CLAUDE.md硬编码密钥、自动运行指令、提示注入模式
settings.json过于宽松的允许列表、缺失的拒绝列表、危险的绕过标志
mcp.json风险 MCP 服务器、硬编码的环境密钥、npx 供应链风险
hooks/通过插值进行命令注入、数据泄露、静默错误抑制
agents/*.md不受限制的工具访问、提示注入面、缺失的模型规范

前提条件

必须安装 AgentShield。检查并按需安装:

# 检查是否已安装
npx ecc-agentshield --version

# 全局安装(推荐)
npm install -g ecc-agentshield

# 或通过 npx 直接运行(无需安装)
npx ecc-agentshield scan .

使用方法

基本扫描

针对当前项目的 .claude/ 目录运行:

# 扫描当前项目
npx ecc-agentshield scan

# 扫描指定路径
npx ecc-agentshield scan --path /path/to/.claude

# 使用最小严重性过滤器
npx ecc-agentshield scan --min-severity medium

输出格式

# 终端输出(默认)— 带评级的彩色报告
npx ecc-agentshield scan

# JSON — 用于 CI/CD 集成
npx ecc-agentshield scan --format json

# Markdown — 用于文档
npx ecc-agentshield scan --format markdown

# HTML — 自包含的深色主题报告
npx ecc-agentshield scan --format html > security-report.html

自动修复

自动应用安全修复(仅修复标记为可自动修复的项):

npx ecc-agentshield scan --fix

这将:

  • 用环境变量引用替换硬编码密钥
  • 将通配符权限收紧为限定范围替代方案
  • 绝不修改仅限手动建议的项

Opus 4.6 深度分析

运行对抗性三智能体管道进行更深入的分析:

# 需要 ANTHROPIC_API_KEY
export ANTHROPIC_API_KEY=your-key
npx ecc-agentshield scan --opus --stream

这将运行:

  1. 攻击者(红队) — 发现攻击向量
  2. 防御者(蓝队) — 推荐加固措施
  3. 审计员(最终裁决) — 综合双方观点

初始化安全配置

从头开始创建新的安全 .claude/ 配置:

npx ecc-agentshield init

创建:

  • settings.json(带有作用域权限和拒绝列表)
  • CLAUDE.md(带有安全最佳实践)
  • mcp.json 占位符

GitHub Action

添加到你的 CI 管道:

- uses: affaan-m/agentshield@v1
  with:
    path: '.'
    min-severity: 'medium'
    fail-on-findings: true

严重性等级

等级分数含义
A90-100安全配置
B75-89轻微问题
C60-74需要关注
D40-59重大风险
F0-39严重漏洞

结果解读

严重发现(立即修复)

  • 配置文件中的硬编码 API 密钥或令牌
  • 允许列表中的 Bash(*)(不受限制的 shell 访问)
  • 通过 ${file} 插值在钩子中的命令注入
  • 运行 shell 的 MCP 服务器

高危发现(上线前修复)

  • CLAUDE.md 中的自动运行指令(提示注入向量)
  • 权限中缺失拒绝列表
  • 具有不必要 Bash 访问权限的代理

中等发现(推荐修复)

  • 钩子中的静默错误抑制(2>/dev/null、|| true)
  • 缺失 PreToolUse 安全钩子
  • MCP 服务器配置中的 npx -y 自动安装

信息发现(仅供参考)

  • MCP 服务器缺少描述
  • 禁止性指令正确标记为良好实践

链接

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能