bito-code-review[bot] commented on code in PR #39604:
URL: https://github.com/apache/superset/pull/39604#discussion_r3326416306


##########
superset/mcp_service/auth.py:
##########
@@ -305,47 +304,78 @@ def _resolve_user_from_jwt_context(app: Any) -> User | 
None:
     if not user:
         # Fail closed: JWT says this user should exist but they don't.
         # Do NOT fall through to MCP_DEV_USERNAME or stale g.user.
+        # Avoid echoing the JWT-extracted username in the exception message
+        # (CodeQL py/clear-text-logging-sensitive-data).
+        logger.debug("JWT-authenticated user not found in database (identity 
from JWT)")
         raise ValueError(
-            f"JWT authenticated user '{username}' not found in Superset 
database. "
-            f"Ensure the user exists before granting MCP access."
+            "JWT authenticated user not found in Superset database. "
+            "Ensure the user exists before granting MCP access."
         )
 
     return user
 
 
+def _redact_access_token(access_token: Any) -> None:
+    """Redact the raw token value after validation so it does not persist."""
+    try:
+        object.__setattr__(access_token, "token", "")
+    except (AttributeError, TypeError):
+        pass  # immutable AccessToken; LoggingMiddleware handles sanitization

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing security test coverage</b></div>
   <div id="fix">
   
   The new `_redact_access_token` function redacts the raw API key after 
validation to prevent token persistence. However, 
`test_valid_api_key_returns_user` (line 114-130 in test_auth_api_key.py) 
verifies `validate_api_key` is called with the correct token but does NOT 
assert that the token is redacted afterward. A test should verify the redaction 
occurs, ensuring the security measure actually works and guards against future 
regressions.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #e16d04</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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