rusackas commented on code in PR #40653:
URL: https://github.com/apache/superset/pull/40653#discussion_r3366345761


##########
superset/mcp_service/auth.py:
##########
@@ -117,6 +195,39 @@ def __init__(
         super().__init__(message)
 
 
+def _log_scope_denial(
+    func: Callable[..., Any],
+    method_permission_name: str,
+    permission_str: str,
+    class_permission_name: str,
+    *,
+    log_denial: bool,
+) -> None:
+    """Log a scope-based denial for a tool the user has RBAC access to.
+
+    Extracted from ``check_tool_permission`` to keep that function's
+    cyclomatic complexity in check.
+    """
+    required_scope = _METHOD_TO_REQUIRED_SCOPE.get(method_permission_name)
+    if log_denial:
+        logger.warning(
+            "Scope denied for user %s: token lacks required scope "
+            "'%s' for %s on %s (tool: %s)",
+            g.user.username,

Review Comment:
   Done — applied `_sanitize_for_log(g.user.username)` in the warning branch of 
`_log_scope_denial`, consistent with how `token_iss` is already sanitized in 
this file. This escapes newlines/CR/tabs to prevent log forgery (CWE-117).



##########
superset/mcp_service/auth.py:
##########
@@ -117,6 +195,39 @@ def __init__(
         super().__init__(message)
 
 
+def _log_scope_denial(
+    func: Callable[..., Any],
+    method_permission_name: str,
+    permission_str: str,
+    class_permission_name: str,
+    *,
+    log_denial: bool,
+) -> None:
+    """Log a scope-based denial for a tool the user has RBAC access to.
+
+    Extracted from ``check_tool_permission`` to keep that function's
+    cyclomatic complexity in check.
+    """
+    required_scope = _METHOD_TO_REQUIRED_SCOPE.get(method_permission_name)
+    if log_denial:
+        logger.warning(
+            "Scope denied for user %s: token lacks required scope "
+            "'%s' for %s on %s (tool: %s)",
+            g.user.username,
+            required_scope,
+            permission_str,
+            class_permission_name,
+            func.__name__,
+        )
+    else:
+        logger.debug(
+            "Tool hidden for user %s: token lacks required scope '%s' (tool: 
%s)",
+            g.user.username,

Review Comment:
   Done — applied `_sanitize_for_log(g.user.username)` in the DEBUG branch of 
`_log_scope_denial` as well, matching the warning-branch fix for consistency 
(CWE-117).



-- 
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