Skip to content

fix(import): tighten ownership and validation checks across asset importers - #43393

Merged
rusackas merged 7 commits into
masterfrom
fix/asset-importer-hardening
Aug 21, 2026
Merged

rusackas merged 7 commits into
masterfrom
fix/asset-importer-hardening

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

  • The legacy v0 dashboard/dataset importer is no longer reachable from the HTTP import dispatchers (it predates the current permission model and lacks per-object ownership checks); the CLI-only legacy import commands are unaffected.
  • Saved-query import now requires write access and, on overwrite, ownership (creator or admin), matching the pattern already used by the chart/dashboard/dataset/database importers.
  • Database import no longer reattaches stored connection credentials when the incoming connection URL or SSH-tunnel endpoint has changed from the stored one.
  • Dataset import now caps how many bytes it will read from a remote data URI, including after gzip decompression, mirroring the existing cap on ZIP-bundle uploads.
  • Example-bundle metadata import now uses yaml.safe_load instead of the unsafe loader.

TESTING INSTRUCTIONS

pytest tests/unit_tests/examples/ tests/unit_tests/dashboards/commands/importers/ tests/unit_tests/datasets/commands/importers/ tests/unit_tests/commands/importers/ tests/unit_tests/databases/commands/importers/ — new/extended tests per change, each verified to fail pre-fix and pass post-fix.

ADDITIONAL INFORMATION

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

Superset Dev and others added 5 commits August 21, 2026 00:37
load_configs_from_directory parsed metadata.yaml with yaml.Loader, which
constructs arbitrary Python objects from tags such as
!!python/object/apply. Switch to yaml.safe_load, which is sufficient
since the code only needs a plain dict to delete the "type" key from.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The dashboard and dataset import dispatchers (reachable from
POST /api/v1/dashboard/import/ and POST /api/v1/dataset/import/) listed
the legacy v0 importer as a fallback for uploads that fail v1 parsing.
v0 overrides datasets matched by (table_name, schema, database) and
charts/dashboards matched by remote_id with no per-object ownership
check. Remove v0 from both dispatchers' command_versions so the HTTP
endpoints only accept the v1 format, which enforces per-asset
ownership. The dedicated legacy_import_dashboards / legacy_import_datasources
CLI commands import v0 directly and are unaffected.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… query

import_saved_query matched an incoming config purely by UUID and
overwrote the row unconditionally, unlike the chart, dashboard, dataset,
database and theme importers, which all check can_write plus ownership
before an overwrite. Add the same can_write gate for both the create and
overwrite paths, and require the caller to be the saved query's creator
(or an admin) to overwrite an existing row, raising ImportFailedError
otherwise. A no-request-user + ignore_permissions path is preserved for
background/CLI callers, matching the chart importer's trust model.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… on import

Database import matched an existing row purely by UUID and reattached
the stored password / SSH tunnel secret / encrypted_extra whenever the
UUID matched, regardless of whether the incoming sqlalchemy_uri or
tunnel server pointed at a different endpoint. Since database UUIDs are
not secret (they appear in every exported bundle), this let an import
repoint an existing connection at a new host while silently keeping the
real credential attached, so the next connection would send it there.

Add database_connection_identity_unchanged() to gate secret reattachment
in load_configs() on the connection URL (driver/host/port/query args)
and SSH tunnel endpoint staying the same, and add a second check in
import_database() itself that refuses an overwrite changing the
endpoint unless fresh credentials are supplied in the same request
(import_from_dict alone would otherwise leave the stored password
column untouched even when load_configs withholds it).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…gzip

load_data() streamed a dataset import's remote data URI straight into
pd.read_csv with no size bound; for .gz URIs the gzip-decompressed
stream had no bound either, unlike the ZIP-bundle and columnar-upload
paths, which enforce ZIPPED_FILE_MAX_SIZE via check_is_safe_zip. Add
_read_bounded(), which drains the (optionally decompressed) stream in
1 MB chunks and raises ImportFailedError once the running total
exceeds ZIPPED_FILE_MAX_SIZE, reusing the same per-file knob.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@dosubot dosubot Bot added authentication:access-control Rlated to access control change:backend Requires changing the backend labels Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.57534% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.80%. Comparing base (f7d505e) to head (d4a23e9).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/database/importers/v1/utils.py 34.61% 14 Missing and 3 partials ⚠️
superset/commands/dataset/importers/v1/utils.py 14.28% 12 Missing ⚠️
superset/commands/query/importers/v1/utils.py 54.54% 2 Missing and 3 partials ⚠️
superset/commands/importers/v1/utils.py 78.94% 3 Missing and 1 partial ⚠️
superset/examples/utils.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43393      +/-   ##
==========================================
- Coverage   66.84%   66.80%   -0.04%     
==========================================
  Files        2876     2876              
  Lines      164066   164290     +224     
  Branches    37863    37921      +58     
==========================================
+ Hits       109666   109755      +89     
- Misses      52226    52343     +117     
- Partials     2174     2192      +18     
Flag Coverage Δ
hive 38.08% <19.17%> (-0.03%) ⬇️
mysql 57.77% <46.57%> (-0.05%) ⬇️
postgres 57.80% <46.57%> (-0.06%) ⬇️
presto 40.01% <19.17%> (-0.04%) ⬇️
python 59.24% <46.57%> (-0.06%) ⬇️
sqlite 57.50% <46.57%> (-0.05%) ⬇️
unit 100.00% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

