xerj-security-audit
它能做什么
通过为代码库建立索引并检查每一处危险函数调用,来审查代码的安全问题,并留下显示搜索已完整进行的记录。适合需要可辩护审计、而非快速扫描的开发者和安全审查人员。
适用场景
- ✓当你想对 PHP 应用或插件进行安全审查,并留存完整覆盖的记录时。
- ✓当你需要列出代码库中的每一处危险调用时。
- ✓当你希望把发现记录在日后可以查询的台账中时。
技能链接
https://github.com/xerj-org/xerj/blob/main/docs/case-studies/wordpress-security-audit/skill/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请对这个 PHP 插件进行安全审查,并证明我们没有遗漏任何危险的函数调用。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能只对代码建立一次索引,映射已知的危险函数,并用语法树扫描找出每个调用点。它会用简单的文本搜索交叉核对结果,证明没有遗漏,然后把发现记录到可搜索的台账中。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
XERJ whitebox security audit
Run a security review where XERJ is the agent's second brain: index the code
once, then interrogate it — never load whole files. The deliverable is a
defensible coverage claim, not a vibe. Scripts referenced below live in
docs/case-studies/wordpress-security-audit/sink-census/ (copy them alongside
this skill to reuse in another repo).
When to use
- "Security-review this codebase / WordPress plugin / PHP app with coverage."
- "Find the dangerous calls / sinks and prove we didn't miss any."
- "Run the sink census / audit ledger."
Prerequisites (state them, then set up)
- XERJ running, ES-compatible, on
http://127.0.0.1:9200(xerj --insecure --data-dir ./data). pip install tree-sitter tree-sitter-php(+ the grammar for the target language).- The target source tree on disk.
The loop (do these in order; report honestly at each step)
1. Map the dangerous functions (knowledge)
Use php_dangerous_functions.json — 275 PHP built-ins/constructs across 28
categories (command/code exec, unserialize, include loaders, file r/w/delete,
SSRF, SQL drivers, XXE, callables, variable-injection, reflection, weak crypto/
random, type-juggling, …), each with vuln class + the taint-relevant argument.
For another framework/language, extend this map — it is data, not code.
2. Census every call site (AST)
python3 sink_census.py <src> parses every file with tree-sitter and records
2b. Census the dangerous PATTERNS (the class a sink list misses)
python3 pattern_census.py <src> AST-detects the non-function vulns — loose ==
/ magic-hash, non-strict in_array, strcmp-with-array (?login[]=), @
suppression, variable-variables, unsafe setcookie, switch-on-request,
Host-header trust, ORDER-BY injection — into wppatterns. Semantic classes a
census can't decide (SQL truncation, charset SQLi, second-order, phar, TOCTOU,
upload-exec, is_numeric bypass, regex-anchor, session-fixation, wrong-context
XSS) are catalogued in php_dangerous_patterns.json with detection guidance and
swept by reasoning. FULL REFERENCE: PHP-SECURITY-GUIDE.md — every function AND
pattern mapped to attack + detection + safe recipe.
every call site of a catalogued function (calls, methods, constructs like
echo/include/backtick, new ReflectionFunction). tree-sitter captures real
calls regardless of formatting/namespacing — grep cannot.
3. PROVE coverage (the guarantee — do not skip)
The census reconciles every grep occurrence against the AST, using AST string/comment/inline-HTML node ranges as the oracle. A clean run prints:
UNEXPLAINED: 0 => coverage PROVEN (0 gaps)
If UNEXPLAINED > 0, EVERY residual must be resolved (it is either a real call the extractor missed — fix the catalog/node-handling — or a proven non-call). Never report coverage while residuals are unexplained.
4. Index + triage (XERJ wpsinks)
The census bulk-indexes one doc per call site (file,line,fn,class,arg). Query
the risk profile; the rare high-value classes are the must-review set (in WP core:
RCE-command 11, deserialization 13, SQL 200, SSRF 107). You can now guarantee
you've seen every one.
5. AI-enrich into a ledger (enrich_pipeline.py)
For each high-risk site: read the arg + enclosing code, decide reachable
(request/cache/trusted/literal), guarded (which defense), severity, and a
verdict; write it back to wpsinks. This is the embedding-pipeline analogue,
but the enrichment is reasoned security judgement, and it accretes across runs.
Enrich 100% of the rare classes; queue the long tail.
5b. Trace any sink through the API (trace_sink.py <file> <line>)
Joins wpsinks -> wpaudit -> wpauthz -> reverse callers with NO local file
access: the sink + verdict, the enclosing function's sources/sinks/sanitizer, its
authz guards, and who calls it + whether they read a request source. The verdict
flags a SOURCE->SINK candidate when a source and an unsanitized sink coexist in a
function. (Reverse callers scan _source calls arrays because of the
array-term engine bug, and restrict common method names like load/query to
the same file to avoid class collision.)
6. Reason about the real bugs (the parts a census can't see)
Sink coverage ≠ total coverage. Also sweep, using the other detectors in the case
study: object-scoped authorization / IDOR (wp_authz_graph.py,
wp_checkuse_idor.py), validator completeness (wp_ssrf_ranges.py — an
incomplete
常见问题
覆盖率声明是什么意思?
语法扫描找到的每个危险调用,都会用简单的文本搜索进行交叉核对,因此审查结果不存在缺口。
它支持哪些语言?
PHP 是主要示例,其他语言需要各自的语法和函数映射。
它需要运行中的服务吗?
需要。它需要运行中的本地搜索节点,并安装 tree-sitter 解析包。
详情
作者的原始描述
Coverage-guaranteed whitebox security audit of a codebase using XERJ + tree-sitter AST. Use when the user wants to security-review PHP (or other-language) code with a provable "we enumerated every dangerous call" guarantee, or asks to run the WordPress-style sink census / audit. Drives an index-once, query-read-reason loop; proves zero gaps against grep; enriches findings into a queryable ledger.
repo: xerj-org/xerj
热度
- GitHub 星标
- 19k
- 排名
- #10503
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …