post-patch-validation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePost-Patch Validation
补丁后验证
Validate a security patch against the reported bug and the surrounding code it affects. Give the
patch author reproducible failures to fix and identify what still needs testing. Apply the same
checks to human and agent patches. The diff, author, upstream implementation, and original proof
of concept alone cannot establish correctness.
针对上报的漏洞及其影响的周边代码验证安全补丁。为补丁作者提供可复现的失败用例以进行修复,并明确仍需测试的内容。对人工编写和Agent生成的补丁采用相同的检查标准。仅靠diff、作者信息、上游实现和原始概念验证(PoC)无法证明补丁的正确性。
When to Use
适用场景
- A security fix, remediation commit, patch file, or pull request already exists.
- An AI-generated patch needs validation before human review or merge.
- A fix may cover one exploit path while missing variants of the same root cause.
- A security fix may alter legitimate behavior or introduce a new vulnerability.
- A patch author needs concrete failures and coverage gaps before another revision.
- 已有安全修复方案、修复提交、补丁文件或Pull Request。
- AI生成的补丁需要在人工审核或合并前进行验证。
- 修复方案可能只覆盖了一条漏洞利用路径,却遗漏了同一根因的其他变体。
- 安全修复可能改变合法行为或引入新的漏洞。
- 补丁作者在进行下一轮修订前需要具体的失败用例和覆盖缺口。
When NOT to Use
不适用场景
- No patch exists yet; use vulnerability discovery or fix implementation first.
- The task is to review an audit finding against a report without executing patch evidence.
- The task is only to convert a finding into a permanent project test.
- The target is remote or production. This skill executes local code and tests only.
- The user has not authorized execution of the repository's code or test suite.
- 尚无补丁;应先进行漏洞发现或修复实现。
- 任务是对照报告审核审计发现,无需执行补丁验证证据。
- 任务仅为将某个发现转化为项目的永久测试用例。
- 目标是远程环境或生产环境。本技能仅执行本地代码和测试。
- 用户未授权执行代码仓库的代码或测试套件。
Quick Start
快速开始
-
Pin the vulnerable base and patched input. Prefer immutable commits. For uncommitted work, create a binary patch file first; do not validate in the user's working tree.
-
Scaffold a pinned plan:bash
uv run {baseDir}/scripts/post_patch_validation.py scaffold \ --repo . \ --base-ref <vulnerable-ref> \ --patched-ref <patched-ref> \ --finding-id <stable-id> \ --finding-summary "<root cause and impact>" \ --evidence-level runtime \ --output post-patch-validation/plan.jsonUseinstead of--patch-file <path>for a patch artifact. Choose the highest honest evidence level:--patched-reffor source/patch invariants only,sourcewhen target code is compiled or analyzed but the reported behavior is not executed, orbuildwhen the checks execute the reported behavior and its safety assertions.runtime -
Inspect the finding, diff, callers, sibling paths, cleanup/error paths, and existing tests. Populatein the generated plan. Run
checksfor the structural schema:print-schemabashuv run {baseDir}/scripts/post_patch_validation.py print-schema -
Runfor the complete validation, including coverage, command restrictions, and pinned inputs, before executing code:
validate-planbashuv run {baseDir}/scripts/post_patch_validation.py validate-plan \ --plan post-patch-validation/plan.json -
Execute the evidence plan:bash
uv run {baseDir}/scripts/post_patch_validation.py run \ --plan post-patch-validation/plan.json \ --output post-patch-validation/results -
Report,
result.json, the evidence level, and the completereport.md. Return each finding to the patch author with its check ID, assertion, and saved logs. Identify each validation gap separately, including gaps that coexist with supported findings. After the author revises the patch, pin the new inputs and save a fresh validation run. Preserve the prior evidence. Passing supplied checks still requires human review before acceptance.assessment
-
固定存在漏洞的基线版本和补丁版本的输入。优先使用不可变的提交。对于未提交的工作,先创建二进制补丁文件;不要在用户的工作树中进行验证。
-
搭建固定计划:bash
uv run {baseDir}/scripts/post_patch_validation.py scaffold \ --repo . \ --base-ref <vulnerable-ref> \ --patched-ref <patched-ref> \ --finding-id <stable-id> \ --finding-summary "<root cause and impact>" \ --evidence-level runtime \ --output post-patch-validation/plan.json对于补丁工件,请使用代替--patch-file <path>。选择符合实际的最高证据级别:--patched-ref仅用于源码/补丁不变性检查;source用于目标代码已编译或分析但未执行上报的行为的场景;build用于检查会执行上报的行为及其安全断言的场景。runtime -
检查漏洞发现、diff、调用方、同级路径、清理/错误路径以及现有测试。在生成的计划中填充字段。运行
checks查看结构模式:print-schemabashuv run {baseDir}/scripts/post_patch_validation.py print-schema -
在执行代码前,运行进行完整验证,包括覆盖范围、命令限制和固定输入:
validate-planbashuv run {baseDir}/scripts/post_patch_validation.py validate-plan \ --plan post-patch-validation/plan.json -
执行证据计划:bash
uv run {baseDir}/scripts/post_patch_validation.py run \ --plan post-patch-validation/plan.json \ --output post-patch-validation/results -
上报、
result.json、证据级别以及完整的report.md结果。将每个发现连同其检查ID、断言和保存的日志返回给补丁作者。分别识别每个验证缺口,包括与已确认发现共存的缺口。作者修订补丁后,固定新的输入并保存新的验证运行结果。保留之前的证据。即使提供的检查全部通过,在接受补丁前仍需进行人工审核。assessment
Evidence Contract
证据契约
The runner rejects incomplete plans. Supply at least one check of every kind:
| Kind | Required observation |
|---|---|
| Benign harness succeeds on both base and patch |
| Original safety assertion fails on base and succeeds on patch |
| A distinct root-cause variant fails on base and succeeds on patch |
| Unaffected behavior succeeds with byte-identical selected output |
| Targeted non-security regression check succeeds on both revisions |
| Adjacent/new-vulnerability check succeeds on base and patch |
| Existing project suite, sanitizer, or deterministic fuzz campaign succeeds on patch |
Commands are argv arrays, never shell strings. Put complex setup in a checked-in or plan artifact
script and invoke it with . The runner fixes locale/timezone/hash-seed inputs, executes
checks in lexical ID order, records raw stdout/stderr, and never edits the original worktree.
Each check's defaults to 300 and accepts integers from 1 through 3600.
Exceeding the timeout leaves a validation gap. A timeout alone does not establish a regression.
Every plan also contains a sorted array ( when none). Scaffolding infers affected
Gitlinks from the changed-file inventory. The runner initializes those pinned commits from the
source repository's existing Git module objects, never from network URLs; initialize
or fetch them in the source repository before validation.
{plan_dir}timeout_secondssubmodules[].gitmodules运行器会拒绝不完整的计划。每类检查至少需提供一个:
| 类型 | 所需观测结果 |
|---|---|
| 良性测试套件在基线版本和补丁版本上均运行成功 |
| 原始安全断言在基线版本上失败,在补丁版本上成功 |
| 不同的根因变体在基线版本上失败,在补丁版本上成功 |
| 未受影响的行为运行成功,且选定输出字节完全一致 |
| 针对性的非安全回归检查在两个版本上均运行成功 |
| 相邻/新漏洞检查在基线版本和补丁版本上均运行成功 |
| 现有项目测试套件、sanitizer或确定性模糊测试活动在补丁版本上运行成功 |
命令为argv数组,绝对不能是shell字符串。将复杂的设置放在已提交的或计划工件脚本中,并通过调用。运行器会固定区域设置/时区/哈希种子输入,按ID字典顺序执行检查,记录原始stdout/stderr,且绝不会修改原始工作树。每个检查的默认值为300,可接受1到3600之间的整数。超时会导致验证缺口。仅超时本身不能证明存在回归问题。每个计划还包含一个排序后的数组(无子模块时为)。脚手架会根据变更文件清单推断受影响的Gitlink。运行器会从源仓库的现有Git模块对象中初始化这些固定提交,绝不会从的网络URL初始化;请在验证前在源仓库中初始化或获取这些子模块。
{plan_dir}timeout_secondssubmodules[].gitmodulesExploit and variant checks must prove they ran
漏洞利用和变体检查必须证明其已运行
A nonzero exit does not mean the vulnerability reproduced. An import error, a failed build, a
missing dependency, and a failed safety assertion all exit nonzero and are indistinguishable to the
runner. Every and check must print and flush immediately
before it evaluates its assertion, on both revisions:
exploitvariantPPV_REACHEDjson
"argv": ["python3", "-c", "import app; value = app.render('<'); print('PPV_REACHED', flush=True); assert value == '<'"]The token is also in the environment as . It must land on stdout, as a line
of its own. Stderr is not scanned, because a Python traceback echoes the offending
source and would otherwise satisfy the check for a harness that executed nothing. A run without it
leaves a gap. Independent findings from other checks remain in the result.
Flush explicitly: a harness whose payload segfaults or calls loses buffered output and forfeits its own evidence.
PPV_REACHED_MARKERSyntaxErrormarker_missing_exitThese checks also run side-blind. is not expanded for them, is absent from
their environment, the checkout directory is randomly named, and the plan validator rejects any
or check whose or mentions either. An assertion that can see which
revision it is on can assert on that instead of on the code, which is the cheapest possible way
to fake a reproduction followed by a fix.
{side}PPV_SIDEexploitvariantargvenv非零退出码并不意味着漏洞已复现。导入错误、构建失败、依赖缺失和安全断言失败都会导致非零退出,运行器无法区分这些情况。每个和检查在两个版本上评估其断言之前,都必须立即打印并刷新:
exploitvariantPPV_REACHEDjson
"argv": ["python3", "-c", "import app; value = app.render('<'); print('PPV_REACHED', flush=True); assert value == '<'"]该标记也以的形式存在于环境变量中。它必须作为单独的一行出现在stdout中。运行器不会扫描stderr,因为Python的回溯会输出有问题的源码,否则对于什么都没执行的测试套件来说,这也会满足检查要求。没有该标记的运行会留下缺口。其他检查的独立发现仍会保留在结果中。请显式刷新输出:如果测试套件的有效负载发生段错误或调用,会丢失缓冲的输出,从而丧失自身的证据效力。
PPV_REACHED_MARKERSyntaxErrormarker_missing_exit这些检查还以**side-blind(侧盲)**模式运行。不会为它们展开变量,环境中也不存在,检出目录是随机命名的,并且计划验证器会拒绝任何在或中提及这两者的或检查。如果断言能够知道自己运行在哪个版本上,它就可以针对版本而非代码进行断言,这是伪造“漏洞复现后被修复”的最廉价方式。
{side}PPV_SIDEargvenvexploitvariantEnvironment
环境
Checks run under a fixed minimal environment: , , and a handful of temp/user keys,
plus /, , , , . Everything else in
the caller's environment is dropped. Toolchains that need more get it explicitly:
PATHHOMELANGLC_ALL=CTZ=UTCPYTHONHASHSEED=0NO_COLORTERM=dumbbash
uv run {baseDir}/scripts/post_patch_validation.py run \
--plan post-patch-validation/plan.json \
--output post-patch-validation/results \
--allow-env JAVA_HOME --allow-env CARGO_HOMEForwarded names and values are recorded in . A requested variable that is unset is an
error, not an empty string. Two classes are refused outright: names that read as credentials
(, , , …), because the value would be written into the result; and
names that change what executes (, , , , …),
because those variables can change which code executes.
The runner's fixed variables and every name are also reserved and cannot be forwarded.
result.json*SECRET**TOKEN**API_KEY*LD_PRELOADBASH_ENVNODE_OPTIONSGIT_SSH_COMMANDPPV_*Placeholders expanded in and per-check values: (the revision under test),
(an isolated copy of the plan artifacts for that one invocation), (a
fresh opaque directory for that one check invocation), and
( or , and not available to / checks). The same values
arrive as , , , , and . Write only
under ; the evidence directory path is not passed to checks. Base and patched invocations
do not share runner-managed scratch, plan, or worktree roots. After each invocation exits, its
scratch tree is archived under the deterministic path, its
private plan copy is discarded, and every readable argv element that resolves to a file is hashed
in . Files inside the isolated plan or checkout roots are additionally retained under
up to 16 MiB; the record explains why any other file was not archived.
Use a dedicated directory for : its sibling files and directories are copied into each
invocation's . Keep helper code under that directory's directory or checked
into the target repository so its bytes are reviewable. The machine plan containing commit pins,
the current output directory, and detected prior result trees are excluded; symlinks are rejected.
The clean snapshot remains only in runner memory, and
exploit/variant sides execute in random order while evidence filenames remain deterministic.
Stdout/stderr use anonymous or randomly named capture descriptors and are copied to the named
evidence files only after the child exits, so fd inspection cannot disclose the side label.
argvenv{checkout}{plan_dir}{scratch}{side}basepatchedexploitvariantPPV_CHECKOUTPPV_PLAN_DIRPPV_SCRATCHPPV_SIDEPPV_CASE_ID{scratch}results/scratch/<check-id-and-side>argv_filesresults/helpers/<sha256>plan.json{plan_dir}checks/This isolation is not a host sandbox: checks run with the caller's privileges and a malicious
helper could use arbitrary external state or deliberately infer the revision from source or Git
metadata. Inspect the content-addressed helper artifacts, and use an OS/container sandbox when the
check code itself is untrusted.
Active validation worktrees are Git-locked with random owner tokens backed by kernel file locks, so
another concurrent validator cannot prune them and PID reuse cannot impersonate an owner. If the
runner is forcibly killed, the next run unlocks stale validator-owned registrations. For manual
recovery, inspect , then use and
(or after the path is gone).
git worktree listgit worktree unlock <path>git worktree remove --force <path>git worktree pruneRead evidence-model.md when designing coverage, selecting
variants, or interpreting findings and validation gaps. Do not read it for routine CLI execution.
检查在固定的最小环境下运行:、、少量临时/用户密钥,以及/、、、、。调用方环境中的其他所有变量都会被丢弃。需要更多环境变量的工具链需显式指定:
PATHHOMELANGLC_ALL=CTZ=UTCPYTHONHASHSEED=0NO_COLORTERM=dumbbash
uv run {baseDir}/scripts/post_patch_validation.py run \
--plan post-patch-validation/plan.json \
--output post-patch-validation/results \
--allow-env JAVA_HOME --allow-env CARGO_HOME转发的变量名和值会记录在中。请求的变量若未设置会视为错误,而非空字符串。两类变量会被直接拒绝:一类是看起来像凭证的变量名(、、等),因为其值会被写入结果;另一类是会改变执行内容的变量名(、、、等),因为这些变量会改变执行的代码。运行器的固定变量以及所有格式的变量名也都是保留的,不能转发。
result.json*SECRET**TOKEN**API_KEY*LD_PRELOADBASH_ENVNODE_OPTIONSGIT_SSH_COMMANDPPV_*在和每个检查的值中展开的占位符包括:(被测版本)、(本次调用使用的计划工件的隔离副本)、(本次检查调用使用的全新不透明目录)以及(或,/检查不可用)。这些值也以、、、和的形式提供。仅可在目录下写入内容;证据目录路径不会传递给检查。基线版本和补丁版本的调用不会共享运行器管理的临时目录、计划或工作树根目录。每次调用退出后,其临时目录树会被归档到确定性路径下,私有计划副本会被丢弃,且每个可解析为文件的可读argv元素都会在中进行哈希计算。隔离的计划或检出根目录下的文件还会被保留在下,最大不超过16 MiB;记录中会说明其他文件未被归档的原因。请为使用专用目录:其同级文件和目录会被复制到每次调用的中。将辅助代码放在该目录的目录下,或提交到目标仓库中,以便其内容可被审核。包含提交固定信息、当前输出目录和检测到的先前结果树的机器计划会被排除;符号链接会被拒绝。干净的快照仅保留在运行器内存中,漏洞利用/变体的两侧(基线和补丁)以随机顺序执行,而证据文件名保持确定性。Stdout/stderr使用匿名或随机命名的捕获描述符,仅在子进程退出后才复制到命名的证据文件中,因此通过fd检查无法泄露侧标签。
argvenv{checkout}{plan_dir}{scratch}{side}basepatchedexploitvariantPPV_CHECKOUTPPV_PLAN_DIRPPV_SCRATCHPPV_SIDEPPV_CASE_ID{scratch}results/scratch/<check-id-and-side>argv_filesresults/helpers/<sha256>plan.json{plan_dir}checks/这种隔离并非主机沙箱:检查以调用方的权限运行,恶意的辅助代码可能利用任意外部状态,或故意从源码或Git元数据中推断出版本。请检查内容寻址的辅助工件,当检查代码本身不可信时,请使用操作系统/容器沙箱。
活动的验证工作树会通过内核文件锁支持的随机所有者令牌进行Git锁定,因此其他并发的验证器无法清理它们,PID复用也无法冒充所有者。如果运行器被强制杀死,下一次运行会解锁验证器拥有的过期注册。手动恢复时,请检查,然后使用和(或在路径删除后使用)。
git worktree listgit worktree unlock <path>git worktree remove --force <path>git worktree prune在设计覆盖范围、选择变体或解释发现和验证缺口时,请阅读evidence-model.md。常规CLI执行无需阅读该文档。
Coverage Rules
覆盖规则
- Derive variants from the root cause, not cosmetic mutations of the original payload.
- Enumerate sibling call sites, alternate callbacks/outputs, error paths, teardown, ownership, serialization, and boundary values touched by the fix.
- Make each exploit or variant test assert the safe behavior. It must fail on the vulnerable base; a test that passes on both revisions proves nothing about remediation. Read the base-side stderr and confirm the failure is the assertion you wrote, not a harness that never got there.
- Keep exploit and variant assertions limited to the security invariant. Test liveness, exact
error types/messages, timing, and compatibility separately as or
behaviorchecks; otherwise an unrelated contract change can masquerade as proof that the vulnerability remains.regression - Keep the harness benign and make it exercise the changed component. It establishes that the harness works on both revisions. Failed controls leave gaps and prevent attributing other failures to the patch. The raw observations remain available for review.
control - Use only for behavior that should remain unchanged. Exact output comparison is deliberate; move unstable values behind a deterministic test harness instead of normalizing them away in prose.
behavior - Make checks pass on the vulnerable base before treating a patched failure as newly introduced. A failed baseline leaves attribution unresolved.
security - Do not edit the patch during validation. Return failures to the patch author and start a new, freshly pinned run.
- 变体应从根因推导而来,而非对原始有效负载进行表面上的修改。
- 枚举修复涉及的同级调用点、备用回调/输出、错误路径、销毁流程、所有权、序列化和边界值。
- 每个漏洞利用或变体测试都应断言安全行为。它必须在存在漏洞的基线版本上失败;在两个版本上都通过的测试无法证明修复有效。请查看基线版本的stderr,确认失败是你编写的断言导致的,而非测试套件根本没执行到断言处。
- 将漏洞利用和变体的断言限制在安全不变量范围内。将活性、精确的错误类型/消息、时序和兼容性作为或
behavior检查单独测试;否则,不相关的契约变更可能会被伪装成漏洞仍然存在的证据。regression - 保持测试套件的良性,并让其测试被修改的组件。它用于证明测试套件在两个版本上都能正常工作。对照检查失败会留下缺口,且无法将其他失败归因于补丁。原始观测结果仍可用于审核。
control - 仅用于应保持不变的行为。精确的输出比较是有意为之的;请将不稳定的值放在确定性测试套件之后处理,而不是在文档中通过文字说明将其归一化。
behavior - 在将补丁版本上的失败视为新引入的问题之前,应确保检查在存在漏洞的基线版本上通过。基线版本失败会导致归因无法确定。
security - 验证过程中请勿修改补丁。将失败结果返回给补丁作者,并启动一次新的、重新固定输入的运行。
Reading the result
结果解读
result.jsonassessmentstatusfindingsgapshuman_review_requiredcompleteincompleteSuite checks run on the patched revision first. A completed failure triggers the same check on
baseline. If baseline passes, report the failure after the patch. If both fail, preserve both logs
and report that attribution is unresolved. Do not assume matching exit codes mean the same failure.
The runner exits 0 for complete checks with no findings, 1 for complete checks with findings,
10 for incomplete validation, and 64 for invalid inputs. Read the artifact even after exit 10:
it can contain supported findings alongside gaps. Source or build evidence cannot establish
runtime behavior. State the evidence level alongside any passing result.
result.jsonassessmentstatusfindingsgapshuman_review_requiredstatuscompletestatusincomplete套件检查首先在补丁版本上运行。如果完成后发现失败,会在基线版本上触发相同的检查。如果基线版本通过,则报告该失败是补丁引入的。如果两者都失败,则保留两个日志,并报告归因无法确定。不要假设相同的退出码意味着相同的失败。
运行器的退出码:0表示检查完成且无发现,1表示检查完成且有发现,10表示验证未完成,64表示输入无效。即使退出码为10也请查看工件:它可能在缺口之外包含已确认的发现。源码或构建级别的证据无法证明运行时行为。请在任何通过结果旁注明证据级别。
Claude Dynamic Workflow
Claude动态工作流
Claude Code exposes the bundled workflow as .
To pass structured inputs through the tool, use the name without a leading slash:
/post-patch-validation:validate-patchWorkflowjavascript
Workflow({
name: 'post-patch-validation:validate-patch',
args: {
finding: '<finding text or local path>',
baseRef: '<vulnerable-ref>',
patchRef: '<patched-ref>',
workdir: 'post-patch-validation',
},
})Use instead of when appropriate. The workflow uses fixed coverage
lenses to propose checks and a fixed executor to run this skill. Agents may author test
artifacts. The Python runner records findings and gaps, and reviewers report coverage or evidence
concerns separately. returns supported failures even when other checks left gaps.
means evidence is incomplete without a supported failure. Passing checks advance to
only after both evidence reviews approve, otherwise .
The workflow cannot ask questions after launch, so pass every input up front.
patchFilepatchRefNEEDS_REPAIRBLOCKEDREADY_FOR_HUMAN_REVIEWREVIEW_REQUIREDClaude Code将捆绑的工作流暴露为。要通过工具传递结构化输入,请使用不带前导斜杠的名称:
/post-patch-validation:validate-patchWorkflowjavascript
Workflow({
name: 'post-patch-validation:validate-patch',
args: {
finding: '<finding text or local path>',
baseRef: '<vulnerable-ref>',
patchRef: '<patched-ref>',
workdir: 'post-patch-validation',
},
})适当时使用代替。该工作流使用固定的覆盖视角来提出检查建议,并使用固定的执行器来运行本技能。Agent可以编写测试工件。Python运行器会记录发现和缺口,审核人员则单独报告覆盖范围或证据方面的问题。状态会返回已确认的失败,即使其他检查存在缺口。表示证据不完整,且没有已确认的失败。只有在两次证据审核都通过后,通过的检查才会进入状态,否则为。工作流启动后无法提问,因此请预先传递所有输入。
patchFilepatchRefNEEDS_REPAIRBLOCKEDREADY_FOR_HUMAN_REVIEWREVIEW_REQUIREDRationalizations to Reject
应驳回的常见理由
| Rationalization | Required response |
|---|---|
| "The original PoC no longer works" | Test at least one independent root-cause variant |
| "The exploit failed on base, so it reproduced" | Confirm the marker and that the failure is the assertion, not a broken harness |
| "The full suite passes" | Prove baseline reproduction and targeted behavior explicitly |
| "This matches the upstream/canonical patch" | Treat provenance as context, not evidence |
| "The diff is tiny" | Exercise callers, failure paths, and teardown affected by the change |
| "All supplied checks passed" | Preserve artifacts and require human review |
| "A flaky rerun passed" | Keep the first pinned result; fix nondeterminism before retrying |
| "There is no obvious variant" | Inspect sibling sites and boundaries; otherwise report the missing coverage |
| 理由 | 应给出的回应 |
|---|---|
| "原始PoC不再起作用了" | 至少测试一个独立的根因变体 |
| "漏洞利用在基线版本上失败了,所以已经复现了" | 确认标记存在,且失败是由断言导致的,而非测试套件损坏 |
| "完整测试套件都通过了" | 明确证明基线版本复现结果和针对性行为 |
| "这和上游/标准补丁一致" | 将来源视为背景信息,而非证据 |
| "这个diff很小" | 测试变更影响的调用方、失败路径和销毁流程 |
| "所有提供的检查都通过了" | 保留工件并要求人工审核 |
| "重新跑了一次就过了,是不稳定" | 保留第一次固定输入的结果;在重试前修复不确定性问题 |
| "没有明显的变体" | 检查同级位点和边界;否则报告覆盖缺口 |