Skip to content

fix(mcp): handle table chart raw mode in query builders and sanitize dashboard titles#38990

Open
aminghadersohi wants to merge 3 commits intoapache:masterfrom
aminghadersohi:amin/fix-mcp-table-chart-query-and-xss
Open

fix(mcp): handle table chart raw mode in query builders and sanitize dashboard titles#38990
aminghadersohi wants to merge 3 commits intoapache:masterfrom
aminghadersohi:amin/fix-mcp-table-chart-query-and-xss

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

@aminghadersohi aminghadersohi commented Mar 31, 2026

SUMMARY

Four fixes for MCP service tools:

  1. ASCII preview for table charts: ASCIIPreviewStrategy now checks for all_columns/query_mode: "raw" when building query context, preventing "Empty query?" errors on table-type charts.

  2. Table chart compile check: _build_query_columns() in preview_utils.py applies the same raw-mode handling so table chart generation compile checks pass.

  3. Table chart form_data: map_table_config() now includes "columns" alongside "all_columns" in raw mode so downstream QueryContextFactory validation passes.

  4. Dashboard title XSS: GenerateDashboardRequest now sanitizes dashboard_title via @field_validator using sanitize_user_input(), matching the existing pattern in chart schemas.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend-only changes.

TESTING INSTRUCTIONS

  1. Call get_chart_preview with format: "ascii" on a table chart → should return data instead of "Empty query?" error
  2. Call generate_chart with chart_type: "table" and raw columns → should succeed without compile error
  3. Call generate_dashboard with dashboard_title: "<script>alert(1)</script>Test" → title should be sanitized (script tags stripped)

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

…dashboard titles

Three fixes:

1. ASCIIPreviewStrategy in get_chart_preview.py now checks for
   all_columns/query_mode:"raw" when building query context for table
   charts, preventing "Empty query?" errors on ASCII preview.

2. _build_query_columns() in preview_utils.py applies the same pattern
   so table chart compile checks also work correctly.

3. map_table_config() in chart_utils.py now includes "columns" alongside
   "all_columns" in raw mode form_data so downstream QueryContextFactory
   validation passes.

4. GenerateDashboardRequest in dashboard/schemas.py now sanitizes
   dashboard_title via field_validator to prevent XSS payloads from
   being stored in dashboard names.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review bot commented Mar 31, 2026

Code Review Agent Run #9cfaf8

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 4e617ab..4e617ab
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/preview_utils.py
    • superset/mcp_service/chart/tool/get_chart_preview.py
    • superset/mcp_service/dashboard/schemas.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 change:backend Requires changing the backend viz:charts:table Related to the Table chart labels Mar 31, 2026
@codeant-ai-for-open-source codeant-ai-for-open-source bot added the size:S This PR changes 10-29 lines, ignoring generated files label Mar 31, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 17.39130% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.42%. Comparing base (1e2d0fa) to head (fba15dc).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
...perset/mcp_service/chart/tool/get_chart_preview.py 0.00% 10 Missing ⚠️
superset/mcp_service/dashboard/schemas.py 44.44% 5 Missing ⚠️
superset/mcp_service/chart/preview_utils.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #38990      +/-   ##
==========================================
- Coverage   64.42%   64.42%   -0.01%     
==========================================
  Files        2536     2536              
  Lines      131103   131120      +17     
  Branches    30434    30437       +3     
==========================================
+ Hits        84467    84471       +4     
- Misses      45173    45186      +13     
  Partials     1463     1463              
Flag Coverage Δ
hive 40.08% <17.39%> (-0.01%) ⬇️
mysql 60.93% <17.39%> (-0.02%) ⬇️
postgres 61.01% <17.39%> (-0.02%) ⬇️
presto 40.10% <17.39%> (-0.01%) ⬇️
python 62.60% <17.39%> (-0.02%) ⬇️
sqlite 60.63% <17.39%> (-0.02%) ⬇️
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.

…anitizer

1. Raw-mode query building now falls back to "columns" when "all_columns"
   is absent, covering pre-existing saved charts that only populate one field.

2. Dashboard title sanitizer uses _strip_html_tags directly instead of
   sanitize_user_input, which would reject benign titles containing "data:"
   (e.g., "Sales data: Q1").
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 1, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 6db7226
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69ccd2b8c6c140000821f8dd
😎 Deploy Preview https://deploy-preview-38990--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.

The sanitizer was converting empty strings to None, which triggered
auto-generated titles. Preserve the original empty string value.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review bot commented Apr 1, 2026

Code Review Agent Run #ff81be

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/dashboard/schemas.py - 1
    • Behavior change in title sanitization · Line 463-463
      This change alters the validator's behavior for inputs that become empty after sanitization (e.g., HTML tags with no content like ''). Previously, such inputs would return None, triggering auto-generation of a descriptive title. Now, they return an empty string, resulting in dashboards with no title. While the test expects explicit empty strings to be preserved, sanitized empty strings should probably still trigger auto-generation for better UX. Consider reverting to 'return v or None' or adding logic to return None when v is empty after processing.
Review Details
  • Files reviewed - 3 · Commit Range: 4e617ab..fba15dc
    • superset/mcp_service/chart/preview_utils.py
    • superset/mcp_service/chart/tool/get_chart_preview.py
    • superset/mcp_service/dashboard/schemas.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/M size:S This PR changes 10-29 lines, ignoring generated files viz:charts:table Related to the Table chart

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant