Skip to content

fix(security): prevent slow review classification on crafted paths - #1262

Merged
vincentkoc merged 1 commit into
mainfrom
security/codeql-clawsweeper-path-classifier-20260827
Aug 27, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
security/codeql-clawsweeper-path-classifier-20260827

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Related: https://github.com/openclaw/clawsweeper/security/code-scanning/99

What Problem This Solves

Fixes an issue where reviewing a pull request with an attacker-sized changed-file path containing repeated .spec. fragments could spend polynomial time classifying whether the path is production code.

Why This Change Was Made

The production-path classifier now parses exact path segments and the basename with bounded string operations. It preserves the existing test/example/fixture classification boundary without adding a fallback or changing unrelated review policy.

User Impact

ClawSweeper review preparation remains responsive for crafted or unusually long changed-file paths. Existing test and production path classifications are unchanged.

OpenClaw Bay Impact

None. This changes local pull-file classification before report rendering; it does not change lifecycle publication, queue state, status, telemetry, or dashboard contracts.

Documentation Impact

No documentation change is needed. The existing review-policy contract remains unchanged; this is an implementation hardening of the same path classification behavior.

Evidence

  • Pre-fix public classifier reproduction: a 120,011-character path with 20,000 repeated .spec. markers took 1,211.9 ms and failed the new 250 ms bound.
  • Post-fix local result: the same production classifier path took 0.64 ms.
  • Classification equivalence: 8,000 generated path combinations matched the previous classifier exactly.
  • Focused owner suite: node --test test/pr-surface-policy.test.ts passed 36/36.
  • Formatting and static/build/lint/coverage gate: pnpm run check completed every touched-surface check. Three unrelated tests failed identically on untouched origin/main: the host Git hook callback expectation, unavailable cached [email protected], and the local live-proof tmux window setup.
  • Pre-commit Sol/high autoreview: no P0/P1 findings, patch correct, confidence 0.98.
  • Committed repository-native review of 71df3a1ce714d737e250008597075bb5eaeb2ac4..536d2b8c6f7dba779f1f4abd92ea09bb20dbfe0e: nothing_found, high confidence. Its independent checks included a 200,000-case differential comparison and adversarial timing.
  • Production LOC: +16/-6 (net +10). The growth replaces ambiguous regex matching with explicit segment/basename parsing required to remove the polynomial-time bug while preserving behavior.
  • Tests: +36/-0.

Real Behavior Proof

  • Claim: changed-file classification preserves the existing production/test boundary and completes in bounded time for repeated .spec. markers.
  • Exercised surface: compiled sqliteSchemaChangeFromPullFilesForTest, which delegates to the production sqliteSchemaChangeFromContext path classifier.
  • Scenario: exact test-directory and test-basename boundaries plus a 120,011-character production filename containing 20,000 repeated .spec. markers before /schema.sql.
  • Environment: AWS Crabbox, provider aws, Node v24.18.1, repository-pinned [email protected], lease cbx_4bb7c81fe09a.
  • Command: clean dependency install, TypeScript build, then node --test test/pr-surface-policy.test.ts.
  • Observed result: 36/36 passed; adversarial classification completed in 0.481 ms.
  • Artifact: https://crabbox.openclaw.ai/portal/runs/run_c5e32fc41153
  • Limits: parser/classifier change only; no GitHub API, workflow, queue, or dashboard behavior was exercised.

Exact-Head Review Proof

Review Disposition

  • The review requested Docker-backed local-container provenance. That clause in AGENTS.md applies specifically on a Windows host; this executor is on macOS. The configured direct Crabbox provider is AWS, and the Crabbox policy describes local-container as a fallback rather than remote proof. The clean AWS lease and the independent exact-review terminal proof above exercise the current head, so no weaker local-container rerun is applicable.
  • Rank-up move retained: keep the narrow linear classifier and current-head focused proof. No code finding or contributor-facing blocker remains.

Overlap

#1081 also touches src/clawsweeper-change-detection.ts, but it changes persistence-policy precision rather than the CodeQL-reported .spec. matcher. It remains untouched and is not superseded by this PR.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Current-head proof and the prior proof disposition are now recorded in the PR body.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 5:36 AM ET / 09:36 UTC.

ClawSweeper review

