Repository navigation
fix(database): don't reattach stored connection details when the effective destination changes - #44003
Conversation
…ctive destination changes test_connection, validate_parameters, database update, and database import all decide whether to reattach a stored secret (password, encrypted_extra, or SSH tunnel credential) by comparing one visible field against its masked/stored form, without checking whether other request-controlled fields also feed into the actual connection destination: - extra.engine_params (in particular engine_params.connect_args.host/ .port) is merged into the DBAPI connect() kwargs by SQLAlchemy and can override the host/port carried in the URI itself. - The SSH tunnel server_address/server_port can change independently of the URI. - (update only) the URI's own host/port can change directly while its password segment is left masked, with nothing comparing it against the stored host first. A principal who can reach one of these endpoints for a given database can redirect its real stored credential to a destination they control. For the update path this is a persistent change: the real credential is sent to the new destination on the *next* use of the database by anyone, not just the requester. Also scopes DatabaseDAO.get_database_by_name to the same DatabaseFilter object-visibility boundary find_by_id/get_connection already apply to this resource; it was previously an unfiltered lookup. Shared comparison logic factored into superset/commands/database/utils.py (engine_params_changed, ssh_tunnel_endpoint_changed, ssh_tunnel_rebind_unsafe, uri_identity_changed) and reused across all four call sites, extending the identity-check policy PR #43393 established for database import's URI-host case to also cover extra.engine_params, and applying an equivalent check to database update, which previously had none. Regression tests added per site (engine_params variant, SSH-tunnel- endpoint variant, and for update also the plain URI-host variant), each verified to fail without its corresponding fix and pass with it. Legitimate flows (unchanged destination, or a deliberate move with a freshly supplied credential) are covered and unaffected. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review Agent Run #1c94efActionable Suggestions - 0Additional Suggestions - 7
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 |
| if connection_identity_changed and submitted_password in ( | ||
| None, | ||
| PASSWORD_MASK, | ||
| ): | ||
| raise DatabaseInvalidError(exceptions=[DatabaseUpdateUnsafeRebindError()]) |
There was a problem hiding this comment.
Suggestion: A destination change is accepted only when the URI contains a real password, so fresh masked_encrypted_extra credentials are rejected for engines storing authentication outside the URI. [api mismatch]
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/commands/database/update.py
**Line:** 228:232
**Comment:**
*Api Mismatch: A destination change is accepted only when the URI contains a real password, so fresh `masked_encrypted_extra` credentials are rejected for engines storing authentication outside the URI.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Correct catch, this and sha174n's more detailed suggestion on the same lines are the same underlying gap. Fixed in 72ccf98 (see reply on that thread for detail).
|
The flagged issue is correct. The current implementation of To resolve this, you should update the check to also verify if Would you like me to fetch all other comments on this PR to validate and implement fixes for them as well? superset/commands/database/update.py |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #44003 +/- ##
=======================================
Coverage 79.81% 79.82%
=======================================
Files 2914 2914
Lines 170473 170549 +76
Branches 39518 39530 +12
=======================================
+ Hits 136066 136143 +77
- Misses 31885 31886 +1
+ Partials 2522 2520 -2
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:
|
Co-authored-by: Shaitan <[email protected]>
- Reuse DatabaseDAO._apply_base_filter in get_database_by_name instead
of reimplementing the base_filter application inline, so the
visibility boundary can't diverge if that logic changes.
- Refine the encrypted_extra reuse check in update.py (building on the
applied suggestion from this thread): check model.password is not
None rather than re-parsing the masked URI to determine whether this
engine even has a URI password, and exclude an empty ("{}")
encrypted_extra from being treated as a stored secret to protect.
- Parameterize field_name on DatabaseUpdateUnsafeRebindError so the SSH
tunnel branch attributes its 422 to ssh_tunnel instead of
sqlalchemy_uri.
- Fix a bug shared by test_connection.py and validate.py: the SSH
tunnel password unmask was gated on the combined identity-changed
flag (engine_params OR ssh tunnel endpoint), so an unrelated
engine_params edit would spuriously withhold a legitimate,
unchanged SSH tunnel's stored password. Gate the tunnel unmask on
its own endpoint-changed check instead, independent of engine_params
(matching how update.py already gates its SSH tunnel check
independently of the URI/engine_params check).
Regression tests added for all of the above; each verified to fail
without its corresponding fix and pass with it.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Went through Bito's additional suggestions and sha174n's inline review, pushed a follow-up commit (72ccf98) addressing what checked out: Taken:
Not taken: the three "narrow Regression tests added for everything taken above, each verified to fail without its fix and pass with it. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
sha174n
left a comment
There was a problem hiding this comment.
LGTM. The destination-change checks now cover the URI password, encrypted_extra, and the SSH tunnel per-secret, so a stored secret is no longer reattached onto a changed destination when only one of them is refreshed — and engines that keep credentials entirely in encrypted_extra (no URI password) can still make legitimate destination changes. Test coverage matches each path, including the encrypted_extra-only and fresh-URI-password-with-masked-encrypted_extra cases. Thanks for the quick turnaround.
|
Bito Automatic Review Skipped – PR Already Merged |
SUMMARY
test_connection,validate_parameters, database update, and database import all decide whether to reattach a stored connection secret (password,encrypted_extra, or SSH tunnel credential) by comparing one visible field against its masked/stored form, without checking whether other request-controlled fields also feed into the actual connection destination.extra.engine_params(in particularengine_params.connect_args.host/.port) is merged into the DBAPI connect kwargs by SQLAlchemy and can override the host/port carried in the URI itself. The SSH tunnel'sserver_address/server_portcan change independently of the URI. For database update, the URI's own host/port can change directly while its password segment stays masked, with nothing comparing it against the stored host first.This PR adds an identity check across all four paths (mirroring the check #43393 already added for database import's URI-host case, extended to also cover
extra.engine_params, and applied fresh to database update, which had none before) and refuses to reattach a stored secret unless a fresh credential is supplied for a destination that changed. Shared comparison logic lives insuperset/commands/database/utils.py. Also scopesDatabaseDAO.get_database_by_nameto the sameDatabaseFilterobject-visibility boundaryfind_by_id/get_connectionalready use for this resource.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change, no UI impact.
TESTING INSTRUCTIONS
Regression tests added per site (
extra.engine_paramsvariant, SSH-tunnel-endpoint variant, and for database update also the plain URI-host variant). Each was verified to fail without its corresponding fix and pass with it.pytest tests/unit_tests/commands/databases/ tests/unit_tests/databases/ tests/unit_tests/daos/— 521 passed. Legitimate flows (unchanged destination, or a deliberate move with a freshly supplied credential) are covered and unaffected.ADDITIONAL INFORMATION