bito-code-review[bot] commented on code in PR #36195:
URL: https://github.com/apache/superset/pull/36195#discussion_r2544116427
##########
superset/security/manager.py:
##########
@@ -2875,8 +2875,31 @@ def register_views(self) -> None:
SupersetRegisterUserView
)
+ # Apply rate limiting to auth view if enabled
+ # This needs to be done after the view is added, otherwise the
blueprint
+ # is not initialized. Only apply if blueprint exists.
+ # We also need to prevent the parent's register_views from trying to
+ # apply rate limiting again (since auth_view already exists), so we
+ # temporarily disable AUTH_RATE_LIMITED during the super() call.
+ if (
+ self.is_auth_limited
+ and hasattr(self.auth_view, "blueprint")
+ and self.auth_view.blueprint is not None
+ ):
+ self.limiter.limit(self.auth_rate_limit, methods=["POST"])(
+ self.auth_view.blueprint
+ )
+
+ # Temporarily disable AUTH_RATE_LIMITED to prevent parent from trying
to
+ # apply rate limiting to a potentially None blueprint
+ original_auth_rate_limited =
current_app.config.get("AUTH_RATE_LIMITED", False)
+ current_app.config["AUTH_RATE_LIMITED"] = False
+
super().register_views()
+ # Restore original value
+ current_app.config["AUTH_RATE_LIMITED"] = original_auth_rate_limited
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Undefined rate limiting attributes and unsafe config
handling</b></div>
<div id="fix">
The code references undefined attributes `self.is_auth_limited` and
`self.auth_rate_limit`, which will cause an AttributeError at runtime during
application initialization, breaking the security manager's view registration.
Additionally, the temporary modification of the `AUTH_RATE_LIMITED` config is
not exception-safe; if `super().register_views()` raises an exception, the
config remains set to `False`, potentially disabling rate limiting globally and
exposing the application to abuse. This impacts the `auth_view` used for user
authentication, where rate limiting is critical for security.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
# Apply rate limiting to auth view if enabled
# This needs to be done after the view is added, otherwise the
blueprint
# is not initialized. Only apply if blueprint exists.
# We also need to prevent the parent's register_views from trying to
# apply rate limiting again (since auth_view already exists), so we
# temporarily disable AUTH_RATE_LIMITED during the super() call.
if (
current_app.config.get("AUTH_RATE_LIMITED", False)
and hasattr(self.auth_view, "blueprint")
and self.auth_view.blueprint is not None
):
self.limiter.limit(current_app.config.get("AUTH_RATE_LIMIT", "5
per second"), methods=["POST"])(
self.auth_view.blueprint
)
# Temporarily disable AUTH_RATE_LIMITED to prevent parent from
trying to
# apply rate limiting to a potentially None blueprint
original_auth_rate_limited =
current_app.config.get("AUTH_RATE_LIMITED", False)
current_app.config["AUTH_RATE_LIMITED"] = False
try:
super().register_views()
finally:
# Restore original value
current_app.config["AUTH_RATE_LIMITED"] =
original_auth_rate_limited
````
</div>
</details>
</div>
<small><i>Code Review Run <a
href=https://github.com/apache/superset/pull/36195#issuecomment-3555433273>#1cb99e</a></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]