What this changes

Replaces regex-based pull-file test-path classification with exact segment and basename checks, adding boundary and adversarial timing tests.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this member-authored draft open for maintainer approval. Current main still uses the backtracking-prone suffix regex, while this PR’s exact-head implementation uses bounded segment and basename checks with focused boundary and timing coverage.

Priority: P2
Reviewed head: 536d2b8c6f7dba779f1f4abd92ea09bb20dbfe0e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-consistent hardening patch with strong current-head runtime evidence and no actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body provides current-head AWS Crabbox proof against the compiled production classifier, including the adversarial path, passing focused suite, elapsed result, lease, and linked artifact.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body provides current-head AWS Crabbox proof against the compiled production classifier, including the adversarial path, passing focused suite, elapsed result, lease, and linked artifact.
Evidence reviewed 5 items Current main remains vulnerable: Current main still applies the suffix regex that repeatedly scans candidate .spec. or .test. markers before a later slash, so the central fix is not already implemented.
Narrow bounded replacement: The PR head lowercases and splits the path once, checks exact excluded segments, then searches only the basename for test suffix markers.
Focused regression coverage: The added cases preserve case-insensitive directory and basename boundaries and exercise 20,000 repeated markers under a 250 ms bound.
Findings None None.
Security None None.

Live Verification

Command: pnpm run build && node --test test/pr-surface-policy.test.ts

Result: PASS (completed)

$ tsc -p tsconfig.json
✔ config surface reports force human review instead of automerge pass (3.902161ms)
✔ config surface reports preserve security-sensitive markers (1.077973ms)
✔ config surface detector finds schema and plugin manifest additions (1.783394ms)
✔ config surface detector ignores non-semantic docs wording (0.349239ms)
✔ config surface detector finds removed schema keys (0.241149ms)
✔ config surface detector finds schema assembly changes (0.270563ms)
✔ config surface detector fails closed for schema continuation changes (0.353657ms)
✔ config surface detector fails closed for missing patches (0.246097ms)
✔ config surface detector fails closed for truncated file patches (0.281453ms)
✔ config surface detector fails closed for renamed config surface files (0.410613ms)
✔ config surface detector fails closed for truncated pull files (0.217955ms)
✔ tooling diagnostic and subprocess regression do not produce a stored-data warning (19.549276ms)
✔ data model detector scopes colocated test serialization (0.237081ms)
✔ data model detector scopes test setup with a missing patch (0.098122ms)
✔ data model detector scopes fixture with a truncated patch (0.120384ms)
✔ data model detector scopes example storage setup (0.105616ms)
✔ data model detector scopes test to production rename with a missing patch (0.186647ms)
✔ data model detector scopes production to test rename with serialization removed (0.454916ms)
✔ data model detector scopes production to fixture rename with a missing patch (0.099355ms)
✔ data model detector scopes truncated file list containing only test setup (0.084918ms)
✔ data model detector finds production persistence and semantic docs changes in mixed diffs (1.436349ms)
✔ data model detector ignores query-only and non-semantic docs changes (0.722944ms)
✔ SQLite schema detector finds production table changes and ignores non-schema SQL (1.169223ms)
✔ production path classification preserves test segment and basename boundaries (0.309586ms)
✔ production path classification is bounded for repeated test markers (0.728122ms)
✔ SQLite schema warning is visible for table changes and absent otherwise (5.590449ms)
✔ data model detector flags path-hinted persisted field declarations (0.609503ms)
✔ data model detector fails closed for missing and truncated likely-surface patches (0.251417ms)
✔ data model reports force human review without migration proof (7.029201ms)
✔ data model warnings escape marker-like surface filenames (2.198365ms)
✔ data model reports can pass when migration proof is recorded (2.339387ms)
✔ data model reports can pass when no migration is required and compatibility is verified (2.472124ms)
✔ data model reports reject explicitly negative migration proof (1.741616ms)
✔ data model reports reject requested future migration proof (3.918712ms)
✔ data model reports reject planned migration tests as proof (3.045249ms)
✔ data model reports reject hypothetical compatibility proof (2.779305ms)
ℹ tests 36
ℹ suites 0
ℹ pass 36
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 364.423666

