Summary
psqlODBC can build SQL statements with an auto-increment column name without escaping embedded double quotes. If an attacker can influence that column name in a table read through an updatable cursor, the altered statements may change which rows the application updates or deletes.
Affected context
The issue occurs when psqlODBC uses an updatable cursor on a table without OIDs that has an auto-increment int4 column. The server-reported column name is inserted into generated keyset queries and positioned SELECT, UPDATE, and DELETE statements. A name containing a double quote can alter the resulting SQL because the quote is not escaped.
Exploit preconditions
- Attack surface: Database metadata used to construct driver-generated SQL for an updatable cursor
- Required access: Ability to create a table that the application reads with an updatable cursor, or a database server that is not trusted under the active SSL settings
- Trigger point: The driver runs keyset queries or a positioned SELECT, UPDATE, or DELETE for a qualifying table
- Why exploitation is possible: The column name is quoted but embedded double quotes are not doubled before it is included in SQL
Why this happens
The driver places a server-reported identifier inside a quoted SQL identifier without escaping embedded double quotes. This can break out of the intended identifier boundary and change the meaning of the generated statement. This is CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Potential impact
- An attacker could alter the conditions of driver-generated SQL statements.
- Positioned UPDATE or DELETE operations may affect rows beyond those intended by the application.
- Data integrity could be compromised using the application's database privileges.
General mitigation guidance
Defensive patterns focus on ensuring identifiers cannot change the meaning of generated SQL.
- Escape identifier delimiters according to the database's identifier-quoting rules, or use safe identifier-quoting APIs.
- Prefer parameterized statements for values and keep identifier handling separate, since ordinary value parameters do not generally substitute for identifiers.
- Reduce trust in database metadata when it comes from user-controlled tables or servers outside the configured trust boundary.
- Limit the privileges of database accounts used by applications and restrict which tables they can modify.
How teams detect issues like this
- Use static analysis to identify SQL construction that inserts database-reported identifiers into statements without identifier-specific escaping.
- Review cursor and query-building code for consistent handling of embedded identifier delimiters across SELECT, UPDATE, and DELETE paths.
- Add tests that verify identifiers containing quote characters cannot alter generated statement structure.
- Enforce code-review or CI policies requiring approved identifier-quoting APIs for dynamically constructed SQL.