Comment thread superset/commands/importers/v1/utils.py Resolved
@netlify

netlify Bot commented Aug 21, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 0fb11e4
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a88788d480d2000083e7391
😎 Deploy Preview https://deploy-preview-43393--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

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

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.

Code Review Agent Run #5c1645

Actionable Suggestions - 3
  • superset/commands/database/importers/v1/utils.py - 3
    • Replace bare Exception with specific exception · Line 41-49
    • Replace bare Exception with specific exception · Line 63-67
    • Missing unit tests for new security guards · Line 147-153
Additional Suggestions - 5
  • superset/commands/database/importers/v1/utils.py - 3
    • CWE-1188: Sensitive credential not checked · Line 85-88
      The SSH tunnel credential check at line 87 only examines `password` and `private_key`. The model (`SSHTunnel.export_fields` line 91, `SSHTunnel.data` property line 115) marks `private_key_password` as a sensitive field, and imports can carry it in `ssh_tunnel`. If an overwrite changes the tunnel endpoint and provides only a fresh `private_key_password`, the stored `private_key_password` could still be exfiltrated to the new host. Add `"private_key_password"` to the `any()` tuple to close the gap.
    • Assign long error message to variable before raise · Line 72-72
      Long error messages should be assigned to variables before raising exceptions. This pattern appears in multiple locations (lines 72 and 90).
    • Assign long error message to variable before raise · Line 90-90
      Long error messages should be assigned to variables before raising exceptions.
  • superset/commands/importers/v1/utils.py - 1
    • Code Structure: Semantic Duplication · Line 107-132
      The same URL comparison logic (`make_url_safe(uri)._replace(password=None)`) appears in both `database_connection_identity_unchanged()` (line 124-125) and `_connection_identity_changed()` in `superset/commands/database/importers/v1/utils.py` (line 44-45). Extracting to a shared utility would reduce duplication and ensure consistent behavior.
  • superset/commands/dataset/importers/v1/utils.py - 1
    • Missing translation for error message · Line 633-633
      The error message string should use a translation function (`_()`) to support internationalization, consistent with BITO.md rule 6516. Add `from flask import g` or use the existing translation pattern in this codebase.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/commands/importers/v1/utils.py - 4
    • CWE-345: Insufficient Verification of Data Authenticity · Line 107-132
    • CWE-345: Insufficient Verification of Data Authenticity · Line 173-187
    • CWE-345: Insufficient Verification of Data Authenticity · Line 199-222
    • CWE-345: Insufficient Verification of Data Authenticity · Line 231-232
Review Details
  • Files reviewed - 13 · Commit Range: 86b458d..0fb11e4
    • superset/commands/dashboard/importers/dispatcher.py
    • superset/commands/database/importers/v1/utils.py
    • superset/commands/dataset/importers/dispatcher.py
    • superset/commands/dataset/importers/v1/utils.py
    • superset/commands/importers/v1/utils.py
    • superset/commands/query/importers/v1/utils.py
    • superset/examples/utils.py
    • tests/unit_tests/commands/importers/v1/import_saved_query_test.py
    • tests/unit_tests/commands/importers/v1/utils_test.py
    • tests/unit_tests/dashboards/commands/importers/dispatcher_test.py
    • tests/unit_tests/databases/commands/importers/v1/import_test.py
    • tests/unit_tests/datasets/commands/importers/dispatcher_test.py
    • tests/unit_tests/examples/utils_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - Manually triggers an incremental AI Review.

  • /review full - 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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Superset Dev and others added 2 commits August 21, 2026 09:48
test_import_dashboard_v0_export and test_import_dataset_v0_export
asserted that uploading a legacy v0-format export through the HTTP
import endpoints succeeded (200). That contract changed in an earlier
commit on this branch, which removed the v0 command from the
dashboard/dataset import dispatchers so the HTTP-reachable endpoints
only accept the v1 format. Update both tests to assert the now-correct
result: a 422 with a "Could not find a valid command to import file"
GENERIC_COMMAND_ERROR, and that no row is created. The legacy
CLI commands (legacy_import_dashboards / legacy_import_datasources)
still import v0 files directly and are covered by their own tests.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ase gap

Replace bare `except Exception` catches around make_url_safe() in the
database importer's connection-identity check with the specific
DatabaseInvalidError it actually raises. Bound the raw (compressed)
download in the dataset data-URI gzip path before decompression, not
just the decompressed output. Guard load_configs() against a
syntactically valid YAML document whose top-level value isn't a
mapping, which previously raised an unhandled AttributeError instead
of a structured validation error. Extend the SSH tunnel repoint guard
so a fresh private_key without a fresh private_key_password still
requires confirmation, matching the existing password/private_key
check.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@rusackas rusackas added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Aug 21, 2026
@rusackas
rusackas merged commit 6589311 into master Aug 21, 2026
84 checks passed
@rusackas
rusackas deleted the fix/asset-importer-hardening branch August 21, 2026 19:35
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

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 change:backend Requires changing the backend merge-if-green If approved and tests are green, please go ahead and merge it for me preset-io size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants