codeant-ai-for-open-source[bot] commented on code in PR #39469: URL: https://github.com/apache/superset/pull/39469#discussion_r3595975685
########## 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() Review Comment: **Suggestion:** Add an explicit type annotation for this local config variable so it complies with the required type-hint coverage. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This is new Python code in the added file, and the local variable `merged_cfg` is assigned a config mapping without an explicit type annotation even though it can be annotated. That matches the type-hint requirement. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2b86701a1b324a76a98e18b400574fee&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2b86701a1b324a76a98e18b400574fee&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:** 137:137 **Comment:** *Custom Rule: Add an explicit type annotation for this local config variable so it complies with the required type-hint coverage. 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=6bab49b7fc63cb8676fdf3aab746ad3297cb44f7d0528d4594a7f0deb3697013&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=6bab49b7fc63cb8676fdf3aab746ad3297cb44f7d0528d4594a7f0deb3697013&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]
