codeant-ai-for-open-source[bot] commented on code in PR #45870:
URL: https://github.com/apache/superset/pull/45870#discussion_r4419435594


##########
superset/databases/schemas.py:
##########
@@ -444,6 +447,76 @@ def build_sqlalchemy_uri(
 
         return data
 
+    @validates_schema
+    def validate_embedded_credentials(
+        self, data: dict[str, Any], **kwargs: Any
+    ) -> None:
+        """Validate authored credentials with the effective connection's 
engine."""
+        value = data.get("masked_encrypted_extra")
+        if not value or not (
+            is_feature_enabled("EMBEDDED_CREDENTIAL_FALLBACK")
+            and is_feature_enabled("EMBEDDED_SUPERSET")
+        ):
+            return
+
+        encrypted_extra = json.loads(value)
+        if EMBEDDED_CREDENTIALS_KEY not in encrypted_extra:
+            return
+
+        engine_spec = BaseEngineSpec
+        stored = (
+            db.session.get(Database, self.database_id)
+            if self.database_id is not None
+            else None
+        )
+        if sqlalchemy_uri := data.get("sqlalchemy_uri"):
+            engine_spec = 
Database(sqlalchemy_uri=sqlalchemy_uri).db_engine_spec
+        elif stored:
+            engine_spec = stored.db_engine_spec
+
+        credentials = encrypted_extra[EMBEDDED_CREDENTIALS_KEY]
+        if embedded_credentials_incomplete(
+            credentials,
+            engine_spec.validate_embedded_credentials,
+        ):

Review Comment:
   **Suggestion:** `PASSWORD_MASK` is non-empty, so masked values for secrets 
absent from storage pass this check as complete; the update then saves the mask 
as the credential.
   
   **Assessment:** 🟠 `Major` · 🔁 `Occurrence: Rarely` · 🏷️ `Incorrect condition 
logic`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a2a4bc5aaa7648388c5cb898842a1816&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a2a4bc5aaa7648388c5cb898842a1816&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/databases/schemas.py
   **Line:** 477:481
   **Comment:**
        *Incorrect Condition Logic: `PASSWORD_MASK` is non-empty, so masked 
values for secrets absent from storage pass this check as complete; the update 
then saves the mask as the credential.
   
   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 fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45870&comment_hash=8ebed582021121fde2e3a747c047b2ee44d86f289ebb77b4bf04f05c3a5fb025&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45870&comment_hash=8ebed582021121fde2e3a747c047b2ee44d86f289ebb77b4bf04f05c3a5fb025&reaction=dislike'>👎</a>



##########
superset/databases/schemas.py:
##########
@@ -1146,25 +1236,37 @@ def validate_masked_encrypted_extra(
                 "File contains both `encrypted_extra` and 
`masked_encrypted_extra`"
             )
 
-        if db.session.query(Database).filter_by(uuid=data["uuid"]).first():
-            # Existing DB: sensitive values will be revealed from existing
-            # encrypted_extra in import_database()
-            return
-
         masked_encrypted_extra = json.loads(data["masked_encrypted_extra"])
 
-        # Determine engine spec from sqlalchemy_uri to get sensitive fields
-        sqlalchemy_uri = data["sqlalchemy_uri"]
-        url = make_url_safe(sqlalchemy_uri)
-        backend = url.get_backend_name()
-        driver = url.get_driver_name()
-        db_engine_spec = get_engine_spec(backend, driver=driver)
-
-        # Check if any sensitive field is still masked
-        masked_fields = get_masked_fields(
-            masked_encrypted_extra,
-            db_engine_spec.encrypted_extra_sensitive_field_paths(),
-        )
+        if existing := 
db.session.query(Database).filter_by(uuid=data["uuid"]).first():
+            if not self.overwrites_existing:
+                return
+            # Existing DB: masked values are revealed from its stored
+            # encrypted_extra in import_database(). Any the stored payload has 
no
+            # value for -- e.g. a connection promoted without its OAuth2 
client or
+            # embedded credential -- would otherwise be stored as the mask 
itself,
+            # so ask for those like a new DB.
+            db_engine_spec = existing.db_engine_spec

Review Comment:
   **Suggestion:** When an overwrite changes the database engine, this checks 
masks using the old engine’s secret paths. A new engine’s secret can pass as a 
mask and be stored literally.
   
   **Assessment:** 🟠 `Major` · 🔁 `Occurrence: Rarely` · 🏷️ `Incorrect variable 
usage`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b125e8b9cd1848b88b3e439fe125f2f1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b125e8b9cd1848b88b3e439fe125f2f1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/databases/schemas.py
   **Line:** 1249:1249
   **Comment:**
        *Incorrect Variable Usage: When an overwrite changes the database 
engine, this checks masks using the old engine’s secret paths. A new engine’s 
secret can pass as a mask and be stored literally.
   
   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 fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45870&comment_hash=7d626bcc04f8ebaf0dbdb0ef7e93d507e0aeab58054f495b1023a899b61586c3&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45870&comment_hash=7d626bcc04f8ebaf0dbdb0ef7e93d507e0aeab58054f495b1023a899b61586c3&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to