Skip to content

fix(mcpx): refuse bare action PRAGMAs in the read-only log-sql guard (#6638) - #6700

Merged
dezren39 merged 2 commits into
mainfrom
queue/fallback-6638-bare-pragma
Nov 7, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/fallback-6638-bare-pragma

Conversation

@dezren39

@dezren39 dezren39 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #6638.

Problem

CheckReadOnly (the guard for the read-only mcpx log sql surface) refused value-carrying PRAGMAs after #3516, but checkReadOnlyPragma passed any bare PRAGMA — and SQLite has bare, no-value PRAGMAs that act instead of answering: PRAGMA optimize (rewrites sqlite_stat1), PRAGMA wal_checkpoint (forces WAL frames into the main database file — this store's DSN is WAL mode), PRAGMA incremental_vacuum, PRAGMA shrink_memory. All executed on the writable store connection.

Change

  • Bare PRAGMAs now pass only from an explicit allowlist of known reads (bareReadPragmas: journal_mode, user_version, schema_version, database_list, compile_options, integrity_check, current-setting reads, …). Unknown names are refused by default, so the next action PRAGMA is kept out by construction.
  • The bare name is extracted with the schema qualifier stripped up to the last . — the same treatment as the function-form branch — so PRAGMA main.wal_checkpoint cannot smuggle an action name past the allowlist (per Lane A's triage design note on mcpx(logstore): read-only log-sql guard still executes bare mutating PRAGMAs (optimize, wal_checkpoint) #6638).
  • incremental_vacuum disposition: refused — its bare form performs vacuum work (freelist 200 → 199 in rollback-journal mode); it is deliberately absent from the allowlist and named in the tests.
  • Package and function doc comments updated to state the bare-form rule.

Tests

  • Guard level (TestReadOnlyGuardRejectsAnythingThatWrites): optimize, wal_checkpoint, incremental_vacuum, shrink_memory, main.optimize, main.wal_checkpoint;, and an unknown pragma added to the refused list; schema_version, database_list, compile_options, main.journal_mode, integrity_check added to the allowed list.
  • RunSQL level (new TestRunSQLRefusesBareActionPragmas, following TestRunSQLRefusesPragmaAssignments): the four action PRAGMAs plus main.wal_checkpoint are refused through RunSQL; PRAGMA journal_mode still runs and returns wal.
  • Laptop: go test ./internal/logstore/ — pass (incl. the three guard tests verbosely); go vet ./internal/logstore/ clean; gofmt clean.
  • Full pkgs/mcpx suite: two failures in internal/api (TestPluginOpsAreGenerated — stale ops.gen.ts; TestTargetBearerTokenResolvesTheTargetDaemon — env-dependent). TestPluginOpsAreGenerated reproduced identically on clean origin/main with this change stashed — pre-existing and unrelated to logstore.

Propagation

mcpx also ships in dezren39/darwin-nix, but that repo carries no logstore Go source (config/planning only — verified by grep this shift), so there is no nix-side copy of the guard to patch; this PR is the whole set for #6638.

Filed and worked in queue fallback mode (queue backend down, code#6619) by Lane W.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…6638)

CheckReadOnly admitted any bare PRAGMA, so PRAGMA optimize, PRAGMA wal_checkpoint, PRAGMA incremental_vacuum and PRAGMA shrink_memory executed on the writable store through the read-only mcpx log sql surface. Bare PRAGMAs now pass only from an explicit allowlist of known reads (schema qualifier stripped, as in the function-form branch); unknown names are refused by default. incremental_vacuum disposition: refused - its bare form performs vacuum work. Regression coverage at guard level and RunSQL level, following TestRunSQLRefusesPragmaAssignments.
@dezren39
dezren39 requested a review from a team as a code owner November 7, 2026 02:49
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2013aae-f7c1-4b7f-906e-ec6974ab2af0
Commits

Reviewing files that changed from the base of the PR and between bfda3ed and c44c1a6.

Files selected for processing: 3

  • pkgs/mcpx/internal/logstore/logstore_test.go
  • pkgs/mcpx/internal/logstore/sql.go
  • pkgs/mcpx/internal/logstore/sql_internal_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T02:56:54.297704Z c44c1a6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39e4841082

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +702 to +706
for _, q := range []string{
`PRAGMA optimize`,
`PRAGMA wal_checkpoint`,
`PRAGMA incremental_vacuum`,
`PRAGMA shrink_memory`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add a registry-driven guard for bare PRAGMA classification

The new regression coverage checks a fixed list of action names, but no test enumerates the new bareReadPragmas registry or SQLite's PRAGMA inventory. Consequently, classification changes outside these examples can go untested, contrary to the source testing rule requiring a registry-driven guard for class-wide fixes. Add table-driven coverage of the read registry and an independent action/refusal oracle, including schema-qualified and assignment permutations; retain these examples as regression cases.

AGENTS.md reference: pkgs/mcpx/internal/AGENTS.md:L11-L12

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c44c1a6. Added a registry-driven class guard in pkgs/mcpx/internal/logstore/sql_internal_test.go (internal test package, per the existing pattern in this directory):

  • TestBareReadPragmaRegistryGuard iterates bareReadPragmas itself: every registered read must pass CheckReadOnly bare, schema-qualified (main.<name>), and upper-case, and its assignment form (<name>=1) must be refused — as must its call form, except for the established function-form reads whose argument names an object.
  • TestBareActionPragmasStayRefused is the independent oracle: the action names (optimize, wal_checkpoint, incremental_vacuum, shrink_memory) are hardcoded from SQLite's PRAGMA inventory, not derived from the registry, and each must be absent from the allowlist and refused bare, schema-qualified, upper-case, and in call form.

The example-based cases in logstore_test.go are retained as regression cases. Verified: go test ./internal/logstore -count=1 pass; the guard set also passes -race -shuffle=on -count=5.

Comment on lines +96 to +97
"short_column_names": true, "soft_heap_limit": true,
"synchronous": true, "table_list": true, "temp_store": true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the read_uncommitted setting query in the allowlist

For users inspecting the connection's isolation setting, mcpx log sql 'PRAGMA read_uncommitted' now fails because read_uncommitted is absent from this allowlist. This previously accepted statement is a genuine setting read: SQLite documents the bare query separately from its assignment form. Include it among the known reads while continuing to reject its value-carrying forms, so blocking action PRAGMAs does not also remove this read-only diagnostic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c44c1a6. read_uncommitted is added to bareReadPragmas — the bare setting query passes again, while PRAGMA read_uncommitted=ON and PRAGMA read_uncommitted(1) remain refused by the value-form branches. PRAGMA read_uncommitted is also retained as a guard-level regression example in TestReadOnlyGuardRejectsAnythingThatWrites, and the new registry guard in sql_internal_test.go covers its permutations. Verified: go test ./internal/logstore -count=1 pass.

…read + registry guard (#6638)

P2: PRAGMA read_uncommitted bare is a genuine setting read; added to bareReadPragmas (value forms still refused), with PRAGMA read_uncommitted retained as a guard-level regression example. P1: registry-driven class guard per pkgs/mcpx/internal/AGENTS.md — new sql_internal_test.go iterates bareReadPragmas asserting every registered read passes bare/schema-qualified/upper-case and its assignment (and, for bare-only reads, call) forms are refused; an independent hardcoded action oracle (optimize, wal_checkpoint, incremental_vacuum, shrink_memory) asserts those names stay out of the allowlist and refused in every form.
@dezren39
dezren39 merged commit b7d16d1 into main Nov 7, 2026
3 checks passed
@dezren39
dezren39 deleted the queue/fallback-6638-bare-pragma branch November 7, 2026 03:00
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.

mcpx(logstore): read-only log-sql guard still executes bare mutating PRAGMAs (optimize, wal_checkpoint)

1 participant