Skip to content

fix(security): prevent SQL injection in Postgres schema prequery - #4

Draft
google-labs-jules[bot] wants to merge 6 commits into
masterfrom
fix-postgres-schema-injection-4026538467311462713
Draft

google-labs-jules[bot] wants to merge 6 commits into
masterfrom
fix-postgres-schema-injection-4026538467311462713

Conversation

@google-labs-jules

Copy link
Copy Markdown

This PR fixes a reported SQL injection vulnerability where the schema parameter in SQL Lab execution was directly interpolated into a SET search_path query for Postgres databases.

Changes:

  • Modified superset/db_engine_specs/postgres.py to use database.quote_identifier(schema) instead of raw string interpolation.
  • Added a regression test case test_get_prequeries_injection in tests/unit_tests/db_engine_specs/test_postgres.py to verify that malicious payloads are correctly escaped.
  • Updated existing tests in tests/unit_tests/db_engine_specs/test_postgres.py to mock quote_identifier.

PR created automatically by Jules for task 4026538467311462713 started by @sha174n

Secures the `get_prequeries` method in `PostgresEngineSpec` by using `database.quote_identifier` to sanitize the schema name in the `SET search_path` statement. This prevents attackers from injecting arbitrary SQL via the schema parameter in SQL Lab.

Includes regression test in `tests/unit_tests/db_engine_specs/test_postgres.py`.
@google-labs-jules

Copy link
Copy Markdown
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Secures the `get_prequeries` method in `PostgresEngineSpec` by using `database.quote_identifier` to sanitize the schema name in the `SET search_path` statement. This prevents attackers from injecting arbitrary SQL via the schema parameter in SQL Lab.

Includes regression test in `tests/unit_tests/db_engine_specs/test_postgres.py`.
Secures the `get_prequeries` method in `PostgresEngineSpec` by using `database.quote_identifier` to sanitize the schema name in the `SET search_path` statement. This prevents attackers from injecting arbitrary SQL via the schema parameter in SQL Lab.

Includes regression test in `tests/unit_tests/db_engine_specs/test_postgres.py`.
Secures the `get_prequeries` method in `PostgresEngineSpec` by using `database.quote_identifier` to sanitize the schema name in the `SET search_path` statement. This prevents attackers from injecting arbitrary SQL via the schema parameter in SQL Lab.

Includes regression test in `tests/unit_tests/db_engine_specs/test_postgres.py`.
Secures the `get_prequeries` method in Postgres, IBM Db2, Databricks, and StarRocks engine specs.
Uses `database.quote_identifier` to sanitize user-controlled parameters (schema, catalog, username) in pre-session queries, preventing SQL injection.

Includes regression tests for all affected engines.
Secures the `get_prequeries` method in Postgres, IBM Db2, Databricks, and StarRocks engine specs.
Uses `database.quote_identifier` to sanitize user-controlled parameters (schema, catalog, username) in pre-session queries, preventing SQL injection.

Includes:
- Regression tests for all affected engines.
- A new meta-test (`test_security_regression.py`) that scans all engine specs to prevent future regressions.
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.

0 participants