Skip to content

Commit 9b36910

Browse files
committed
Prevent information extraction about organization memberships
Check first that the requesting user really has the corresponding rights to play with an organization because doing more checks whose errors can provide information about who is a member of which organization.
1 parent 1c02fe0 commit 9b36910

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

pytition/petition/views.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -893,41 +893,41 @@ def org_set_user_perms(request, orgslugname, user_name):
893893
"""
894894
pytitionuser = get_session_user(request)
895895

896-
try:
897-
member = PytitionUser.objects.get(user__username=user_name)
898-
except PytitionUser.DoesNotExist:
899-
messages.error(request, _("User does not exist"))
900-
return redirect("org_dashboard", orgslugname)
901-
902896
try:
903897
org = Organization.objects.get(slugname=orgslugname)
904898
except Organization.DoesNotExist:
905899
raise Http404(_("Organization does not exist"))
906900

907-
if org not in member.organization_set.all():
908-
messages.error(request, _("This user is not part of organization \'{orgname}\'".format(orgname=org.name)))
909-
return redirect("org_dashboard", org.slugname)
910-
911-
try:
912-
permissions = Permission.objects.get(user=member, organization=org)
913-
except Permission.DoesNotExist:
914-
messages.error(request, _("Fatal error, this user does not have permissions attached for this organization"))
915-
return redirect("org_dashboard", org.slugname)
901+
if pytitionuser not in org.members.all():
902+
messages.error(request, _("You are not part of this organization"))
903+
return redirect("user_dashboard")
916904

917905
try:
918906
userperms = Permission.objects.get(user=pytitionuser, organization=org)
919907
except:
920908
messages.error(request, _("Fatal error, you don't have permissions attached to you for this organization"))
921909
return redirect("org_dashboard", org.slugname)
922910

923-
if pytitionuser not in org.members.all():
924-
messages.error(request, _("You are not part of this organization"))
925-
return redirect("user_dashboard")
926-
927911
if not userperms.can_modify_permissions:
928912
messages.error(request, _("You are not allowed to modify this organization members' permissions"))
929913
return redirect("org_edit_user_perms", orgslugname, user_name)
930914

915+
try:
916+
member = PytitionUser.objects.get(user__username=user_name)
917+
except PytitionUser.DoesNotExist:
918+
messages.error(request, _("User does not exist"))
919+
return redirect("org_dashboard", orgslugname)
920+
921+
if org not in member.organization_set.all():
922+
messages.error(request, _("This user is not part of organization \'{orgname}\'".format(orgname=org.name)))
923+
return redirect("org_dashboard", org.slugname)
924+
925+
try:
926+
permissions = Permission.objects.get(user=member, organization=org)
927+
except Permission.DoesNotExist:
928+
messages.error(request, _("Fatal error, this user does not have permissions attached for this organization"))
929+
return redirect("org_dashboard", org.slugname)
930+
931931
if request.method == "POST":
932932
error = False
933933
post = request.POST

0 commit comments

Comments
 (0)