clawsweeper icon indicating copy to clipboard operation
clawsweeper copied to clipboard

Forged Real Behavior Proof heading in model prose flips a PR's proof verdict: first-match sectionValue reads attacker-echoed sections

Open yetval opened this issue 4 months ago • 1 comments

Summary

A contributor can get an unproven external PR routed into the automated repair lane by putting a fake ## Real Behavior Proof block in the PR body. When the review model echoes that text into the report summary, the report parser reads the forged block instead of the real one and the PR's proof verdict flips from blocked to sufficient.

Root cause

sectionValue in src/clawsweeper.ts is a single non-global regex match:

function sectionValue(markdown: string, heading: string): string {
  const match = markdown.match(
    new RegExp(`(?:^|\\n)## ${heading}\\n\\n([\\s\\S]*?)(?=\\n## |\\n?$)`),
  );
  return match?.[1]?.trim() ?? "";
}

The first \n## <heading>\n\n anywhere in the report wins. markdownFor emits ## Summary eleven sections before ## Real Behavior Proof, so any ## Real Behavior Proof block sitting inside the summary body is read first.

parseDecision sanitizes only two of its model-authored fields, systemContext and architectureDiagram (via neutralizeOwnedSectionSpoofing and sanitizeArchitectureDiagram). Every other prose field, including summary, is a raw requireString and reaches the durable report verbatim. So heading-shaped text that the review model quotes from an attacker-controlled PR body creates a section boundary that downstream parsers trust.

Impact chain

Once the forged section is read:

  1. reportRealBehaviorProof returns sufficient.
  2. The proof: sufficient label is applied.
  3. realBehaviorProofBlocksMerge returns false.
  4. derivedPrRating raises the proof tier.
  5. reviewAutomationMarkersFromReport emits clawsweeper-verdict:needs-changes plus clawsweeper-action:fix-required instead of clawsweeper-verdict:needs-human, which is what routes the unproven PR into the automated repair lane.

The forgery works bare, inside a code fence, inside <details>, and inside an HTML comment. The fence and wrapper variants matter because they show that "the injected text is visibly quoted" is not a defense; the parser operates on raw markdown.

Reproduction

Verified on origin/main at 6284161cdc, Linux, Node 24.18.0, no mocks: a driver imports the shipped dist/clawsweeper.js and calls the exported production entry points parseDecision, reviewAutomationMarkersFromReport, and renderReviewCommentFromReport with a model decision whose summary carries a forged proof block, while the genuine ## Real Behavior Proof section says Status: missing and front matter carries real_behavior_proof_status: missing, pr_rating_overall: F, work_candidate: queue_fix_pr.

Result for all four forgery shapes (bare, fenced, details, comment):

routing=clawsweeper-verdict:needs-changes clawsweeper-action:fix-required
proof_row=| **Proof confidence** | diamond lobster **(5/6)** | Sufficient (terminal): ...

Expected: clawsweeper-verdict:needs-human, no fix-required marker, and the proof row reporting the genuine missing status at 1/6.

Related surfaces found while confirming this

  • src/repair/workflow-utils.ts:2413 and src/repair/create-job.ts:276 each define the same first-match sectionValue parser over the same report artifact. Write-side escaping of new reports does not retroactively fix reports already published in openclaw/clawsweeper-state, which are re-read every sweep cycle, so these legacy readers need either bounded front matter reads or fail-closed handling when section content conflicts with front matter.
  • frontMatterValue (src/clawsweeper.ts:7763 on main) matches ^key: with the m flag rather than being bounded to the leading --- block, so a body line can satisfy a front matter lookup. Follow-up hardening.
  • src/repair/create-job.ts:249 reads a ClawSweeper Work Prompt section that no renderer emits; the report heading is Repair Work Prompt. Dead code path.
  • Per a Codex review finding on the fix branch: renderReportMarkdown writes selected label justification reasons verbatim into ## Label Justifications, which appears before the real review sections, so a heading-shaped label reason is another injection point into reviewSectionValue() consumers such as reportReviewFindings() and isRepairLoopPassReport().

Suggested fix shape

Extend the existing write-side defense (neutralizeOwnedSectionSpoofing, already load-bearing for extractMarkdownSection in src/repair/comment-router-core.ts) to every model-authored prose field that lands in a report section body, and make proof and rating readers prefer front matter over section text so already-published unescaped reports cannot flip verdicts. PR #835 implemented this shape with regression tests and before/after proof from the compiled production entry points; it is being closed in favor of this issue per the request to pause contributor PRs during stabilization, and the branch (yetval:fix/report-section-spoofing, head 7e6f81f27872) is available to take over or reference.

yetval avatar Jul 30 '26 05:07 yetval

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 2, 2026, 1:34 PM ET / 17:34 UTC.

Summary This issue remains necessary on current main: model-authored report prose is written verbatim into durable Markdown, while proof and rating readers still trust the first matching report section ahead of front-matter metadata. The related implementation attempt at https://github.com/openclaw/clawsweeper/pull/835 was closed unmerged, so it is useful design evidence rather than a current fix.

Reproducibility: yes. from source: model-authored Summary text is written before the genuine proof section, and current proof and rating readers take the first matching section before metadata. The supplied compiled-entry-point reproduction matches those current-main code paths, though this read-only review did not execute it.

