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


##########
superset/utils/auth_db_password.py:
##########
@@ -0,0 +1,265 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Password policy helpers for AUTH_DB (database authentication)."""
+
+from __future__ import annotations
+
+import re
+from collections.abc import Mapping
+from typing import Any
+
+from flask import current_app as app
+from marshmallow import ValidationError
+
+# Defaults are merged with ``AUTH_DB_CONFIG`` from Flask config (partial 
overrides).
+AUTH_DB_DEFAULTS: dict[str, Any] = {
+    "password_min_length": 12,
+    "password_require_uppercase": True,
+    "password_require_lowercase": True,
+    "password_require_digit": True,
+    "password_require_special": True,
+    "password_common_list_check": True,
+    "password_hash_algorithm": "bcrypt",
+    "reset_token_expiry_minutes": 30,
+    "reset_rate_limit": "5 per 15 minutes",
+    "login_rate_limit": "10 per 5 minutes",
+    "login_max_failures": 5,
+    "login_lockout_duration_minutes": 15,
+}
+
+_PUBLIC_PASSWORD_POLICY_KEYS: tuple[str, ...] = (
+    "password_min_length",
+    "password_require_uppercase",
+    "password_require_lowercase",
+    "password_require_digit",
+    "password_require_special",
+    "password_common_list_check",
+)
+
+_SUPPORTED_HASH_ALGORITHMS: frozenset[str] = frozenset({"bcrypt", "argon2"})
+
+# bcrypt silently truncates input beyond this UTF-8 byte limit.
+BCRYPT_MAX_PASSWORD_BYTES: int = 72
+
+_COMMON_PASSWORDS: frozenset[str] = frozenset(
+    password.lower()
+    for password in {
+        "password",
+        "password1",
+        "password123",
+        "123456",
+        "12345678",
+        "123456789",
+        "qwerty",
+        "abc123",
+        "monkey",
+        "letmein",
+        "trustno1",
+        "dragon",
+        "baseball",
+        "iloveyou",
+        "master",
+        "sunshine",
+        "ashley",
+        "bailey",
+        "shadow",
+        "superman",
+        "qazwsx",
+        "michael",
+        "football",
+        "welcome",
+        "jesus",
+        "ninja",
+        "mustang",
+        "password1!",
+        "admin",
+        "admin123",
+        "root",
+        "toor",
+        "guest",
+        "p@ssw0rd",
+        "Passw0rd",
+        "Password1",
+        "Password123",
+        "Welcome1",
+        "Qwerty123",
+    }
+)
+
+
+def get_merged_auth_db_config() -> dict[str, Any]:
+    """Return ``AUTH_DB_DEFAULTS`` merged with ``AUTH_DB_CONFIG`` from app 
config."""
+    overrides: Any = app.config.get("AUTH_DB_CONFIG") or {}
+    if not isinstance(overrides, Mapping):
+        raise ValidationError(
+            {
+                "AUTH_DB_CONFIG": [
+                    "Invalid AUTH_DB_CONFIG. Expected a mapping of policy 
options."
+                ]
+            }
+        )
+    return {**AUTH_DB_DEFAULTS, **overrides}
+
+
+def get_auth_db_login_rate_limit_string() -> str:
+    """
+    Return the configured AUTH_DB ``login_rate_limit`` string for 
Flask-Limiter.
+
+    Used for endpoints that verify a password (for example ``PUT 
/api/v1/me/password``).
+    """
+    return str(
+        get_merged_auth_db_config().get(
+            "login_rate_limit", AUTH_DB_DEFAULTS["login_rate_limit"]
+        )
+    )
+
+
+def get_public_auth_db_password_policy(
+    cfg: dict[str, Any] | None = None,
+) -> dict[str, Any]:
+    """
+    Return non-secret AUTH_DB password policy options for frontend validation 
UI.
+    """
+    merged_cfg = cfg if cfg is not None else get_merged_auth_db_config()
+    return {
+        key: merged_cfg.get(key, AUTH_DB_DEFAULTS[key])
+        for key in _PUBLIC_PASSWORD_POLICY_KEYS
+    }
+
+
+def get_auth_db_password_hash_algorithm(cfg: dict[str, Any] | None = None) -> 
str:
+    """
+    Return the password hash algorithm for AUTH_DB.
+
+    ``AUTH_DB_CONFIG["password_hash_algorithm"]`` accepts ``bcrypt`` (default)
+    or ``argon2``.
+    """
+    merged_cfg = cfg if cfg is not None else get_merged_auth_db_config()
+    raw_algorithm: Any = merged_cfg.get(
+        "password_hash_algorithm", AUTH_DB_DEFAULTS["password_hash_algorithm"]
+    )
+    algorithm = str(raw_algorithm).strip().lower()

Review Comment:
   **Suggestion:** Add an explicit type hint for this derived local value to 
satisfy the rule requiring type hints on relevant variables. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This new local variable is a derived string value that can be explicitly 
annotated, but the code omits a type hint. That is a real instance of the 
type-hint rule violation.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![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=cd608bb1ac794d9498b18f267452c72c&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=cd608bb1ac794d9498b18f267452c72c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/utils/auth_db_password.py
   **Line:** 155:155
   **Comment:**
        *Custom Rule: Add an explicit type hint for this derived local value to 
satisfy the rule requiring type hints on relevant variables.
   
   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%2F39469&comment_hash=7e3bacc74df4044488d66eeb7888be154c7119477c6be11c4c660891f2b59530&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=7e3bacc74df4044488d66eeb7888be154c7119477c6be11c4c660891f2b59530&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