Skip to content

fix(sqlalchemy-spanner): parameterize information_schema reflection queries - #19236

Merged
olavloite merged 2 commits into
mainfrom
spanner-sqlalchemy-parameterize-reflection-queries
Nov 26, 2026
Merged

olavloite merged 2 commits into
mainfrom
spanner-sqlalchemy-parameterize-reflection-queries

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Previously, schema, table, view, sequence, and filter names passed to SQLAlchemy reflection methods were interpolated directly into information_schema queries using string formatting. If untrusted identifiers were passed to reflection APIs, those values could alter the generated SQL queries.

This change updates all information_schema reflection queries in the Spanner dialect to use bound GoogleSQL parameters instead of string interpolation:

  • Schema, table, view, and sequence names are normalized and passed as string query parameters.
  • Multi-table filter lists are passed as a single string array parameter using UNNEST, keeping query text constant and preserving query plan caching while short-circuiting empty filter lists.
  • Reflection helpers and tests have been updated accordingly, including unit tests for parameter binding, mock server gRPC tests verifying serialized query parameters, and Spanner Emulator system tests confirming real queries execute safely against injection-style inputs.

…ueries

Previously, schema, table, view, sequence, and filter names passed to
SQLAlchemy reflection methods were interpolated directly into
information_schema queries using string formatting. If untrusted
identifiers were passed to reflection APIs, those values could alter the
generated SQL queries.

This change updates all information_schema reflection queries in the
Spanner dialect to use bound GoogleSQL parameters instead of string
interpolation:

- Schema, table, view, and sequence names are normalized and passed as
  string query parameters.
- Multi-table filter lists are passed as a single string array parameter
  using UNNEST, keeping query text constant and preserving query plan
  caching while short-circuiting empty filter lists.
- Reflection helpers and tests have been updated accordingly, including
  unit tests for parameter binding, mock server gRPC tests verifying
  serialized query parameters, and Spanner Emulator system tests
  confirming real queries execute safely against injection-style inputs.
@olavloite
olavloite requested a review from a team as a code owner November 26, 2026 09:06

@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 metadata reflection methods in the Cloud Spanner SQLAlchemy dialect to use parameterized SQL queries instead of string formatting, effectively preventing potential SQL injection vulnerabilities. It introduces helper methods for parameter normalization and query preparation, and updates the mock server and test suites to validate parameter binding and SQL injection prevention. I have no additional feedback to provide as there are no review comments.

@olavloite
olavloite enabled auto-merge (squash) November 26, 2026 17:10
@olavloite
olavloite merged commit 9df7e1d into main Nov 26, 2026
84 of 85 checks passed
@olavloite
olavloite deleted the spanner-sqlalchemy-parameterize-reflection-queries branch November 26, 2026 17:19
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