Root-cause cluster Relationship: canonical Canonical: https://github.com/openclaw/clawsweeper/issues/951 Summary: This issue is the canonical open record for the durable report-section spoofing vulnerability; the prior PR is closed and unmerged.

Members:

  • fixed_by_candidate: https://github.com/openclaw/clawsweeper/pull/835 - It proposed the same hardening design but was closed unmerged, so it remains implementation evidence rather than a viable landing path.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Maintainer decision needed

Question Recommendation
Should bounded leading front matter become authoritative for proof and rating metadata in legacy durable reports, with section/front-matter conflicts failing closed rather than trusting section text? Prefer front matter and fail closed on conflict: Use bounded leading front matter for proof and rating gates, and route any disagreement with section text to human review.

Why: The source establishes the spoofable parser path, but the correct compatibility behavior for historical reports determines whether conflicting artifacts are silently normalized, held for human review, or rejected.

Next step This source-proven security issue needs the maintainer’s legacy-report trust-boundary decision before any repair lane can safely proceed.

Security Needs attention: Current source leaves a concrete trust-boundary gap between model-authored Markdown and durable-report readers.

Review details

Best possible solution:

Establish one auditable report trust boundary: neutralize all model-authored text written into report section bodies, use bounded leading front matter as the authoritative proof and rating metadata, and fail closed on conflicts in legacy reports with focused regression coverage for bare, fenced, HTML, and details-wrapped spoofing.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: model-authored Summary text is written before the genuine proof section, and current proof and rating readers take the first matching section before metadata. The supplied compiled-entry-point reproduction matches those current-main code paths, though this read-only review did not execute it.

Is this the best way to solve the issue?

Unclear until maintainers choose the legacy-report conflict policy. Extending the existing neutralizer plus bounded front-matter-first readers is the narrowest maintainable defense, but disagreement handling should fail closed rather than preserve spoofable section precedence.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • Changing legacy report readers without an explicit conflict policy could change labels or routing for already-published reports whose sections and front matter disagree.
  • Broad write-side escaping must preserve intentionally literal fields such as commands, file paths, automation payloads, and the separately allowlisted Mermaid diagram.

Codex review notes: model internal, reasoning high; reviewed against 5f8543d985cc.

Label changes

Label justifications:

  • P1: A source-proven proof-gate bypass can route unproven external pull requests away from the intended human-proof path.
  • impact:security: Attacker-controlled Markdown can cross into trusted proof, rating, labeling, and repair-routing decisions.
Evidence reviewed

Security concerns:

  • [high] Use trusted metadata before report section text — src/clawsweeper-report-parser.ts:414 Proof and rating readers consume the first matching report section before authoritative metadata, allowing earlier heading-shaped prose in an unsanitized model field to influence automated routing. Confidence: 0.92

What I checked:

  • Current proof reader is section-first: reportRealBehaviorProof reads the Real Behavior Proof section and derives status, evidence kind, summary, and action flag without preferring proof front matter. An earlier forged matching section can therefore control the derived proof result. (src/clawsweeper-report-parser.ts:414, 5f8543d985cc)
  • Current rating reader is section-first: reportPrRating takes Proof, Patch, and Overall tier values from the section before falling back to front matter, preserving the same trust problem for rating metadata. (src/clawsweeper-report-parser.ts:464, 5f8543d985cc)
  • Model prose reaches report sections unneutralized: The decision parser accepts summary, changeSummary, bestSolution, and assessment text through raw requireString; only systemContext is passed through neutralizeOwnedSectionSpoofing in the central decision construction. (src/clawsweeper-decision-parser.ts:779, 5f8543d985cc)
  • Renderer writes raw summary before trusted sections: The durable-report renderer writes options.decision.summary directly under its owned Summary heading, before later owned sections such as Real Behavior Proof and PR Rating. (src/clawsweeper-report-rendering.ts:2344, 5f8543d985cc)
  • Existing hardening pattern: The current neutralizer already escapes heading-shaped Markdown, HTML delimiters, fences, Setext underlines, and owned section labels, providing an established write-side defense to extend carefully. (src/clawsweeper-report-helpers.ts:136, 5f8543d985cc)
  • History and release provenance: Commit 526b4be3ded9cd86ac90b8abe6937212b6f224d0 is the earlier parser-sanitizer hardening commit and is contained in v0.1.0 and v0.2.0. git blame attributes the current extracted neutralizer and current parser modules to the August 1, 2026 decomposition commit, and no inspected current-main commit implements the broader durable-report fix. (src/clawsweeper-report-helpers.ts:136, 526b4be3ded9)

Likely related people:

  • Peter Steinberger: Recent commits dccfa528 and 4a39cfcf reorganized the review/reporting runtime into the current decision, report, and parser modules; blame attributes the current extracted neutralizer to that refactor. (role: recent area contributor; confidence: high; commits: dccfa528f038, 4a39cfcf6a96; files: src/clawsweeper-decision-parser.ts, src/clawsweeper-report-parser.ts, src/clawsweeper-report-helpers.ts)
  • Vincent Koc: Commit 526b4be3 introduced the parser-sanitizer hardening lineage that current code retains and extends through later refactors. (role: introduced earlier hardening pattern; confidence: medium; commits: 526b4be3ded9; files: src/clawsweeper-report-helpers.ts)
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Jul 30 '26 05:07 clawsweeper[bot]