Skip to content

fix(spanner): escape identifier delimiters and validate table names - #19052

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-escape-identifiers
Open

olavloite wants to merge 1 commit into
mainfrom
spanner-escape-identifiers

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Harden table and schema identifier handling against SQL injection when inspecting table schemas.

Previously, identifiers were wrapped in backticks or double quotes without escaping embedded delimiter characters, which could allow maliciously crafted table names to break out of identifier boundaries in schema queries.

This change:

  • Escapes backticks and backslashes for GoogleSQL databases.
  • Escapes double quotes for PostgreSQL databases.
  • Rejects control characters (such as newlines and null bytes) upfront.
  • Validates that identifiers are non-empty strings.
  • Gracefully handles empty schema names for PostgreSQL databases.

@olavloite
olavloite requested a review from a team as a code owner November 12, 2026 09:03

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Table class in the Google Cloud Spanner client library to improve identifier quoting and validation. Specifically, it simplifies schema name initialization, updates qualified_table_name to use f-strings, and enhances _quote_identifier to validate input types, check for empty values or control characters, and properly escape quotes and backslashes according to the database dialect (Google Standard SQL vs. PostgreSQL). Additionally, comprehensive unit tests have been added to cover these validation and escaping scenarios. I have no feedback to provide as the changes are well-implemented and thoroughly tested.

Harden table and schema identifier handling against SQL injection when
inspecting table schemas.

Previously, identifiers were wrapped in backticks or double quotes without
escaping embedded delimiter characters, which could allow maliciously crafted
table names to break out of identifier boundaries in schema queries.

This change:
- Escapes backticks and backslashes for GoogleSQL databases.
- Escapes double quotes for PostgreSQL databases.
- Rejects control characters (such as newlines and null bytes) upfront.
- Validates that identifiers are non-empty strings.
- Gracefully handles empty schema names for PostgreSQL databases.
@olavloite
olavloite force-pushed the spanner-escape-identifiers branch from 4fa10a5 to cdea5ab Compare November 12, 2026 09:11

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.

1 participant