Skip to content

fix(macos): hold Read-Only Safe Mode at the server, bound MCP and assistant answers, narrow the assistant's tools and refuse MCP file access - #4219

Merged
datlechin merged 13 commits into
mainfrom
fix/audit-w6-ai-security
Nov 12, 2026
Merged

datlechin merged 13 commits into
mainfrom
fix/audit-w6-ai-security

Conversation

@datlechin

@datlechin datlechin commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Audit 2026-11-12, lane ai-security. Every MCP and AI change narrows what a client or the assistant can do; none widens it.

  • ER-1: the Claude Agent and Copilot pipe reads landed on main in perf(macos): append the execution log in place, skip unchanged tab saves, read agent CLI pipes apart and release closed agent sessions #4212; this PR keeps a tunnel helper's stderr lines whole across CRLF and split UTF-8.
  • AM-1: search_query_history, list_recent_tabs and focus_query_tab without connection_id cover only already-approved connections; focus_query_tab asks about the tab's connection; a call that names one asks once.
  • AM-3: in Ask, the Claude Agent token reaches only the seven schema tools, enforced by the MCP server; initialize advertises resources, prompts and completions only with resources:read.
  • AM-4: the assistant's list_connections returns only the conversation's connection.
  • AM-2: MCP answers held to 4 MB, assistant tool answers to 256 KB, values over 64 KB cut with a mark, notes says why. PostgreSQL, MySQL, SQLite, DuckDB and ClickHouse stop reading at the byte limit; SQL Server and ClickHouse stop at the row cap.
  • RV-1: Stop during an assistant write already in the database says it may have been applied, logs it to history and refreshes the catalog when it ends. MCP keeps -33002, with data.outcome: "unknown".
  • AM-5: a waiting tool card is settled on Stop, New Conversation, switch and reopen; its buttons and Return/Escape act only while a turn waits on it.
  • AM-6: Always Allow grants are listed under AI Policy in the connection form, each with Forget.
  • AM-7: the Edit prompt adds "leave schema, privilege and session changes to Agent mode". What Edit runs is unchanged.
  • EX-1: at Read-Only, every read TablePro runs for the user runs in the engine's read-only mode on PostgreSQL, PGlite, CockroachDB, KingbaseES, MySQL, MariaDB, SQLite, DuckDB and ClickHouse. Run All runs in autocommit there. On Oracle, Dameng and OceanBase a call off the built-in list asks, and is refused when a profile or floor holds Read-Only.
  • PluginKit (kit stays 44, additive): PluginStatementContext.enforcesReadOnly and resultByteLimit, PluginCapabilities.enforcesReadOnlyMode, executeBoundedQuery(query:rowCap:context:).
  • CR-1: the core refuses an MCP statement that reads or writes files, reaches another server or runs code, at every External Clients level (DuckDB file and unknown table functions, file names in FROM, COPY, ATTACH, INSTALL, LOAD, EXPORT, also after EXPLAIN ANALYZE; file functions of the other engines). macOS gains the DuckDB table-function allowlist and dotted file names. One fixture pins both apps' lists.
  • Also fixed: assistant tool errors show the database's message; the MCP error redactor no longer takes minutes on long errors; an analyzed write through explain_query lands in history.

Tests changed on purpose: ProtectedWriteDeadlineTests.inDriverAtCancelFinishes, LibPQReadOnlyTransactionTests.wrapsOnlyExternalAndSafeModeReads, LibPQBoundedReadOnlyTests (drainsWhereNoCancelIsTaken replaced), ReadOnlySafeModeEntryPointTests.plainBrowseCarriesTheMode, WritePolicyMatrix (focus_query_tab), MySQL wrapsOnlyEnforcingFlavors, capabilityFollowsFlavor, refusalIsReported, declaresReadOnlyStatements.

Docs: TableProApp/docs#210

Needs the maintainer

  • AM-7: whether Edit should refuse DDL, DCL and session statements at the gate.
  • AM-2: the assistant's 256 KB answer size.
  • EX-1: the docs said Read-Only blocks what it cannot tell; per the lane brief the fallback asks unless a profile or floor holds the level.

Left open

  • AM-2: one SQL Server executeBatch is decoded whole, and its single statements stop at the row cap but not at bytes; Snowflake, Oracle and drivers on the PluginKit default read the whole result.
  • EX-1: an Oracle or Dameng function called without parentheses reads as a column; the iOS app has the same Read-Only gap.

Test plan

  • Unit plan: 30452 run; the 7 failures also fail on main (ConnectionFormPortTLSTests, ResultRowsBuildOffMainTests, SessionRecoveryLoopTests).
  • package TableProCore (grammar, PluginKit), core tablepro-core, core tablepro-mcp, clippy and rustfmt on both crates, plugins, abi.
  • Not run live: a Claude Agent turn in Ask mode; apple/scripts/probes/check-postgresql-read-only-functions.sh.

@datlechin
datlechin enabled auto-merge (squash) November 12, 2026 05:27
# Conflicts:
#	apple/Plugins/PostgreSQLDriverTests/LibPQScriptedServer.swift
# Conflicts:
#	apple/TablePro/Core/AI/CLI/AgentCLIProcess.swift
#	apple/TablePro/Core/Coordinators/QueryExecutionCoordinator+Parameters.swift
#	apple/TablePro/Core/Database/Access/DatabaseAccessBridge+Scripts.swift
#	apple/TablePro/Core/LSP/LSPTransport.swift
#	apple/TablePro/Core/Process/PipeReader.swift
#	apple/TablePro/Models/AI/AgentSession.swift
#	apple/TablePro/ViewModels/AIChatViewModel+Persistence.swift
#	apple/TablePro/ViewModels/AIChatViewModel.swift
#	apple/TablePro/Views/Main/Extensions/MainContentCoordinator+Explain.swift
#	apple/TablePro/Views/Main/MainContentCoordinator.swift
#	apple/TableProTests/Core/AI/AgentCLIProcessTests.swift
# Conflicts:
#	apple/Plugins/MySQLDriverPlugin/MySQLPluginDriver.swift
#	apple/Plugins/TableProPluginKit/PluginStatementContext.swift
#	apple/TablePro/Core/ObjectCopy/ObjectCopyRunner.swift
# Conflicts:
#	apple/Plugins/SQLiteDriverPlugin/SQLitePlugin.swift
#	apple/TablePro/Core/Compare/CompareRowService.swift
# Conflicts:
#	apple/TablePro/Core/AI/ClaudeAgent/ClaudeAgentMCPBridge.swift
#	apple/TablePro/Core/AI/ClaudeAgent/ClaudeAgentProvider.swift
#	apple/TablePro/Core/MCP/MCPTokenStore.swift
#	apple/TableProTests/Core/AI/ClaudeAgentConnectionScopeTests.swift
@datlechin
datlechin merged commit 832011a into main Nov 12, 2026
1 check passed
@datlechin
datlechin deleted the fix/audit-w6-ai-security branch November 12, 2026 21:36
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.

1 participant