Skip to content

fix(mcp): add permission checks to generate_dashboard and update_chart tools#38845

Merged
aminghadersohi merged 5 commits into
apache:masterfrom
aminghadersohi:amin/fix-mcp-permission-gaps
Mar 25, 2026
Merged

fix(mcp): add permission checks to generate_dashboard and update_chart tools#38845
aminghadersohi merged 5 commits into
apache:masterfrom
aminghadersohi:amin/fix-mcp-permission-gaps

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

@aminghadersohi aminghadersohi commented Mar 25, 2026

User description

SUMMARY

Fix two permission gaps in MCP tools:

  1. generate_dashboard: Previously checked chart existence but did NOT verify chart access permissions. Users could create dashboards containing charts they shouldn't have access to. Now calls security_manager.can_access_chart() after verifying charts exist, returning an error listing inaccessible chart IDs.

  2. update_chart: Previously did not validate dataset access before applying configuration changes. Users could update charts whose underlying dataset they cannot access. Now calls validate_chart_dataset(chart, check_access=True) after finding the chart, returning a structured DatasetNotAccessible error before any DB writes.

Both fixes reuse existing utilities (security_manager.can_access_chart and validate_chart_dataset) that are already used in other MCP tools like get_chart_info.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - backend-only changes

TESTING INSTRUCTIONS

  1. Run MCP unit tests:
    pytest tests/unit_tests/mcp_service/ -x
  2. Verify new tests pass:
    • test_generate_dashboard_inaccessible_charts - asserts error when user lacks chart access
    • test_update_chart_dataset_access_denied - asserts error when dataset is inaccessible
    • test_update_chart_dataset_not_found - asserts error when dataset is deleted
  3. Verify existing tests still pass (no regression):
    • test_generate_dashboard_basic and all other dashboard generation tests
    • All existing TestUpdateChart tests

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CodeAnt-AI Description

Block dashboard and chart updates when the user cannot access the underlying dataset

What Changed

  • Creating a dashboard now stops if any selected chart points to a dataset the user cannot view, and shows which chart is blocked.
  • Adding a chart to an existing dashboard now rejects charts whose dataset is not accessible.
  • Updating a chart now fails before saving changes when its dataset is inaccessible, with a clear dataset-access error instead of a generic failure.
  • Added test coverage for inaccessible and deleted datasets during chart updates, dashboard generation, and adding charts to dashboards.

Impact

✅ Fewer unauthorized dashboard creations
✅ Clearer dataset access errors
✅ Safer chart updates

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

…t tools

- generate_dashboard: Add chart access check via security_manager.can_access_chart()
  after verifying charts exist but before creating the dashboard
- update_chart: Add dataset access validation via validate_chart_dataset()
  after finding the chart but before applying configuration changes
- Add tests for both permission checks
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Mar 25, 2026

Code Review Agent Run #298c73

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 5f43620..5f43620
    • superset/mcp_service/chart/tool/update_chart.py
    • superset/mcp_service/dashboard/tool/generate_dashboard.py
    • tests/unit_tests/mcp_service/chart/tool/test_update_chart.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added authentication:access-control Rlated to access control change:backend Requires changing the backend labels Mar 25, 2026
@codeant-ai-for-open-source codeant-ai-for-open-source Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Mar 25, 2026
@codeant-ai-for-open-source
Copy link
Copy Markdown
Contributor

Sequence Diagram

This PR adds two pre-write authorization checks in MCP tools. Generate dashboard now blocks inaccessible charts, and update chart now blocks updates when the chart dataset is inaccessible or missing.

sequenceDiagram
    participant Client
    participant MCP
    participant SecurityManager
    participant DatasetValidator

    Client->>MCP: Call generate dashboard
    MCP->>SecurityManager: Check access for requested charts
    SecurityManager-->>MCP: Access result per chart
    alt Any chart inaccessible
        MCP-->>Client: Return access denied with chart ids
    else All charts accessible
        MCP-->>Client: Continue with dashboard creation flow
    end

    Client->>MCP: Call update chart
    MCP->>DatasetValidator: Validate chart dataset access
    DatasetValidator-->>MCP: Dataset validation result
    alt Dataset inaccessible or missing
        MCP-->>Client: Return DatasetNotAccessible error
    else Dataset accessible
        MCP-->>Client: Continue with chart update flow
    end
Loading

Generated by CodeAnt AI

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 10.52632% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.40%. Comparing base (7222327) to head (4c900f6).
⚠️ Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/chart/tool/update_chart.py 14.28% 6 Missing ⚠️
...t/mcp_service/dashboard/tool/generate_dashboard.py 0.00% 5 Missing ⚠️
.../dashboard/tool/add_chart_to_existing_dashboard.py 0.00% 4 Missing ⚠️
superset/mcp_service/auth.py 33.33% 2 Missing ⚠️

