Conversation
The admin route protection logic (`require_admin`) previously checked `if (admin_user := request.state.user) and ...`. This check evaluated to `False` if `request.state.user` was `None` (falsy), causing the `HTTPException` to be skipped and allowing unauthorized access. This commit changes the logic to: 1. Safely retrieve the user using `getattr(request.state, "user", None)`. 2. Explicitly raise `ImpossibleStateError` if the user is missing or `None`. This asserts that upstream authentication middleware must have successfully populated the user. 3. If the user exists, verify the admin role and raise `401 Unauthorized` if the check fails. This fails closed on missing user data, treating it as an internal server error (impossible state) rather than an unauthorized request, which aligns with the expectation that admin routes are behind strict authentication middleware. Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR fixes a critical security vulnerability in
app/routes/admin.pywhere unauthorized users could bypass admin checks ifrequest.state.userwas not set.Changes:
require_admindependency to explicitly check for user existence usinggetattr(request.state, "user", None).ImpossibleStateErrorif the user is missing, enforcing the assumption that upstream middleware handles authentication.HTTPException(401)for authenticated users who are not admins.Testing:
verify_fix.py, now deleted) which simulated requests withrequest.state.userasNone, missing, non-admin, and admin.ImpossibleStateErroris raised for missing users and401for non-admins.just py_lint).PR created automatically by Jules for task 17224035668587722108 started by @iloveitaly