Skip to content

[SECURITY] Require operator opt-in for NATIVEQUERY on server surfaces #815

Open

Description

@jeffreyaven

Current ownership after the SDK migration

Native backing-store execution and the pure-Go SQLite driver are now host-owned in StackQL. This issue requires a StackQL capability boundary; the former any-sdk driver ownership does not create an omnisdk blocker.

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

CWEs: CWE-749, CWE-269.

Source: GitHub Security Lab finding 21536, originally tested at adc0956, plus current-code review and the validation below. Credit: GitHub Security Lab Taskflow Agent, GitHub Secure Open Source Fund, reported by @JarLob.

Finding and evidence

The pgwire client controls raw backing-store SQL without an operator gate: internal/stackql/planbuilder/plan_builder.go passes node.QueryString to internal/stackql/primitivebuilder/raw_native_select.go and the engine's Query method. SQL submitted through Query can mutate the database.

On the current Windows build, an isolated unauthenticated loopback session created a table, inserted a marker, and ran VACUUM INTO to a disposable path. Another connection read the marker. load_extension was refused. This is database-content/file creation, not demonstrated arbitrary-byte file overwrite or SQLite code execution.

The original report also demonstrated PostgreSQL COPY ... PROGRAM under a privileged backend role; it was refused for a non-superuser role. That PostgreSQL experiment was not repeated in this review.

Required outcome

  • Add an operator-controlled server capability for native SQL, disabled unless explicitly enabled, covering simple/extended pgwire and MCP execution paths. CLI/shell behavior can remain available to the local operator.
  • Document that enabled native SQL grants the configured database role's authority and shared-cache access. Document least-privilege PostgreSQL roles.
  • Evaluate feasible SQLite restrictions through StackQL's current pure-Go SQL driver. Do not promise isolation from a shared-connection query_only pragma, reintroduce cgo, or assume an authorizer API exists without verifying it.

Validation and acceptance

Robot tests must refuse native reads and writes before backend execution when disabled, and preserve explicitly enabled diagnostics. Cover CREATE/INSERT, ATTACH/VACUUM to temporary files, control-table access, extended protocol, and MCP full_access versus the operator gate. Existing GC robot servers using NATIVEQUERY must opt in.

Scope and related work

Independent of listener authentication: an authenticated mTLS client currently has the same native capability. MCP already mode-gates NATIVEQUERY as unknown (read_only refuses, safe/delete_safe request approval, full_access allows). This issue is not the separate SQL-literal rendering bug.

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