Security Code Review logo

Security Code Review

Organization
Ascend
security-code-review

多语言安全代码审查 (Security Code Review)。对 Python、C++、Shell、Markdown 文件进行系统性安全漏洞检测与修复指导。覆盖 OWASP Top 10、CWE Top 25、CERT 安全编码标准。当用户提及以下内容时,务必使用此技能:安全审查、安全代码审查、security review、code review 中的安全检查、漏洞扫描、安全合规检查(CWE/CERT/OWASP)、编写安全代码、检查代码安全性、推理服务安全审计、多模态 Token 安全校验、JSON 嵌套深度攻击防护。即使用户没有明确说'安全审查',只要涉及代码安全性评估、漏洞检测、安全最佳实践,都应触发此技能。

Overview

PublisherAscend
Repositoryagent-skills
Skill namesecurity-code-review
Stars
54
Forks
4
Bundled files
5
LicenseMulanPSL-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by Ascend on GitHub. Read the source before you install it.

Installation

Install the Security Code Review AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Ascend/agent-skills/tree/master/skills/security-code-review
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Ascend/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/security-code-review .claude/skills/security-code-review
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Security Code Review in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Security Code Review on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Security Code Review is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

多语言安全代码审查 (Security Code Review)

适用场景

  • 安全审查: 对 Python、C++、Shell、Markdown 文件进行安全代码审查
  • Code Review: 在代码评审中检查安全漏洞
  • 新代码编写: 编写安全的代码,避免常见漏洞
  • 合规检查: 满足安全合规要求 (CWE, CERT, OWASP)
  • CI/CD 集成: 在流水线中集成安全扫描工具

审查工作流程

执行安全审查时,按以下步骤进行:

  1. 确定审查范围:识别目标代码的语言类型(Python/C++/Shell/Markdown)
  2. 加载对应参考:根据语言读取 references/ 下的详细审查指南
  3. 逐项检查:按照下方各语言的审查要点和检查清单执行
  4. 查阅历史经验:对于推理服务相关代码,读取 references/lessons-learned.md 排查已知问题模式
  5. 生成审查报告:按照本文件末尾的输出规范生成 CSV 报告

Python 安全审查

详细代码示例和安全/不安全对比:读取 references/python.md

审查覆盖的 10 个关键领域:

#领域核心风险关键搜索模式
1代码注入任意代码执行eval(, exec(, shell=True
2SQL 注入数据泄露/篡改f"SELECT, cursor.execute(f"
3反序列化RCEpickle.loads, yaml.load( (无 safe_load)
4路径遍历任意文件读取os.path.join( + 用户输入, 无 realpath 校验
5敏感信息泄露密钥暴露硬编码 API_KEY=, PASSWORD=, logger.*(password
6assert 误用权限绕过assert user.is_admin, assert.*auth
7临时文件竞态/符号链接攻击open("/tmp/ (未用 tempfile)
8ReDoSCPU 耗尽(a+)+, (.*)*, 嵌套量词
9JSON 嵌套深度栈溢出/资源耗尽json.loads( 无深度限制 (CWE-674, CWE-400)
10特殊 Token 注入进程崩溃/DoSnp.where(np.equal(input_ids, 无配对校验 (CWE-129, CWE-248)

Python 安全工具:

工具用途命令
bandit静态安全分析bandit -r src/
pip-audit依赖漏洞扫描pip-audit
pylint代码质量 + 部分安全规则pylint src/
mypy类型检查,防止类型混淆mypy src/
semgrep自定义安全规则semgrep --config=p/python

C++ 安全审查

详细代码示例和安全/不安全对比:读取 references/cpp.md

审查覆盖的 11 个关键领域:

#领域核心风险关键搜索模式
1缓冲区溢出代码执行strcpy(, sprintf(, gets(
2内存管理UAF/Double-freenew/delete (非智能指针), raw pointer
3整数溢出缓冲区分配错误new char[size] 无范围检查
4格式化字符串内存读写printf(user_input), fprintf(stderr, var)
5未初始化变量未定义行为声明后未赋值即使用
6RAII/资源泄漏资源耗尽fopen/fclose, mutex.lock()/.unlock()
7线程安全数据竞争非 atomic 跨线程变量, 无锁共享数据
8类型转换类型混淆C 风格强转 (Type*)ptr, 尤其是向下转型
9JSON 嵌套深度栈溢出nlohmann::json::parse( 无深度限制 (CWE-674)
10服务资源上限OOM配置参数组合峰值内存超物理内存 (CWE-400, CWE-770)
11特殊 Token 注入段错误/崩溃Token 配对假设, 固定偏移访问 (CWE-129, CWE-248)

C++ 安全工具:

工具用途命令/用法
AddressSanitizer内存错误检测-fsanitize=address
ThreadSanitizer数据竞争检测-fsanitize=thread
UBSanitizer未定义行为检测-fsanitize=undefined
Valgrind内存泄漏检测valgrind --leak-check=full ./app
cppcheck静态分析cppcheck --enable=all src/
clang-tidyLinter + 安全规则clang-tidy -checks='*' src/*.cpp
Coverity企业级静态分析CI 集成

Shell 安全审查

详细代码示例和安全/不安全对比:读取 references/shell.md

审查覆盖的 8 个关键领域:

#领域核心风险关键搜索模式
1脚本头部静默失败缺少 set -euo pipefail
2变量引用命令注入/误删$var (未用 "$var")
3命令注入任意命令执行eval "$user_input"
4临时文件竞态条件> /tmp/fixed_name (未用 mktemp)
5权限未授权访问chmod 777, chmod 666
6PATH 安全路径劫持关键命令未用绝对路径
7信号处理资源泄漏缺少 trap cleanup EXIT
8输入验证路径遍历未校验的 $filename 直接 cat

Shell 安全工具:

工具用途命令
ShellCheckShell 脚本静态分析shellcheck script.sh
shfmtShell 格式化shfmt -d script.sh

Markdown 安全审查

详细代码示例和安全/不安全对比:读取 references/markdown.md

审查覆盖的 4 个关键领域:

#领域核心风险关键搜索模式
1XSS 注入脚本执行<script>, <iframe>, onerror=, onmouseover=
2链接安全XSS/钓鱼javascript:, data:, vbscript:
3敏感信息密钥泄露sk-, ghp_, AKIA, 内部 IP/URL
4图片安全追踪/DoS外部追踪像素, 超大图片

历史安全问题经验库

完整案例分析和排查清单:读取 references/lessons-learned.md

审查推理服务引擎代码时,重点排查以下已知问题模式:

编号问题严重级别核心教训
SEC-EXP-001配置参数组合导致 OOMCRITICAL峰值内存 = maxReqs × bodyLimit × JSON放大系数,各参数独立合理但组合后超出物理内存
SEC-EXP-002<|begin_of_image|> 无 <|end_of_image|> 导致 DoSCRITICAL假设特殊 Token 成对出现,未校验即用硬索引访问
SEC-EXP-003<|vision_start|><|video_pad|><|vision_end|> 打破格式假设CRITICAL假设 Token 序列遵循私有协议格式,用固定偏移取值导致越界

通用安全约束 (Constraints)

必须遵守 (MUST)

  1. 输入验证: 验证所有外部输入,永远不信任用户数据
  2. 参数化查询: 使用参数化查询防止注入攻击
  3. 最小权限: 进程、文件、用户使用最小必要权限
  4. 安全默认值: 变量初始化、错误处理使用安全的默认值
  5. 依赖审计: 定期扫描依赖中的已知漏洞
  6. 敏感信息保护: 密钥、密码、Token 通过环境变量管理
  7. 日志脱敏: 日志中不记录密码、密钥等敏感信息
  8. 错误处理: 错误消息不泄露内部实现细节
  9. JSON 嵌套深度校验: 对所有外部 JSON 请求在解析前/解析时校验嵌套深度,防止栈溢出和资源耗尽攻击 (CWE-674, CWE-400)
  10. 服务化请求资源上限校验: 服务配置参数(最大并发数、请求体上限、请求头上限等)组合后的峰值内存必须小于部署环境可用内存;需考虑 JSON/XML 等反序列化库的内存放大系数 (CWE-400, CWE-770)
  11. 特殊 Token 输入校验: 多模态/多轮对话等场景中的特殊 Token(如 begin/end_of_image、vision_start/end 等)必须校验配对完整性和序列格式合法性;禁止对 Token 序列做隐式格式假设;框架层必须兜底捕获 IndexError/out_of_range 防止进程崩溃 (CWE-129, CWE-248, CWE-20)

禁止事项 (MUST NOT)

  1. 禁止 eval 类函数: Python eval()/exec()、Shell eval、C++ 无等价物但禁止动态代码生成
  2. 禁止硬编码密钥: 不在代码中硬编码密码、API Key、Token
  3. 禁止提交敏感文件: .env、私钥、证书不得提交到版本控制
  4. 禁止忽略错误: 不得静默吞掉异常或忽略返回值
  5. 禁止过宽权限: 不使用 chmod 777、0.0.0.0 无限制监听
  6. 禁止使用已弃用的不安全函数: gets(), sprintf(), strcpy() 等

安全审查检查清单 (Checklist)

Python

- [ ] 无 eval()/exec() 使用不受信任的输入
- [ ] 无 pickle.loads() 加载不受信任的数据
- [ ] 使用 yaml.safe_load() 替代 yaml.load()
- [ ] subprocess 调用不使用 shell=True
- [ ] SQL 查询使用参数化方式
- [ ] 文件路径操作有路径遍历防护
- [ ] 无硬编码的密钥/密码
- [ ] 日志不记录敏感信息
- [ ] 未使用 assert 进行安全/权限相关检查
- [ ] 依赖已通过 pip-audit/bandit 扫描
- [ ] 正则表达式无 ReDoS 风险
- [ ] 临时文件使用 tempfile 模块
- [ ] JSON 请求解析入口有嵌套深度限制(建议 ≤ 32 层)
- [ ] 递归遍历 JSON 数据结构有深度保护
- [ ] 多模态特殊 Token(begin/end_of_image、vision_start/end 等)校验了配对完整性,不假设成对出现
- [ ] 推理请求处理路径有框架层 IndexError/ValueError/KeyError 兜底捕获,防止单请求异常导致进程崩溃

C++

- [ ] 无缓冲区溢出风险 (strcpy → strncpy/std::string)
- [ ] 使用智能指针管理内存
- [ ] 无 use-after-free / double-free
- [ ] 整数运算有溢出检查
- [ ] printf 系列函数使用固定格式字符串
- [ ] 所有变量在使用前初始化
- [ ] 资源管理遵循 RAII 原则
- [ ] 多线程代码无数据竞争
- [ ] 使用 C++ 风格类型转换 (static_cast/dynamic_cast)
- [ ] 编译启用安全选项 (-Wall -Werror -fsanitize=address)
- [ ] JSON 请求解析入口有嵌套深度限制(建议 ≤ 32 层)
- [ ] 递归遍历 JSON 数据结构有深度参数并设上限
- [ ] 服务配置参数组合后峰值内存不超过部署环境可用内存(考虑 JSON 放大系数)
- [ ] 存在运行时内存水位监控或请求准入控制机制
- [ ] 多模态特殊 Token(boi/eoi、vision_start/end 等)校验了配对完整性和序列格式,不做隐式格式假设
- [ ] model forward / pre-processing 路径有框架层 std::out_of_range/std::invalid_argument 兜底 catch,防止进程崩溃

Shell

- [ ] 脚本使用 set -euo pipefail
- [ ] 所有变量使用双引号包裹 ("$var")
- [ ] 无 eval 使用用户输入
- [ ] 临时文件使用 mktemp
- [ ] 文件权限不超过 755(脚本)/ 644(配置)
- [ ] 关键命令使用绝对路径
- [ ] 有 trap 清理机制
- [ ] 输入经过验证和过滤
- [ ] 通过 ShellCheck 无警告
- [ ] 不使用 . 或空目录在 PATH 中

Markdown

- [ ] 无内嵌 <script>/<iframe> 标签
- [ ] 无 javascript:/data: 协议链接
- [ ] 无硬编码密钥/密码/Token
- [ ] 无内部 IP 地址或内部 URL 泄露
- [ ] 外部图片来源可信
- [ ] 无追踪像素

推荐工具汇总

语言工具类型说明
Pythonbandit静态分析Python 安全漏洞检测
Pythonpip-audit依赖扫描Python 依赖漏洞检查
Pythonsemgrep规则引擎自定义安全规则匹配
Pythonmypy类型检查类型安全,防止类型混淆
C++AddressSanitizer运行时检测内存错误检测
C++ThreadSanitizer运行时检测数据竞争检测
C++cppcheck静态分析C/C++ 静态分析
C++clang-tidyLinter代码质量 + 安全规则
C++Valgrind运行时检测内存泄漏检测
ShellShellCheck静态分析Shell 脚本安全分析
通用git-secrets预提交钩子防止提交密钥
通用trufflehog密钥扫描扫描代码中的密钥
通用gitleaks密钥扫描Git 仓库密钥泄露检测
MarkdownmarkdownlintLinterMarkdown 格式检查

参考标准


审查结果输出 (Output)

审查流程要求

当使用此 Skill 对代码仓库执行安全审查(即参数包含 review 关键字)时,完成所有审查后自动将结果保存为 CSV 文件。这是审查流程的最终必要步骤。

CSV 输出规范

文件名: security_code_review_report.csv 保存位置: 被审查的代码仓库根目录下(即 review <path> 中的 <path> 下) 编码: UTF-8

CSV 必须包含以下 9 列(表头固定):

csv
编号,严重级别,漏洞类别,语言,文件路径,行号,问题描述,风险说明,建议修复方案
列名说明示例值
编号唯一编号,格式为 严重级别首字母-序号C-01, H-05, M-12, L-03
严重级别四级:CRITICAL / HIGH / MEDIUM / LOWCRITICAL
漏洞类别安全漏洞分类名称命令注入, 不安全反序列化, 线程安全, 路径遍历
语言代码语言/文件类型Python, C++, Shell, Markdown, Docker, Config
文件路径相对于仓库根目录的文件路径src/utils/file_utils.py
行号问题代码所在行号,多行用逗号分隔79, 40-44, 220-232
问题描述简明扼要描述发现的问题pickle.loads() 反序列化来自共享内存的数据
风险说明说明该问题可能导致的安全风险攻击者可注入恶意 pickle payload 实现 RCE
建议修复方案具体的修复建议和代码示例用 json.loads() 替代 pickle.loads()

CSV 格式要求

  1. 逗号分隔,含逗号的字段值用双引号包裹
  2. 字段值内部的双引号用两个双引号转义("")
  3. 第一行为表头行,之后每行一条发现
  4. 按严重级别排序:CRITICAL → HIGH → MEDIUM → LOW
  5. 同级别内按编号顺序排列
  6. 文件路径使用相对路径(相对于仓库根目录)

输出流程

审查完成后执行以下步骤:

  1. 汇总所有发现:收集所有审查代理/扫描的结果
  2. 去重合并:合并重复发现,确保每条记录唯一
  3. 生成 CSV:按上述规范生成 CSV 文件并写入目标路径
  4. 验证 CSV:用 Python csv 模块验证文件格式正确、行数与发现数一致
  5. 输出摘要:向用户报告文件位置和各严重级别的统计数量

示例输出

csv
编号,严重级别,漏洞类别,语言,文件路径,行号,问题描述,风险说明,建议修复方案
C-01,CRITICAL,不安全反序列化,Python,src/utils/share_memory.py,79,"pickle.loads() 反序列化来自共享内存的数据","攻击者可注入恶意 pickle payload 实现 RCE","用 json.loads() 替代 pickle.loads()"
H-01,HIGH,命令注入,Shell,scripts/run.sh,52,"eval 执行含用户输入的命令字符串","模型路径含 shell 元字符时可注入任意命令","改用 bash 数组构建命令, 消除 eval"
M-01,MEDIUM,线程安全,C++,src/thread_pool.h,45,"m_shutdown 为非原子 bool 跨线程读写","数据竞争导致工作线程可能无法退出","改为 std::atomic<bool>"
L-01,LOW,临时文件安全,Python,tests/test_utils.py,30,"硬编码 /tmp 路径","共享 CI 环境中符号链接攻击风险","使用 tempfile.mkdtemp()"

注意事项

  • 即使审查未发现任何问题,也应生成 CSV 文件(仅含表头行),并向用户说明"未发现安全问题"
  • CSV 文件用于人工审核,描述必须清晰具体,避免模糊表述
  • 如果审查仅针对特定文件而非整个仓库,CSV 保存到该文件所在目录
  • 生成 CSV 后用 Python 脚本验证格式,确保可被 Excel/WPS 正确打开

Metadata

  • Version: 2.0.0
  • Last updated: 2026-04-24
  • Languages: Python, C++, Shell/Bash, Markdown
  • Tags: #security #code-review #python #cpp #shell #markdown #OWASP #CWE

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Security Code Review AI skill do?

多语言安全代码审查 (Security Code Review)。对 Python、C++、Shell、Markdown 文件进行系统性安全漏洞检测与修复指导。覆盖 OWASP Top 10、CWE Top 25、CERT 安全编码标准。当用户提及以下内容时,务必使用此技能:安全审查、安全代码审查、security review、code review 中的安全检查、漏洞扫描、安全合规检查(CWE/CERT/OWASP)、编写安全代码、检查代码安全性、推理服务安全审计、多模态 Token 安全校验、JSON 嵌套深度攻击防护。即使用户没有明确说'安全审查',只要涉及代码安全性评估、漏洞检测、安全最佳实践,都应触发此技能。

Why use Security Code Review on TypingMind?

Because you install it once and use it with any model. Security Code Review is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Security Code Review in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Ascend/agent-skills/tree/master/skills/security-code-review. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Security Code Review?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Security Code Review?

As many as you like. As long as a model supports skills, you can use Security Code Review with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Security Code Review AI skill free?

Yes. It is published on GitHub by Ascend under the MulanPSL-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