[fix](fe) Fix Ranger column-level privilege bypass when CTE combined …#61741
[fix](fe) Fix Ranger column-level privilege bypass when CTE combined …#61741smith1000 wants to merge 2 commits intoapache:masterfrom
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
add test please |
|
sure |
…with JOIN ### What problem does this PR solve? Issue Number: close apache#61631 Problem Summary: When a CTE (WITH ... AS) is referenced multiple times in a JOIN query and is not inlined (due to inlineCTEReferencedThreshold), the CheckPrivileges rule only runs once per statement because the privChecked flag is stored on StatementContext which is shared across all CascadesContext subtrees. After the outer query's CascadesContext marks privChecked=true, the CTE producer subtree's CascadesContext skips privilege checking entirely, allowing users without column-level access to bypass Ranger authorization. The fix moves the privChecked flag from StatementContext to CascadesContext, ensuring each subtree (including CTE producer subtrees) performs its own independent privilege check. ### Release note Fixed a security issue where Ranger column-level privileges could be bypassed when using CTE (WITH ... AS) combined with JOIN queries. Users without proper column access permissions could read restricted columns through CTE+JOIN patterns. ### Check List (For Author) - Test: Manual test (verified with Ranger 2.7.0 + Doris 4.0.3 environment) - Behavior changed: No - Does this need documentation: No
Add test cases to TestCheckPrivileges to verify that column-level privileges are properly enforced when CTE is referenced multiple times via JOIN. The CTE won't be inlined due to inlineCTEReferencedThreshold, exercising the per-CascadesContext privilege checking path. Test scenarios: - CTE + LEFT JOIN on fully-privileged table (should succeed) - CTE + LEFT JOIN accessing restricted column (should be denied) - CTE + LEFT JOIN accessing only allowed columns (should succeed) - CTE + INNER JOIN accessing restricted column (should be denied)
214c8ba to
cd94a32
Compare
|
@morrySnow Test cases added. Please take a look |
|
Hi, @smith1000, It is expected that the entire query statement checks permissions only once, which helps prevent redundant permission checks. In addition, placing the permission flag in the StatementContext is intentional. Consider this scenario: a user has access to view_a, but does not have access to table_b inside view_a. In this case, two CascadeContexts are generated—one for the scope outside view_a, and one for the scope inside view_a. The expected behavior is that if the user has access to view_a, they can bypass the permission check on table_b and query it through the view. This requirement implies that the permission information needs to be shared in a common place (i.e., StatementContext). Therefore, for this issue, the expected behavior is to traverse the outermost query. If a CTE reference is encountered, the traversal should continue into the CTE to perform a complete permission check. Once the entire traversal is finished, the StatementContext should be marked as having completed the permission check. |
|
/review |
Code Review SummaryVerdict: No issues found. The change is correct, minimal, and well-tested. Change OverviewThis PR fixes a security bug (Ranger column-level privilege bypass with CTE+JOIN) by moving the Critical Checkpoint Conclusions
|
|
hi, @924060929 , |
What problem does this PR solve?
Issue Number: close #61631
Problem Summary: When a CTE (WITH ... AS) is referenced multiple times in a
JOIN query and is not inlined (due to inlineCTEReferencedThreshold), the
CheckPrivileges rule only runs once per statement because the privChecked flag
is stored on StatementContext which is shared across all CascadesContext
subtrees. After the outer query's CascadesContext marks privChecked=true,
the CTE producer subtree's CascadesContext skips privilege checking entirely,
allowing users without column-level access to bypass Ranger authorization.
The fix moves the privChecked flag from StatementContext to CascadesContext,
ensuring each subtree (including CTE producer subtrees) performs its own
independent privilege check.
Release note
Fixed a security issue where Ranger column-level privileges could be bypassed
when using CTE (WITH ... AS) combined with JOIN queries. Users without proper
column access permissions could read restricted columns through CTE+JOIN
patterns.
Check List (For Author)