Skip to content

fix(security): prevent RLS bypass via subqueries - #10

Open
sha174n wants to merge 5 commits into
masterfrom
jules-9444043596758737189-6a47ff3b
Open

sha174n wants to merge 5 commits into
masterfrom
jules-9444043596758737189-6a47ff3b

Conversation

@sha174n

@sha174n sha174n commented Mar 4, 2026

Copy link
Copy Markdown
Owner

This commit addresses the reported vulnerability where users could inject malicious subqueries through Row-Level Security (RLS) filters.

Key changes:

  • Added validate_rls_clause to superset/models/helpers.py to ensure RLS fragments do not contain subqueries or DML mutations.
  • Upgraded SQLStatement.has_subquery inside superset/sql/parse.py to explicitly detect nested subqueries and DML statements (UPDATE, DELETE, INSERT, MERGE) via an AST walker.
  • Integrated the validation explicitly at the execution layer in superset/connectors/sqla/models.py (BaseDatasource.get_sqla_row_level_filters) for both standard and guest RLS rules.
  • Added API/Command-level validations in CreateRLSRuleCommand and UpdateRLSRuleCommand to ensure bad rules cannot be created in the first place.
  • Wrote clean, isolated unit tests in tests/unit_tests/sql/parse_tests.py verifying RLS clause parsing, to avoid flaky SQLite/Flask-integration tests.

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

Extracts logic from feat/rls-filter-parsing-improvement branch to correctly apply RLS clause validations. Addressed issues with running the logic by testing the newly extracted functions via isolated tests in parse_tests.py. Ensures no ad-hoc SQL query failures.

Co-authored-by: sha174n <105581038+sha174n@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 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.

google-labs-jules Bot and others added 2 commits March 4, 2026 19:29
This commit addresses a vulnerability where users could inject malicious subqueries through Row-Level Security (RLS) filters.

Key changes:
- Added validate_rls_clause to superset/models/helpers.py to ensure RLS fragments do not contain subqueries or DML mutations.
- Upgraded SQLStatement.has_subquery inside superset/sql/parse.py to explicitly detect nested subqueries and DML statements (UPDATE, DELETE, INSERT, MERGE) via an AST walker.
- Integrated the validation explicitly at the execution layer in superset/connectors/sqla/models.py (BaseDatasource.get_sqla_row_level_filters) for both standard and guest RLS rules.
- Added API/Command-level validations in CreateRLSRuleCommand and UpdateRLSRuleCommand to ensure bad rules cannot be created in the first place.
- Wrote unit tests in tests/unit_tests/sql/parse_tests.py verifying RLS clause parsing.

Co-authored-by: sha174n <105581038+sha174n@users.noreply.github.com>
This commit addresses a vulnerability where users could inject malicious subqueries through Row-Level Security (RLS) filters.

Key changes:
- Added validate_rls_clause to superset/models/helpers.py to ensure RLS fragments do not contain subqueries or DML mutations.
- Upgraded SQLStatement.has_subquery inside superset/sql/parse.py to explicitly detect nested subqueries and DML statements (UPDATE, DELETE, INSERT, MERGE) via an AST walker.
- Integrated the validation explicitly at the execution layer in superset/connectors/sqla/models.py (BaseDatasource.get_sqla_row_level_filters) for both standard and guest RLS rules.
- Added API/Command-level validations in CreateRLSRuleCommand and UpdateRLSRuleCommand to ensure bad rules cannot be created in the first place, and mapped RLSRuleInvalidError in row_level_security/api.py
- Wrote unit tests in tests/unit_tests/sql/parse_tests.py verifying RLS clause parsing.

Co-authored-by: sha174n <105581038+sha174n@users.noreply.github.com>
This commit fixes a vulnerability where administrators could embed
subqueries and DML statements into RLS filters, which could lead to
data leakage or manipulation. We enforce this validation using
`validate_rls_clause` in the `superset/connectors/sqla/models.py` layer and
in the security command/API validations.

It also introduces new robust AST-walking checks in `superset/sql/parse.py`
for specific AST node mutation types (UPDATE, DELETE, MERGE, INSERT)
that `sqlglot` classifies outside of typical `SELECT` or `COMMAND` structures.

Includes targeted unit tests ensuring RLS blocks subqueries correctly.

Co-authored-by: sha174n <105581038+sha174n@users.noreply.github.com>
This commit fixes a vulnerability where administrators could embed
subqueries and DML statements into RLS filters, which could lead to
data leakage or manipulation. We enforce this validation using
`validate_rls_clause` in the `superset/connectors/sqla/models.py` layer and
in the security command/API validations.

It also introduces new robust AST-walking checks in `superset/sql/parse.py`
for specific AST node mutation types (UPDATE, DELETE, MERGE, INSERT)
that `sqlglot` classifies outside of typical `SELECT` or `COMMAND` structures.

Includes targeted unit tests ensuring RLS blocks subqueries correctly.

Co-authored-by: sha174n <105581038+sha174n@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant