Skip to content

[10.0] Quote names and option values in replication commands - #6737

Open
Brar wants to merge 2 commits into
npgsql:hotfix/10.0.4from
Brar:repl/quoting-10.0
Open

Brar wants to merge 2 commits into
npgsql:hotfix/10.0.4from
Brar:repl/quoting-10.0

Conversation

@Brar

@Brar Brar commented Nov 1, 2026

Copy link
Copy Markdown
Member

Backport of #6707 to 10.0: its squash commit e87d421, cherry-picked without conflicts, plus one commit for 10.0: Set_Schemas_with_backslashes returns early with multiplexing, which requires standard_conforming_strings to be on (main no longer has multiplexing).

What changes on 10.0, as on main:

  • Replication commands send slot and plugin names as quoted identifiers, trimmed and with A-Z lowercased the way the server read them unquoted, so existing names keep their meaning; names the caller already quoted and identifiers with non-ASCII letters are sent as they are. Valid slot names starting with a digit now work, and no name can add keywords to a command.
  • Option values are literals with their quotes doubled, and publication_names is a list of quoted identifiers, so quotes in values and publication names no longer break the command. Callers who escaped such quotes themselves must stop doing so.
  • StartLogicalReplication rejects pgoutput's proto_version and publication_names without a value, which crash the walsender (PostgreSQL bug #19795), and pgoutput with an emptied publication list throws before anything is sent.
  • Type loading reads schema names with backslashes correctly when standard_conforming_strings is off.
  • Savepoint names, the named arguments of stored procedure calls and the GIDs of two-phase commits go through the same helpers and send the same SQL as before. No API change.

Tests

On hotfix/10.0.4, against PostgreSQL 18.6:

  • With the branch's own source and the backported tests, 15 of the 29 live tests fail: the slots whose names start with a digit, the publication names, the null option name, the pgoutput options without a value, the emptied publication list and the schemas with backslashes.
  • With the backport, they pass, and so do the QuotingTests: 54 of 54, in Debug and Release.

Brar and others added 2 commits November 1, 2026 14:23
Replication commands sent slot and plugin names unquoted and wrapped
option values and publication names in quotes without escaping them, so
valid slot names starting with a digit failed, a name could add keywords
to a command (x TEMPORARY, x WAIT), and quotes in option values or
publication names broke it. Names are now sent as quoted identifiers,
trimmed and with A-Z lowercased the way the server reads unquoted names;
pre-quoted names and identifiers with non-ASCII letters are sent as they
are. Option values are literals, and publication_names is a list of
quoted identifiers.

pgoutput's proto_version and publication_names are rejected without a
value, which crashes the walsender (BUG #19795), and an emptied
publication list is rejected before anything is sent.

The quoting helpers are in Statics and also quote savepoint names, the
named arguments of stored procedure calls, the schema list of the type
loading and two-phase GIDs. For SQL, a literal with backslashes becomes
an escape string (E'...'), which fixes type loading schema names with
backslashes under standard_conforming_strings off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e87d421)
On 10.0 the connection tests also run with multiplexing, which requires
standard_conforming_strings to be on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 1, 2026 13:40
@Brar
Brar requested review from roji and vonzshik as code owners November 1, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The plugin-name check misses valid shared-library forms such as pgoutput.so, allowing null replication options to reach vulnerable server code and potentially crash the walsender.

1 open issue
What changed in this PR

Backports replication-command quoting fixes to Npgsql 10.0 and centralizes quoting helpers used elsewhere in SQL generation.

Changes:

  • Quotes replication names and option values, including publication-name lists.
  • Adds validation for missing pgoutput option values and empty publication lists.
  • Fixes schema-name escaping and adds regression tests, with a multiplexing-specific exclusion.
File Description
test/​Npgsql.Tests/​Replication/​ReplicationQuotingTests.cs Adds replication quoting and option-validation tests.
test/​Npgsql.Tests/​QuotingTests.cs Tests shared quoting helpers.
test/​Npgsql.Tests/​ConnectionTests.cs Tests schema backslashes with nonstandard string handling.
src/​Npgsql/​VolatileResourceManager.cs Quotes two-phase transaction identifiers as literals.
src/​Npgsql/​Util/​Statics.cs Adds shared name, identifier, and literal quoting helpers.
src/​Npgsql/​Replication/​ReplicationConnection.cs Quotes slot names in read and drop commands.
src/​Npgsql/​Replication/​PhysicalReplicationConnection.cs Quotes physical slot names and rejects null names.
src/​Npgsql/​Replication/​PgOutput/​PgOutputReplicationOptions.cs Escapes publication names and rejects empty lists.
src/​Npgsql/​Replication/​Internal/​LogicalReplicationConnectionExtensions.cs Quotes logical replication arguments and validates options.
src/​Npgsql/​PostgresDatabaseInfo.cs Handles backslashes in type-loading schema literals.
src/​Npgsql/​NpgsqlTransaction.cs Reuses identifier quoting for savepoints.
src/​Npgsql/​NpgsqlCommand.cs Reuses identifier quoting for named procedure arguments.

Review effort: Balanced

@Brar
Brar requested a balanced review from Copilot November 1, 2026 13:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the replication quoting and schema-handling backport.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants