Summary
pgEdge Postgres MCP Server could allow a caller to bypass the intended read-only boundary when issuing database queries. If the connection's PostgreSQL role has write privileges, multiple statements or persistent session changes may allow database writes and affect availability.
Affected context
The issue affects the query_database path when it uses a connection marked read-only but sends unrecognized statements through pgx without bind parameters. This can select PostgreSQL's simple query protocol, which permits multiple semicolon-separated statements in one request. Risk depends on the database role's privileges and whether session state is reused through a connection pool; the flaw does not add confidentiality impact beyond reads already allowed by the connection.
Exploit preconditions
- Attack surface: The MCP server's
query_databaseoperation. - Required access: The caller must be able to submit requests to that operation.
- Required database privilege: The PostgreSQL role used by the connection must have write privileges for the affected data or operations.
- Trigger point: The server executes an unrecognized statement without bind parameters on a connection treated as read-only.
- Why exploitation is possible: The simple query protocol can process multiple statements in one request, while the read-only safeguard does not reliably prevent transaction or session changes and subsequent writes. Reused pooled connections can retain session state.
Why this happens
The server's read-only control relies on query handling that does not reliably constrain the statements sent to PostgreSQL. Executing unrecognized input without bind parameters can select the simple query protocol, which accepts multiple statements; session state changes may also outlive a request when a connection is pooled. This is associated with CWE-89: Improper Neutralization of Special Elements used in an SQL Command and CWE-693: Protection Mechanism Failure: the query boundary and read-only safeguard do not adequately enforce the intended policy.
Potential impact
- A caller may perform database writes when the connected role has write privileges.
- Database records or other writable state could be altered, affecting integrity.
- Persistent session changes could make later pooled calls writable.
- Database availability could be affected by unauthorized changes or disruptive operations.
- Confidentiality impact is not increased beyond the reads already permitted by the connection.
General mitigation guidance
Defensive patterns should make the database enforce read-only behavior rather than relying solely on an application-side flag. Use a least-privilege database role that lacks write permissions for read-only operations, and constrain accepted query forms to the intended use.
Other useful patterns include rejecting multi-statement input where it is not required, avoiding execution paths that select a more permissive query protocol, and resetting or discarding pooled connections when session state may have changed. Treat client-supplied query text as untrusted, and keep database privileges limited to the minimum needed.
How teams detect issues like this
Review query execution paths for calls made without bind parameters, handling of unrecognized statements, and assumptions that a read-only application flag enforces database permissions. Check whether multiple statements are accepted and whether pooled connections are reset after requests.
Static analysis and code review can flag dynamic SQL execution and weak read-only checks. Runtime policy enforcement can also verify that read-only service roles lack write privileges and that query interfaces reject unsupported statement forms.

