# GHSA-M88C-HFF9-6GW3: MCP server read-only / safe mode can be bypassed to perform arbitrary writes (data-modifying CTE and EXPLAIN ANALYZE)

- Database: GitHub
- Severity: CVSS 8.1 (High)
- Published: 2026-09-25
- Modified: 2026-09-25

## Affected versions

- github.com/clidey/whodb (Go): through 0.129.0

## Description

### Summary
When the WhoDB MCP server is started in read-only mode (`whodb-cli mcp serve --read-only`, or `--safe-mode` which is read-only plus strict), the read-only guarantee for the `whodb_query` tool is enforced only by an application-layer SQL string classifier. The classifier decides the statement type from the leading SQL keyword and allow-lists `WITH` and `EXPLAIN` statements without inspecting the statement body. There is no database-level read-only control on the execution path, so a statement that is classified as read-only but actually performs a write is executed and committed. A client restricted to read-only MCP access can therefore perform arbitrary INSERT, UPDATE, and DELETE operations, defeating the security property the mode advertises.

### Details
In `cli/pkg/mcp/validation.go` (verified at commit `44099a29ea73baa0a3e5465c68dd20e6eb3957d2`):

Statement type is decided by leading-keyword prefix (lines 85-90):

    {"DESC ", StatementDescribe}, {"EXPLAIN ", StatementExplain},
    {"WITH ", StatementWith},
    ...
    if strings.HasPrefix(q, k.kw) { return k.typ }

Read-only mode allow-lists those types and returns nil (allowed) without inspecting the body (lines 156-158):

    switch stmtType {
    case StatementSelect, StatementShow, StatementDescribe, StatementExplain, StatementWith:
        return nil

The execution path applies no database-level read-only control:
- `cli/pkg/mcp/tools.go:393` calls `mgr.ExecuteQuery(query)`
- `core/src/plugins/gorm/plugin.go:635` runs `rows, err := db.Raw(query, params...).Rows()` with no `SET TRANSACTION READ ONLY` and no read-only role or replica.

The classifier does block `--` and `/*` comments, multiple statements (`;`), and `DROP `/`TRUNCATE ` substrings, but `WITH ...` and `EXPLAIN ANALYZE ...` pass because the leading keyword drives classification even when the body modifies data.

### PoC
Both queries pass the `--read-only` validator and commit writes.

1. PostgreSQL with a test table:

    CREATE TABLE t(id int primary key, v text);
    INSERT INTO t VALUES (1,'orig'),(2,'orig'),(3,'orig');

2. Start the MCP server in read-only mode against that database:

    WHODB_POSTGRES='[{"alias":"test","host":"127.0.0.1","user":"postgres","password":"...","database":"testdb","port":"5432"}]' whodb-cli mcp serve --read-only --transport http --host 127.0.0.1 --port 8088

3. Call the `whodb_query` tool with each query:
   - control: `SELECT count(*) FROM t` -> allowed (read)
   - `DELETE FROM t WHERE id=1` -> rejected ("write operations are not allowed in read-only mode: DELETE")
   - `WITH x AS (DELETE FROM t WHERE id=2 RETURNING *) SELECT * FROM x` -> allowed, row id=2 deleted
   - `EXPLAIN ANALYZE INSERT INTO t VALUES (99,'pwned')` -> allowed, row id=99 inserted

Database state checked by a direct query (not through the MCP server): before `{1,2,3}`, after `{1,3,99}`. The direct DELETE is blocked, confirming read-only mode is active; the two allow-listed statement types perform real writes regardless. This is an enforcement defect, not a documented design choice: the server's own security model explicitly rejects INSERT/UPDATE/DELETE.

### Impact
CWE-863 (incorrect authorization) / incomplete read-only enforcement. Any party with read-only MCP access to a WhoDB-managed database can modify or delete data, defeating the read-only and safe-mode guarantee. Backends executed via the `db.Raw` path (PostgreSQL, MySQL/MariaDB, SQLite) are affected; verified on PostgreSQL.

### Suggested remediation
1. Enforce read-only at the database layer for read-only and safe mode: run the query connection in a read-only transaction (`SET TRANSACTION READ ONLY`) or under a least-privilege read-only role, so classifier gaps cannot result in writes.
2. If keeping the classifier as defense in depth, inspect the full statement rather than only the leading keyword: scan CTE bodies for data-modifying sub-statements, and reject `EXPLAIN ANALYZE` of DML in read-only mode.

## References

- https://github.com/clidey/whodb/security/advisories/GHSA-m88c-hff9-6gw3

Page: https://cve.now/GHSA-M88C-HFF9-6GW3

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