❌ Your project status has failed because the head coverage (99.85%) is below the target coverage (100.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #38845      +/-   ##
==========================================
- Coverage   65.54%   64.40%   -1.14%     
==========================================
  Files        1820     2535     +715     
  Lines       72868   130469   +57601     
  Branches    23339    30220    +6881     
==========================================
+ Hits        47758    84035   +36277     
- Misses      25110    44968   +19858     
- Partials        0     1466    +1466     
Flag Coverage Δ
hive 40.38% <10.52%> (?)
mysql 61.33% <10.52%> (?)
postgres 61.41% <10.52%> (?)
presto 40.40% <10.52%> (?)
python 63.01% <10.52%> (?)
sqlite 61.03% <10.52%> (?)
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Remove parentheses from @pytest.mark.asyncio() and @pytest.fixture()
decorators to comply with ruff 0.9.7 PT023 rule.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Mar 25, 2026

Code Review Agent Run #5534c5

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 5f43620..1876a3c
    • tests/unit_tests/mcp_service/chart/tool/test_update_chart.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

- Replace security_manager.can_access_chart() with validate_chart_dataset()
  in generate_dashboard for consistency with other MCP tools
- Add dataset access check to add_chart_to_existing_dashboard
- Narrow broad except Exception to specific exceptions in update_chart
- Add test for add_chart_to_existing_dashboard dataset access validation
- Update test mocks to use validate_chart_dataset instead of can_access_chart
OSS ruff 0.9.7 enforces no-parentheses style for @pytest.mark.asyncio
and @pytest.fixture decorators.
Copy link
Copy Markdown
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the RBAC system introduced in #38407 ? or extending it?

Copy link
Copy Markdown
Contributor

@bito-code-review bito-code-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #57d487

Actionable Suggestions - 1
  • superset/mcp_service/dashboard/tool/generate_dashboard.py - 1
    • Error handling regression in multi-chart validation · Line 236-245
Additional Suggestions - 1
  • superset/mcp_service/chart/tool/update_chart.py - 1
    • Narrow exception handling risks unhandled errors · Line 270-270
      The exception handling change narrows the catch from all Exception to specific types, which may allow unexpected exceptions to propagate instead of returning error responses. This differs from similar functions like generate_chart.py and changes observable behavior.
      Code suggestion
       @@ -267,2 +267,2 @@
      -        return GenerateChartResponse.model_validate(result)
      -    except (CommandException, ValueError, KeyError, AttributeError) as e:
      +        return GenerateChartResponse.model_validate(result)
      +    except Exception as e:
Review Details
  • Files reviewed - 4 · Commit Range: 1876a3c..31945f1
    • superset/mcp_service/chart/tool/update_chart.py
    • superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py
    • superset/mcp_service/dashboard/tool/generate_dashboard.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +236 to +245
for chart in chart_objects:
validation = validate_chart_dataset(chart, check_access=True)
if not validation.is_valid:
return GenerateDashboardResponse(
dashboard=None,
dashboard_url=None,
error=(
f"Chart {chart.id} is not accessible: {validation.error}"
),
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling regression in multi-chart validation

The new validation stops at the first inaccessible chart, but the original code collected all inaccessible charts for better UX. Since generate_dashboard handles multiple charts like generate_chart does, collect all errors to match that pattern and avoid iterative fixes.

Code suggestion
Check the AI-generated fix before applying
Suggested change
for chart in chart_objects:
validation = validate_chart_dataset(chart, check_access=True)
if not validation.is_valid:
return GenerateDashboardResponse(
dashboard=None,
dashboard_url=None,
error=(
f"Chart {chart.id} is not accessible: {validation.error}"
),
)
errors = []
for chart in chart_objects:
validation = validate_chart_dataset(chart, check_access=True)
if not validation.is_valid:
errors.append(f"Chart {chart.id} is not accessible: {validation.error}")
if errors:
return GenerateDashboardResponse(
dashboard=None,
dashboard_url=None,
error="; ".join(errors),
)

Code Review Run #57d487


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Move chart dataset access validation into auth.py as
check_chart_data_access(), making it part of the auth layer alongside
mcp_auth_hook (class-level RBAC) and has_dataset_access. Tools now
import from auth instead of chart_utils directly.

This addresses review feedback to use/extend the RBAC system from apache#38407
rather than adding standalone inline checks.
@codeant-ai-for-open-source codeant-ai-for-open-source Bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:L This PR changes 100-499 lines, ignoring generated files labels Mar 25, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 25, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 4c900f6
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69c40ef874a7f4000728c0ef
😎 Deploy Preview https://deploy-preview-38845--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Mar 25, 2026

Code Review Agent Run #eb1ed3

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: 31945f1..4c900f6
    • superset/mcp_service/auth.py
    • superset/mcp_service/chart/tool/update_chart.py
    • superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py
    • superset/mcp_service/dashboard/tool/generate_dashboard.py
    • tests/unit_tests/mcp_service/chart/tool/test_update_chart.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @Antonio-RiveroMartnez! Good question.

I moved the data-level check into auth.py as check_chart_data_access(), sitting alongside mcp_auth_hook and has_dataset_access. The three tools now import from auth instead of chart_utils directly.

The reason it's a separate function rather than part of mcp_auth_hook itself: the hook runs before the tool function (it doesn't know which specific charts/datasets will be accessed), while data-level checks need the actual ORM objects that are only available inside the tool after querying. Two inherently separate phases — but now both live in the auth module.

@aminghadersohi aminghadersohi merged commit 23a5e95 into apache:master Mar 25, 2026
68 of 70 checks passed
michael-s-molina pushed a commit that referenced this pull request Mar 26, 2026
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
@github-actions github-actions Bot added 🍒 6.1.0 Cherry-picked to 6.1.0 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

authentication:access-control Rlated to access control 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels change:backend Requires changing the backend size/L size:L This PR changes 100-499 lines, ignoring generated files 🍒 6.1.0 Cherry-picked to 6.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants