Skip to content

fix: prevent sqlite commands from opening live state - #123816

Merged
fuller-stack-dev merged 4 commits into
openclaw:mainfrom
fuller-stack-dev:fix/guard-live-state-sqlite-exec
Aug 14, 2026
Merged

fuller-stack-dev merged 4 commits into
openclaw:mainfrom
fuller-stack-dev:fix/guard-live-state-sqlite-exec

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Related: #101290

What Problem This Solves

Fixes an issue where an agent running external sqlite3 against an active OpenClaw state database could join the live WAL lifecycle outside OpenClaw's SQLite version and ownership guards, risking database corruption.

Why This Change Was Made

Gateway-host exec preflight now rejects external sqlite3 commands whose initial database or explicit positional/-cmd .open target resolves inside the active OpenClaw state directory. The guard follows command carriers, relative paths, state-directory variables, and symlink aliases; private database copies outside the live state tree remain usable.

This is defense in depth for the agent-exec path. It does not claim to close the broader live-state ownership work tracked in #101290 or provide an OS sandbox against deliberately obfuscated arbitrary code.

User Impact

Agents can no longer open live OpenClaw state databases directly with external sqlite3. They receive an actionable error directing them to OpenClaw commands or a private backup copy, while operators can still inspect copied databases normally.

Evidence

  • Base 3289e08c3005515fb8e49379fd18951ef2530507: a harmless sqlite3 stand-in started against both an isolated active-state path and a private copied path (RED).
  • Prior head: positional .open reopened a live database after the initial :memory: target passed preflight (RED).
  • Head 09db2821139b9bffde545d8973df506c847b49be: direct, positional .open, and -cmd .open live targets were rejected before spawn; all three private-copy controls completed (GREEN).
  • Focused regression, adjacent-path, and negative-control tests: 95 passed, 4 platform skips.
  • Production TypeScript graph, focused formatting, and diff checks passed.
  • Source-blind six-case behavior validation passed on the exact final head with fresh isolated state.
  • Autoreview passed with no accepted/actionable findings.
  • Hosted CI passed on the exact final head: 62 jobs passed and 18 were intentionally skipped.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 14, 2026
@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review August 14, 2026 20:33
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 14, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 5:17 PM ET / 21:17 UTC.

ClawSweeper review

What this changes

The PR prevents gateway-hosted external SQLite commands from opening OpenClaw’s active state directory, including direct, positional .open, and -cmd .open targets.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer approval. The prior SQLite .open bypass is addressed on the final head, and no blocking patch defect was found; this remains an intentional, scoped compatibility and state-safety decision.

Priority: P1
Reviewed head: 09db2821139b9bffde545d8973df506c847b49be
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The final patch directly fixes the earlier bypass with focused boundary coverage and no blocking review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This PR is authored by a repository member, so the external-contributor real-behavior-proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This PR is authored by a repository member, so the external-contributor real-behavior-proof gate does not apply.
Evidence reviewed 6 items Final guard implementation: The final head preserves argv candidates through command carriers, extracts direct and .open SQLite targets, canonicalizes existing ancestors, and checks containment against the state directory.
Gateway owner boundary: The gateway path performs the new state-target rejection after resolving the workdir and before any process dispatch or environment preparation.
Regression coverage: The added test covers direct targets, carrier wrapping, positional and -cmd .open, state-relative paths, symlink aliases, private-copy controls, and a pre-spawn marker check.
Findings None None.
Security None None.

How this fits together

Gateway-hosted agent exec requests pass through preparation before OpenClaw starts a process. The changed guard preserves parsed command arguments, detects SQLite database targets, and rejects targets inside live OpenClaw state.

flowchart LR
A[Agent exec request] --> B[Gateway exec preparation]
B --> C[SQLite target analysis]
C --> D{Target inside active state?}
D -->|Yes| E[Actionable rejection]
D -->|No| F[Start external command]
Loading

Decision needed

Question Recommendation
Should this land as a deliberately scoped gateway-exec mitigation for live SQLite access, while leaving broader state-ownership enforcement to #101290? Land the scoped exec guard: Accept the targeted rejection of live-state SQLite commands while keeping broader ownership work in the canonical issue.

Why: The code is a focused defense-in-depth guard, but accepting its intentional compatibility change and limited scope is a maintainer security-boundary decision.

Before merge

  • Resolve merge risk (P1) - Merging intentionally rejects existing gateway-hosted sqlite3 access to active state paths; affected automation must use OpenClaw commands or a copied database.
  • Resolve merge risk (P1) - Production code grows by 228 net lines for this bug fix; the added argv-preserving path is justified by retaining quoted database-token boundaries, but the guard should remain limited to this pre-spawn state-ownership invariant.
Agent review details

Security

None.

PR surface

Source +228, Tests +172. Total +400 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 247 19 +228
Tests 1 172 0 +172
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 419 19 +400

Review metrics

Metric Value Why it matters
Production versus test delta production +247/-19 (net +228), tests +172/-0 The repair adds a meaningful parser and path-containment surface alongside focused boundary regressions.

Stored data model

Persistent data-model change detected: serialized state: src/agents/bash-tools.exec-live-state-sqlite-guard.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Merge the scoped guard (recommended)
    Accept the intentional rejection of gateway-hosted SQLite access to live state while preserving copied-database inspection.
  2. Pause for broader policy
    Hold this PR if maintainers require a system-wide state-access solution before changing the gateway exec contract.

Technical review

Best possible solution:

Adopt this as a bounded gateway-exec mitigation, retaining private-copy access and the explicit boundary that broader live-state ownership remains tracked by the canonical issue.

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

Yes: the added focused test supplies direct and reopen command cases plus a pre-spawn marker check; this read-only review inspected the path but did not execute it.

Is this the best way to solve the issue?

Yes, as a scoped mitigation: the gateway exec preflight owns the decision to launch an external process and has both the resolved workdir and active state directory available before spawn.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This PR is authored by a repository member, so the external-contributor real-behavior-proof gate does not apply.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The PR mitigates live state-database corruption exposure in gateway-hosted agent execution.
  • merge-risk: 🚨 compatibility: Previously permitted gateway-hosted SQLite commands targeting active state will now fail before spawn.
  • merge-risk: 🚨 security-boundary: The patch changes a pre-spawn boundary protecting OpenClaw-managed live SQLite state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This PR is authored by a repository member, so the external-contributor real-behavior-proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • fuller-stack-dev: The PR timeline assigns this repository member to the work, and they authored both the initial guard and the targeted reopen repair. (role: assigned current repair owner; confidence: high; commits: 2729502a6ae0, 09db2821139b; files: src/infra/exec-control-command-guard.ts, src/agents/bash-tools.exec-run.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-14T20:41:21.739Z sha 2729502 :: found issues before merge. :: [P1] Reject SQLite shell commands that reopen a live database

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Fixed the SQLite shell reopen bypass in 09db2821139b9bffde545d8973df506c847b49be. The Gateway preflight now checks both positional and -cmd .open/.op targets against the active state directory. Added regressions for both live-target forms and copied-database negative controls; focused suite: 95 passed, 4 platform skips; exact-head source-blind behavior proof passes all six direct/reopen cases. @clawsweeper re-review

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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 added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Owner decision: land the scoped Gateway exec guard and accept the intentional compatibility change. Live-state sqlite3 automation must use OpenClaw-owned commands or a private copied database; broader state-ownership enforcement remains tracked in #101290.

@fuller-stack-dev
fuller-stack-dev merged commit 2044167 into openclaw:main Aug 14, 2026
143 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant