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


##########
superset/views/oauth.py:
##########
@@ -0,0 +1,85 @@
+# 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.
+
+import logging
+from typing import Optional
+import jwt
+from flask import flash, g, redirect, get_flashed_messages, request, session, 
url_for
+from flask_appbuilder import expose
+from flask_appbuilder.security.decorators import no_cache
+from flask_appbuilder.security.utils import generate_random_string
+from flask_appbuilder.security.views import  AuthOAuthView, WerkzeugResponse
+from flask_appbuilder._compat import as_unicode
+from superset.views.base import BaseSupersetView
+
+logger = logging.getLogger(__name__)
+
+
+class SupersetOAuthView(BaseSupersetView, AuthOAuthView):
+    route_base = "/login"
+
+    @expose("/")
+    @expose("/<provider>")
+    @no_cache
+    def login(self, provider: Optional[str] = None) -> WerkzeugResponse:
+    
+        get_flashed_messages(category_filter=['danger'])
+
+        if provider is None:
+            providers = [k for k in self.appbuilder.sm.oauth_remotes.keys()]
+            if len(providers) == 1:
+                provider = providers[0]
+        logger.debug("Provider: %s", provider)
+        if g.user is not None and g.user.is_authenticated:
+                logger.debug("Already authenticated %s", g.user)
+                return redirect(self.appbuilder.get_url_for_index)

Review Comment:
   **Suggestion:** Runtime bug: passing the method object 
`self.appbuilder.get_url_for_index` to `redirect` instead of calling it will 
lead to an invalid redirect URL (the bound method's repr). Call the method to 
obtain the URL string before redirecting. [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Authenticated users redirected to invalid URL.
   - ⚠️ /login route broken for signed-in users.
   - ⚠️ User experience degraded on login access.
   ```
   </details>
   
   ```suggestion
                   return redirect(self.appbuilder.get_url_for_index())
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Authenticate a user in the running Superset instance. The login view is
   SupersetOAuthView.login at superset/views/oauth.py:35-38.
   
   2. While authenticated, visit the login route (GET /login). The login 
handler checks
   authentication at superset/views/oauth.py:47.
   
   3. Because g.user is authenticated, execution reaches 
superset/views/oauth.py:48-49 and
   calls return redirect(self.appbuilder.get_url_for_index) — note the code 
passes the bound
   method object rather than calling it.
   
   4. Flask's redirect will convert the bound method to a string (its repr) and 
set it as the
   Location header; result is an invalid Location (e.g., "<bound method ...>") 
and the
   browser navigates to an incorrect path or receives an unexpected response. 
This reproduces
   the broken redirect for signed-in users.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/views/oauth.py
   **Line:** 49:49
   **Comment:**
        *Possible Bug: Runtime bug: passing the method object 
`self.appbuilder.get_url_for_index` to `redirect` instead of calling it will 
lead to an invalid redirect URL (the bound method's repr). Call the method to 
obtain the URL string before redirecting.
   
   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.
   ```
   </details>



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