Repository navigation
fix(charts): type-aware datasource access parity for the chart list - #43848
aminghadersohi merged 7 commits into
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #43848 +/- ##
=======================================
Coverage 80.41% 80.42%
=======================================
Files 2932 2932
Lines 174621 174663 +42
Branches 40559 40565 +6
=======================================
+ Hits 140422 140467 +45
+ Misses 31532 31530 -2
+ Partials 2667 2666 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
868f550 to
ec9d554
Compare
The chart list's dataset-access fallback inner-joined Slice.datasource_id == SqlaTable.id with no datasource_type predicate, failing in both directions for charts on non-table datasource types: semantic-view charts were dropped from the list for users holding the view's (or its parent layer's) datasource_access grant, and the type-less join could bind a semantic-view chart to an unrelated table sharing its numeric id, leaking it to holders of the colliding table's database grant (SC-119500; the dashboard-side siblings were fixed in apache#43781). - table_backed_slice_join in utils/filters.py is the single authoritative type-guarded ON-clause (FR-004); DashboardAccessFilter and ChartFilter both consume it - ChartFilter branch C: outer type-guarded joins + the semantic-layer grant clause, mirroring DashboardAccessFilter (FR-002); access matches through the perm columns denormalized by set_related_perm, uniformly across perm-carrying types - the dead _apply_legacy path (zero callers) is deleted, not fixed - get_dataset_access_filters grows named extra_access_clauses and an explicit include_all (deferred-in from the apache#43781 review round) - new contract-matrix regression file pins every grant x type cell, including the id-collision control Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Dashboard.has_member_datasource compares (datasource_type, datasource_id) pairs — zero queries, immune to numeric-id collisions — and both drill consumers use it instead of the table-shaped Dashboard.datasources set, whose members never include semantic views (FR-005; membership was vacuously false, and the id-set variant could match a colliding non-member table). Dashboard.datasources itself is unchanged for its export/thumbnail consumers. The embedded-guest datasets allowlist behaviour for non-table member charts is pinned by tests as the decided fail-closed semantic (FR-006): the allowlist is dataset-id space, so a semantic-view member chart is denied even when the token allowlists its colliding numeric id. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Three-lens round (clean-code, tidy-first, python) over the parity change: - extract the semantic-view sibling helpers (semantic_view_slice_join, semantic_view_layer_join, semantic_layer_grant_clause) so the other type-guarded join and the layer grant clause also have exactly one definition across both list filters (the round's converged MEDIUM) - get_dataset_access_filters: include_all now returns an explicit always-true clause early, skipping the grant lookups; clauses list keeps the ColumnElement[bool] typing end-to-end - has_member_datasource: named locals, documented duck-typing posture and the int-id comparison semantics (string-id explorables fail closed) - can_drill_dataset_via_dashboard_access: parameter renamed to datasource to match its widened type - chart filter documents the deliberate include_all asymmetry with the dashboard filter; test docstrings corrected (all_datasource_access is the apply() early return, not the fallback); extra-clause unit pin now asserts OR-composition Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
ec9d554 to
c5eea02
Compare
|
The flagged security issue is correct. The code changes implement type-aware outer joins to ensure that charts on non-table datasources (like semantic views) are correctly included in visibility filters. Because these joins are outer joins, they can include rows where the datasource has been deleted, potentially leaving stale No further code changes are required to resolve this specific issue, as the existing object-level gate provides the necessary security enforcement. superset/charts/filters.py |
Code Review Agent Run #97d5f9Actionable Suggestions - 0Additional Suggestions - 3
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
aminghadersohi
left a comment
There was a problem hiding this comment.
Net security improvement, verified by reverting only the production files: 11 tests flip, including the collision-rejection cases. Blocking for merge, not review: the branch conflicts with master and needs a rebase.
| # denormalized onto Slice by ``set_related_perm``. A chart whose | ||
| # datasource row is hard-deleted can still match its stale | ||
| # denormalized perm here; the object gate stays authoritative | ||
| # and denies (accepted edge, shared with the dashboard filter). |
There was a problem hiding this comment.
Slice.perm can't match after an ORM delete: dataset_after_delete drops the datasource_access PVM and hard_delete fires it per row. The reachable residual is schema_perm/catalog_perm, which survive deletion — worth narrowing this comment and pinning it with a test.
There was a problem hiding this comment.
Agreed — narrowed in 8a5bd06f91. The comment now names schema_perm / catalog_perm explicitly and qualifies this as the table ORM-delete case, rather than implying a stale Slice.perm can match after the PVM is dropped.
Added a lifecycle test covering it end to end: the dataset grant disappears on delete, the schema/catalog list match remains, and the datasource-based object gate denies. That pins the narrower residual you identified instead of the mechanism originally described.
| # explorable with a string id never matches the integer | ||
| # ``datasource_id`` column, which is likewise fail closed. | ||
| candidate_type = getattr(datasource, "type", None) | ||
| candidate_id = datasource.id |
There was a problem hiding this comment.
Docstring says an object with no id is "simply no member — fail closed", but direct attribute access raises AttributeError instead. type above already uses getattr; make id symmetric.
| candidate_id = datasource.id | |
| candidate_id = getattr(datasource, "id", None) |
There was a problem hiding this comment.
Good catch — the docstring promised "no id is simply no member, fail closed" while direct attribute access raised AttributeError instead.
Took your suggestion in 8a5bd06f91 with an explicit local annotation, and added a missing-id regression that raised AttributeError before the change and returns False now.
UPDATING.md keeps both entries. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EA4MGEkUcDpyLReqjQBhPy
aminghadersohi
left a comment
There was a problem hiding this comment.
Re-reviewed at 0cde1cf: the round-1 merge blocker is cleared — the branch is even with master and mergeable, and neither merge commit changed any PR-owned code. The two open threads on charts/filters.py and models/dashboard.py are unchanged.
Answer PRRT_kwDOAlosUs6gwOhy by naming the schema/catalog grants that survive table ORM deletion and pinning their list/object access behavior with real permission lifecycle tests. Dataset datasource_access grants are removed, so the comment must not imply they survive deletion. Answer PRRT_kwDOAlosUs6gwOh0 by safely reading a duck-typed datasource id so dashboard membership returns False instead of raising AttributeError. Add a regression test verified by reverting and restoring the guard.
aminghadersohi
left a comment
There was a problem hiding this comment.
Verified at 8a5bd06 by execution, not by reading the replies: the missing-id guard returns False (reverting it reds only the new regression), and the deletion residual is pinned — schema/catalog grants list the orphan, the object gate denies it against a known-allow control.
Code Review Agent Run #b435d1Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Resolve the sole conflict by retaining both cast and TYPE_CHECKING imports. Add explicit annotations to new branch variables to satisfy the required Python review; no behavior changes.
…43848) Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Mike Bridge <[email protected]> (cherry picked from commit e4bbd39)
SUMMARY
Chart-side transplant of the type-aware datasource access pattern from #43781 (SC-111233), closing SC-119500.
ChartFilter's dataset-access fallback — the only reachable list path — inner-joinedSlice.datasource_id == SqlaTable.idwith nodatasource_typepredicate, failing in both directions for charts on non-table datasource types:datasource_accessgrant (or its parent semantic layer's, per the layer fallback shipped in fix(dashboard): resolve chart datasources across types in access checks #43781) never saw those charts in the chart list — even though the object gate admits them when opened directly;SqlaTablesharing its numeric id, listing the chart to users entitled only to the colliding table's database (the same id-collision class as SC-111089 / fix(dashboard): resolve display-control and drill datasources by type, not id alone #42539, and the exact leak fix(dashboard): resolve chart datasources across types in access checks #43781 closed for dashboards).What this PR does:
table_backed_slice_joininsuperset/utils/filters.py): the single authoritative ON-clause consumed by bothDashboardAccessFilterandChartFilter, so the id-collision constraint cannot drift between the filters.ChartFilterbranch C reshape: outer, type-guarded joins; access matches through the perm columns denormalized ontoSlicebyset_related_perm, uniformly across perm-carrying datasource types (no per-type allowlist; NULL-perm rows can never match). Includes the semantic-layer grant clause, mirroring the dashboard filter._apply_legacydeleted: zero callers (ChartFilter.applyroutes every request through_apply_viewersregardless ofENABLE_VIEWERS); deleting rather than fixing keeps exactly one definition of the access path.Dashboard.has_member_datasource): compares(datasource_type, datasource_id)pairs — zero queries, collision-immune by construction. Both drill consumers (can_drill_dataset_via_dashboard_access,has_drill_access) use it instead of the table-shapedDashboard.datasourcesset (whose export/thumbnail consumers are untouched). No user-visible drill change today (semantic views ship with drill disabled); this makes the membership primitive correct before any provider enables it.datasetsallowlist still denies a semantic-view member chart — now asserted by tests as the decided fail-closed semantic (the allowlist is dataset-id space; resolving other types into it would reintroduce id ambiguity), with a companion control showing the same token admits the table chart whose id it names.get_dataset_access_filterssignature:*args: Anybecomes named*extra_access_clauseswith an explicitinclude_allkeyword (deferred-in from the fix(dashboard): resolve chart datasources across types in access checks #43781 review round).Stacked on #43781— #43781 has merged; this branch is now rebased directly onto master and contains only its own three commits.Review round (clean-code + tidy-first + python lenses, report in the campaign's spec repo): all three verdicts ship, 0 blocker / 0 high. The converged finding — the semantic-view/layer join block deserved the same single-definition extraction as the table join — plus eight polish items landed in the review-polish commit (
semantic_view_slice_join/semantic_view_layer_join/semantic_layer_grant_clausehelpers,include_allearly return, membership-helper readability + id semantics, param rename, test-precision fixes).Two planned tidyings were deliberately skipped and stay as commented accepted costs: deduping the double
datasource_accessperm fetch (would changeget_dataset_access_filters' contract for its four other callers — belongs to a dedicated rework if it ever pays for itself) and extracting_no_viewer_fallback_query(no natural seam materialized in the reshape).Reverted-fix control (with
superset/stashed, the new contract tests flip — both defect directions demonstrated):BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — list-visibility change; the contract matrix in
tests/unit_tests/charts/semantic_view_chart_filter_test.pyis the behavioural spec.TESTING INSTRUCTIONS
Manual: as a scoped user with no DAR grants the chart list shows no semantic-view charts; grant
datasource_accesson a semantic view (or its parent layer) → its charts appear in/chart/list/; a user granted only database access to a database containing a table that shares a semantic view's numeric id does not see that view's charts;all_datasource_accesssees everything.ADDITIONAL INFORMATION
ChartFilter._apply_legacy, no callers)🤖 Generated with Claude Code
https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW