Repository navigation
fix(import): tighten ownership and validation checks across asset importers - #43393
Conversation
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]>
Codecov Report❌ Patch coverage is 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
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:
|
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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-88The 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-72Long 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-90Long error messages should be assigned to variables before raising exceptions.
-
-
superset/commands/importers/v1/utils.py - 1
-
Code Structure: Semantic Duplication · Line 107-132The 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-633The 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
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]>
|
Bito Automatic Review Skipped – PR Already Merged |
SUMMARY
yaml.safe_loadinstead 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