Skip to content

fix(security): do not treat COMMENT/CALL table names as mutations - #64

Merged
geekypunk merged 1 commit into
mainfrom
cursor/sql-guard-comment-call-c497
Aug 17, 2026
Merged

fix(security): do not treat COMMENT/CALL table names as mutations#64
geekypunk merged 1 commit into
mainfrom
cursor/sql-guard-comment-call-c497

Conversation

@venkateshsakamuri-lab

Copy link
Copy Markdown
Contributor

Summary

Yes, this is a real bug and it should be fixed before anyone hits it on a comment table.

McpSqlGuardService.containsForbiddenKeyword (and the matching MCP JS shim) scanned the whole statement with \bCOMMENT\b / \bCALL\b. That is an identifier match, not a statement-verb match, so these were rejected as "potentially mutating":

  • SELECT * FROM comment
  • SELECT * FROM call
  • JOIN comment ON comment.id = …
  • SELECT COALESCE(comment, '')
  • SELECT REPLACE(name, 'a', 'b') (REPLACE is also on the forbidden list)

This guard sits on dashboard artifact queries (POST /api/dashboards/query and the public share query path) as well as /api/mcp/query-readonly. A generated dashboard against a comment table would fail at the gate.

Fix

Stop scanning bare words. Detect mutating statements only:

  • Mutating CTE body: WITH x AS (DELETE FROM t RETURNING …) SELECT …
  • WITH then DML: WITH x AS (SELECT …) DELETE FROM t …
  • SELECT … FOR UPDATE
  • EXPLAIN DELETE … (while EXPLAIN SELECT * FROM comment stays allowed)

Top-level DELETE / CALL / COMMENT ON were already rejected by the first-keyword allowlist and still are.

Java and JS stay in lockstep.

Test plan

  • ./mvnw test -Dtest=McpSqlGuardServiceTest — 12 tests, 0 failures (FROM comment / FROM call allowed; mutating CTEs and WITH … DELETE still blocked)
  • node --test mcp/deepsql-phase1-lib.test.js — 78 tests, 0 failures
Open in Web Open in Cursor 

Bare \bCOMMENT\b / \bCALL\b scans rejected SELECT * FROM comment.
Match statement verbs only (mutating CTEs, WITH … DML, FOR UPDATE).

Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
@venkateshsakamuri-lab
venkateshsakamuri-lab marked this pull request as ready for review August 17, 2026 18:28
@cursor

cursor Bot commented Aug 17, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@geekypunk
geekypunk merged commit 659394f into main Aug 17, 2026
9 checks passed
@geekypunk
geekypunk deleted the cursor/sql-guard-comment-call-c497 branch August 17, 2026 19:29
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.

3 participants