Skip to content

[SECURITY] Classify SQL by its effects before applying MCP safety modes #818

Open

Description

@jeffreyaven

Constituent of #769. Reviewed current main at 1de4135 on 2026-10-08; this issue proposes work, no implementation is included.

CWEs: CWE-862, CWE-863.

Finding and evidence

pkg/mcp_server/policy/policy.go treats every SELECT as read-only and scans for mutation keywords only in WITH statements. The parser and planner support EXEC as a table subquery.

Current-code parser and in-memory MCP tests confirmed that select status from (exec stackql_native_test.casing.activate.activate @id = 'x') parses as SELECT, is allowed in read_only, and reaches the query backend. The existing robot EXEC scenario establishes that this form invokes the operation.

Also inspect stackql_preview.iac.run: internal/stackql/intrinsic/iac.go executes a converge plan from SELECT. It requires --preview with unstable:true; it is not enabled by default. An AST-only 'SELECT is safe' rule would still miss this effect. Its mutation path was source-traced, not exercised against cloud resources.

Required outcome

  • Use one semantic effect classification shared with the parser/planner, including nested EXEC, subqueries, views/indirection and effectful intrinsic relations.
  • Refuse cloud mutations/lifecycle effects in read_only and request the appropriate approval in safe/delete_safe; do so before any effect occurs.
  • Keep metadata/select-only queries usable. Avoid regex matching inside literal strings as the definitive classifier.

Validation and acceptance

Add robot cases with a mock operation counter proving zero writes for nested EXEC in read_only, correct approval behavior in safe/delete_safe, and allowed execution in full_access. Add an opt-in preview IaC mock case. Preserve PR #804 multi-statement protections and test indirection through views as applicable.

Scope and related work

pull_provider and reload_credentials are expressly documented as allowed in all modes because the contract concerns cloud effects. Their cache/source safety is covered separately; their mere availability is not this bypass.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions