mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 12:52:19 +01:00
fix(security): require ownership or admin to refresh another user's RetroAchievements
The endpoint took an arbitrary user id under me.write and looked it up with no ownership check, so any authenticated user could trigger a RetroAchievements fetch for another account and overwrite its stored progression. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -562,6 +562,10 @@ async def refresh_retro_achievements(
|
||||
] = False,
|
||||
) -> None:
|
||||
"""Refresh RetroAchievements progression data for a user."""
|
||||
# Admin users can refresh any user, while other users can only refresh self
|
||||
if id != request.user.id and request.user.role != Role.ADMIN:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
|
||||
user = db_user_handler.get_user(id)
|
||||
if not user or not user.ra_username:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -79,6 +79,18 @@ def test_get_user_avatar(
|
||||
assert response.headers["content-type"].startswith("image/")
|
||||
|
||||
|
||||
def test_refresh_ra_for_another_user_is_forbidden(
|
||||
client, viewer_access_token: str, admin_user: User
|
||||
):
|
||||
# Rejected on ownership before the user is looked up, so it does not depend
|
||||
# on the target having a RetroAchievements username set.
|
||||
response = client.post(
|
||||
f"/api/users/{admin_user.id}/ra/refresh",
|
||||
headers={"Authorization": f"Bearer {viewer_access_token}"},
|
||||
)
|
||||
assert response.status_code == status.HTTP_403_FORBIDDEN
|
||||
|
||||
|
||||
def test_get_user_avatar_none_set(client, access_token: str, admin_user: User):
|
||||
response = client.get(
|
||||
f"/api/users/{admin_user.id}/avatar",
|
||||
|
||||
Reference in New Issue
Block a user