Assertions:

  • PASS expect_output: production path classification preserves test segment and basename boundaries
  • PASS expect_output: production path classification is bounded for repeated test markers
  • PASS expect_output: pass

How this fits together

ClawSweeper examines changed-file paths from OpenClaw pull requests before deciding whether SQLite schema changes need a review warning. The classifier feeds the schema detector, which writes warning metadata into the generated review report.

flowchart LR
  A[GitHub pull-file paths] --> B[Review context]
  B --> C[Path classifier]
  C --> D{Production source path?}
  D -->|yes| E[SQLite schema detector]
  D -->|no| F[No schema warning]
  E --> G[Review report metadata]
  G --> H[Maintainer warning]
Loading

Decision needed

Question Recommendation
Should an area owner approve this member-authored draft for landing based on the current-head classifier proof? Approve for landing: Accept the bounded classifier and its focused current-head proof once the author marks the draft ready.

Why: The implementation and proof support the change, but repository policy keeps member-authored pull requests open for explicit maintainer judgment.

Before merge

  • Complete next step (P2) - No mechanical repair is needed; this clean member-authored draft requires explicit maintainer approval and marking ready.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Classifier and coverage delta production +16/-6; tests +36/-0; 2 files affected The small production rewrite is paired with targeted boundary and adversarial timing coverage.

Technical review

Best possible solution:

Approve the narrow linear classifier after the draft is marked ready, retaining the focused boundary and adversarial regression coverage.

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

Yes—source inspection gives a high-confidence path: repeated suffix markers followed by a slash make the current-main suffix regex retry across many starts; the PR records the matching adversarial run.

Is this the best way to solve the issue?

Yes—the exact segment and basename parsing preserves the classifier’s documented boundary without broadening review policy or adding a new fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 13f77495c462.

Labels

Label changes:

  • add P2: This is a bounded review-preparation availability hardening with limited direct user blast radius.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides current-head AWS Crabbox proof against the compiled production classifier, including the adversarial path, passing focused suite, elapsed result, lease, and linked artifact.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded review-preparation availability hardening with limited direct user blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides current-head AWS Crabbox proof against the compiled production classifier, including the adversarial path, passing focused suite, elapsed result, lease, and linked artifact.

Evidence

What I checked:

  • Current main remains vulnerable: Current main still applies the suffix regex that repeatedly scans candidate .spec. or .test. markers before a later slash, so the central fix is not already implemented. (src/clawsweeper-change-detection.ts:202, 13f77495c462)
  • Narrow bounded replacement: The PR head lowercases and splits the path once, checks exact excluded segments, then searches only the basename for test suffix markers. (src/clawsweeper-change-detection.ts:197, 536d2b8c6f7d)
  • Focused regression coverage: The added cases preserve case-insensitive directory and basename boundaries and exercise 20,000 repeated markers under a 250 ms bound. (test/pr-surface-policy.test.ts:448, 536d2b8c6f7d)
  • Recorded real-behavior proof: The PR body records an exact-head AWS Crabbox run against the compiled production path classifier: 36 focused tests passed and the adversarial case completed in 0.481 ms, with a linked run artifact. (536d2b8c6f7d)
  • Feature history: File history identifies the original SQLite warning feature and a recent adjacent fixture-classification repair, supporting routing to the area’s prior contributors. (src/clawsweeper-change-detection.ts:197, a8b2debb75fd)

Likely related people:

  • Patrick Erichsen: Authored the visible history entry that introduced the SQLite schema-warning surface this classifier serves. (role: introduced SQLite schema warning; confidence: medium; commits: a8b2debb75fd; files: src/clawsweeper-change-detection.ts, test/pr-surface-policy.test.ts)
  • Peter Steinberger: Authored the most recent preceding classifier repair for test fixtures in the same source and test files. (role: recent area contributor; confidence: medium; commits: ff813ac2fa76; files: src/clawsweeper-change-detection.ts, test/pr-surface-policy.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-27T08:54:44.447Z sha 536d2b8 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review August 27, 2026 09:37
@vincentkoc
vincentkoc merged commit a22ff98 into main Aug 27, 2026
13 checks passed
@vincentkoc
vincentkoc deleted the security/codeql-clawsweeper-path-classifier-20260827 branch August 27, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant