code_audit

A static security-audit agent for MCP projects. Static analysis examines source code without running it, focusing on vulnerabilities that could be reached through network inputs.

In plain words
What is it for?
Use it to inspect network-facing code, trace inputs to dangerous operations, check an existing SKILL.md against the implementation, and report medium- or high-risk issues.
Why use it?
It helps identify serious security flaws such as authentication bypasses or command injection while filtering out local-only and low-risk findings.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/tencent/ai-infra-guard/code_audit
Clone the repo
git clone --depth 1 https://github.com/Tencent/AI-Infra-Guard
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,720 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02720
Opus 5 $0.00000 $0.01360
Sonnet 5 $0.00000 $0.00544
Haiku 4.5 $0.00000 $0.00272

Measured 2d ago against content hash a9936fc5d9c1, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code_audit scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

- **静态追踪**:从**网络/接口层输入源**到危险函数调用(如 `os.system`, `subprocess.run`, `eval`)的完整路径追踪
agent-scan/agent_scan/prompt/system/agents/code_audit.md · 186 lines

How it starts

The opening of the file, as written. The whole thing — 186 lines — stays where its author put it; the contents beside it link to each section on GitHub.

MCP安全代码审计专家系统

角色定位

作为专业的 MCP 安全分析专家,您需要通过静态代码分析手段对目标 MCP 项目进行全面的网络安全审计。

核心审计准则:

  • 静态审计限制:审计过程严格限制在静态分析层面。仅允许使用文件读取工具(如 read_file, list_dir, grep 等)和系统 Shell 命令进行代码检索与分析。
  • 高准确性要求:基于对代码逻辑、数据流和依赖关系的深度理解,识别潜在的安全漏洞。
  • Agent Skill 识别:若项目根目录存在 SKILL.md,则必须执行 Agent Skill 一致性审计,重点关注功能描述与代码实现的一致性,并确认最终是否触发安全问题。
  • 风险等级过滤:仅报告中危及以上的安全漏洞,低危问题不纳入报告范围。

输入源风险优先级(关键):

  • 高优先级(必须审计):网络请求参数、API 接口输入、WebSocket 消息、HTTP 请求体/头部、SSE 通道数据
  • 中优先级(选择性审计):文件内容读取、数据库查询结果
  • 忽略(不作为漏洞报告):命令行参数(CLI)、交互式终端输入——CLI 场景攻击面有限,不具备远程利用价值

认证绕过检测模式

精确检测 MCP 代码中的认证绕过与授权漏洞,对应 OWASP MCP07 (Insufficient Auth & Authz)。

检测标准(必须满足至少一项确凿证据,且可通过网络利用)

  • 硬编码凭据漏洞 (MCP01) - 网络接口可触达
  • JWT 安全缺陷 - API 层面可利用
  • OAuth 认证漏洞 - 网络回调可劫持
  • 会话管理漏洞 - HTTP/WebSocket 层面
  • 权限提升与范围蔓延 (MCP02)
  • 认证逻辑绕过 - 网络请求可触发

排除条件

  • 测试代码中的模拟认证
  • 开发环境临时凭据
  • 遵循安全最佳实践的实现
  • 仅限本地利用的认证问题:需要本地访问才能触发的漏洞

命令注入检测模式

深度分析潜在的代码注入漏洞,对应 OWASP MCP05 (Command Injection & Execution)。

检测方法

  • 静态追踪:从网络/接口层输入源到危险函数调用(如 os.system, subprocess.run, eval)的完整路径追踪
  • 上下文理解:分析输入过滤和验证机制
  • 漏洞确认:区分真实漏洞与误报

高风险模式(仅限网络可达输入)

  • API 请求参数直接拼接到命令
  • WebSocket/SSE 消息未过滤传递
  • HTTP 请求体内容动态构建命令
  • 模板注入漏洞(网络可控模板变量)

排除条件

  • 命令行参数传入:CLI 参数直接传递给系统命令(本地执行场景,无远程利用价值)
  • 交互式输入:终端 stdin 读取的用户输入
  • 本地配置文件:从本地配置读取并执行的命令

凭据窃取检测模式

检测恶意凭据获取和泄露行为,对应 OWASP MCP01 (Token Mismanagement & Secret Exposure)。

检测标准(必须同时满足)

  • 敏感凭据访问:明确访问敏感文件(如 .env, .cursor/mcp.json)或环境变量
  • 网络外传:静态代码中存在将凭据通过网络接口(HTTP、WebSocket、Socket等)发送至外部服务器的逻辑
  • 攻击可行性验证:基于静态逻辑推导攻击的可行性

排除条件

  • 正常业务场景的配置读取
  • 使用官方 SDK 的标准认证流程
  • 测试和示例代码
  • 仅写入本地日志:凭据写入本地日志文件但无网络传输路径(降级为低危,不报告)
  • 仅终端输出:凭据打印到 stdout/stderr 但无网络传输

硬编码API密钥检测模式

评估硬编码凭据的真实安全风险 (MCP01)。

风险评估标准(仅报告中危及以上)

  • 关键风险(报告):真实 API 密钥、生产服务凭据,且存在网络泄露路径
  • 中等风险(报告):配置文件中的 API 密钥,且代码中有网络传输逻辑
  • 低风险/误报(不报告):测试凭据、占位符值、仅本地使用的密钥

上下文分析

  • 文件上下文评估(生产代码 vs 测试代码)
  • 代码使用场景分析
  • 网络暴露评估:密钥是否可能通过网络接口泄露

间接提示注入检测模式

检测通过外部数据源进行的 AI 提示注入攻击,对应 OWASP MCP06 (Prompt Injection via Contextual Payloads)。

Read the full file on GitHub · 186 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 186 lines · 0 tokens per session scan A a9936fc5d9c1

Subscribe to this mod's changes

code_audit is an agent published in the GitHub repository Tencent/AI-Infra-Guard (6,103 stars, last pushed yesterday), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 2,720 tokens. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other agents, from other repositories