Skip to content

Security: SQL injection risk in materialized view management templates#801

Open
tuanaiseo wants to merge 1 commit intouselotus:mainfrom
tuanaiseo:contribai/fix/security/sql-injection-risk-in-materialized-view-
Open

Security: SQL injection risk in materialized view management templates#801
tuanaiseo wants to merge 1 commit intouselotus:mainfrom
tuanaiseo:contribai/fix/security/sql-injection-risk-in-materialized-view-

Conversation

@tuanaiseo
Copy link
Copy Markdown

Problem

Templates for DROP MATERIALIZED VIEW, ALTER MATERIALIZED VIEW, and policy creation interpolate cagg_name directly into SQL statements. If cagg_name is influenced by external input, this enables SQL injection in DDL statements.

Severity: high
File: backend/metering_billing/aggregation/common_query_templates.py

Solution

Treat object names as untrusted. Build statements using safe identifier composition (e.g., psycopg SQL Identifier) and enforce a strict naming allowlist/regex before use.

Changes

  • backend/metering_billing/aggregation/common_query_templates.py (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

Templates for `DROP MATERIALIZED VIEW`, `ALTER MATERIALIZED VIEW`, and policy creation interpolate `cagg_name` directly into SQL statements. If `cagg_name` is influenced by external input, this enables SQL injection in DDL statements.

Affected files: common_query_templates.py

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
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