Repository navigation
Conversation
queryStatementSource names a relation, so it is interpolated into the FROM clause of the query-history SQL rather than bound as a parameter. f669f7d (#33477) added validate_query_statement_source and wired it into both Postgres call sites, but the Timescale copies in timescale/connection.py (the live Test Connection path) and timescale/query_parser.py (a dead copy that TimescaleUsageSource / TimescaleLineageSource no longer import) kept interpolating the raw, user-controlled value, leaving the rest of the statement open to being rewritten via UNION SELECT / file-read functions at test-connection time. Route both Timescale call sites through validate_query_statement_source, mirroring postgres/connection.py:188 and postgres/query_parser.py:75.
…tementsource-in-times-61bf12
Collaborator
|
Can you check the pushed commit and review it? |
Contributor
Author
|
Re: #38052 (comment) Reviewed the pushed commit
LGTM. No changes needed from me. |
IceS2
enabled auto-merge (squash)
November 27, 2026 10:56
IceS2
approved these changes
Nov 27, 2026
Khairajani
approved these changes
Nov 27, 2026
IceS2
deleted the
detail/bug-fix/fixes-38024-validate-querystatementsource-in-times-61bf12
branch
November 27, 2026 11:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detail bug report: View on Detail
Describe your changes:
Fixes #38024
I hardened the Timescale
queryStatementSourcehandling against SQL injection by routing it through the existingvalidate_query_statement_sourcevalidator (added topostgres/utils.pyby #33477 for the Postgres call sites). The Timescale copies had been left interpolating the raw, user-controlled value into theFROMclause of the query-history SQL, so a user who could edit a Timescale service connection could execute arbitrary SQL against the target database at Test Connection time (e.g.pg_stat_statements) UNION SELECT rolname, rolpassword FROM pg_authid --).Type of change:
High-level design:
N/A — small change. The fix mirrors the Postgres hardening already shipped in #33477 at
postgres/connection.py:188andpostgres/query_parser.py:75:ingestion/src/metadata/ingestion/source/database/timescale/connection.py— the live attack surface:TimescaleConnection.test_connectionbuilds theGetQueriesprobe thattest_connection_db_commonruns against the configured ingestion DB user. Replaced the rawself.service_connection.queryStatementSource or "pg_stat_statements"withvalidate_query_statement_source(self.service_connection.queryStatementSource)in thePOSTGRES_TEST_GET_QUERIES.format(...)call.ingestion/src/metadata/ingestion/source/database/timescale/query_parser.py— the dead copy inPostgresQueryParserSource.get_sql_statement. The module is not imported anywhere today (TimescaleUsageSource/TimescaleLineageSourceinherit the validatedPostgresQueryParserSourcefrompostgres/query_parser.py), but the same fix prevents the flaw from silently regaining effect if it is ever re-registered.The validator constrains the value to an optionally schema-quoted relation identifier (matching
pg_stat_statements,my_schema.custom_pg_stat_statements,"Audit Schema"."Query Log", …) and raisesValueErrorfor anything else, so it can no longer close the relation and appendUNION SELECT/--etc.Tests:
Use cases covered
queryStatementSource(the two bug-report exploits —pg_authidUNION andpg_stat_filefile-read — plus the Postgres validator's existing rejection set) raisesValueError("Invalid queryStatementSource ...")attimescale/connection.py:71beforetest_connection_db_commonis invoked, so no SQL reaches the database.timescale/query_parser.py::get_sql_statementcopy (defense-in-depth).NonequeryStatementSourcefalls back toDEFAULT_QUERY_STATEMENT_SOURCE(pg_stat_statements) at both call sites — benign deployments that never set the field still work.FROMclause unchanged, preserving the documented custom-view support.Unit tests
ingestion/tests/unit/topology/database/test_timescale_query_statement_source.py(51 parametrized cases: 17 injection payloads × 2 call sites that must raise; valid-identifier pass-through; empty fallback; and wiring guards that assert each call site routes throughvalidate_query_statement_source).validate_query_statement_source100% covered, both new Timescale call sites fully covered across empty/valid/malicious branches. Module-level line coverage fromnox -s unit-testsfor the two files:timescale/connection.py71%,timescale/query_parser.py44% (the uncovered lines are the auth-strategy dispatch and the live-DBget_table_querystream, neither of which the fix touches).Backend integration tests
Ingestion integration tests
tests/integration/. The fix touches two source modules underingestion/src/metadata/ingestion/source/database/timescale/; the connector's integration suite (tests/integration/source/timescale/) is the relevant broader set and would run in the merge queue.Playwright (UI) tests
Visual regression baselines
Manual testing performed
I drove
TimescaleConnection.test_connection— the exact Python entry point the UI "Test Connection" button and a test-connection automation workflow dispatch to via Airflow — end-to-end against a live Postgres 16 container with statement logging enabled:log_statement = 'all'+logging_collector = on, and created a custom viewmy_schema.custom_pg_stat_statementswith the expected columns for the happy-path step.TimescaleConnectionservice config pointing at the live DB with the maliciousqueryStatementSource = "pg_stat_statements) UNION SELECT rolname, rolpassword FROM pg_authid --"and calledtest_connection(metadata=...)(with a stubbedOpenMetadata.get_by_namereturning the seeded TimescaleTestConnectionDefinition).ValueErrorattimescale/connection.py:71;test_connection_db_commonwas not invoked; the postgres log had zero matches forpg_authid/UNION SELECT rolname.pg_stat_file('/tmp/pwned')): same behavior —ValueErrorattimescale/connection.py:71, no SQL reached the DB.queryStatementSource):test_connectionreturned; all mandatory steps passed against the live DB;GetQueriesreached the DB and cleanly failed with the documented42P01 undefined_table(relation "pg_stat_statements" does not exist) — not a validation error.my_schema.custom_pg_stat_statements): the validator accepted the schema-qualified identifier and the custom-view SQL actually executed against the DB; all 7 test-connection steps passed.I also started the OpenMetadata Java server against a Dockerized MySQL 8.0 + Elasticsearch 9.3 stack (after working around an ES 8.11
media_type_header_exceptionby upgrading to 9.3 and a QuartzUnknownHostExceptionby adding the sandbox hostname to/etc/hosts), logged in as admin, and verified viaPUT /api/v1/services/databaseServicesthat the server accepts and stores the maliciousqueryStatementSourcein a Timescale service config verbatim (HTTP 200, value preserved) — confirming the server-side tier does not validate the SQL field; validation lives in the Python ingestion worker that Airflow runs, which is exactly the layer the fix patches and the manual steps above exercised.The full UI-button → Airflow worker → DB chain was not exercised:
POST /api/v1/automations/workflowsrejected my hand-craftedTestConnectionworkflow payload withHTTP 400 Invalid request format(the polymorphicrequestfield needs a discriminator the generated TypeScript client produces but my curl did not), and the Noop Airflow client used for the boot would not have run a dispatched workflow anyway. Both UI exit points dispatch to the sameTimescaleConnection.test_connectionmethod exercised above and asserted-against in the unit test's wiring checks.UI screen recording:
Not applicable — backend-only ingestion security fix; no UI changes.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.Automatic Fixes PRs can be configured here.


Confidence Score: 5/5
The PR appears safe to merge; the previous finding is fixed and no new issues were found.Summary
The PR routes Timescale query-history relation names through the existing Postgres validator. The follow-up removes wiring-only tests while keeping checks for rejected SQL payloads, default values, and valid custom relation names.
Reviews (2) · Last reviewed commit: "Remove wiring-only tests asserting valid..." · Reviewed by Greptile