Enforce order of permissions decorators

At the moment we mostly have `user_has_permissions` execute first. It
shouldn’t matter, but it feels right for us to check that a user is
logged in before we check their permissions to a service. Otherwise a
malicious user could (maybe) check if a service ID belongs to a real
service, and go on to do something malicious with that information.

This commit adds some extra test code to enforce that the order is
always the same.

N.B. decorators in Python execute from closest to furthest (from the
line on which the function is defined).
This commit is contained in:
Chris Hill-Scott
2019-07-01 13:45:21 +01:00
parent 91f2da8b68
commit 3da9e84ece
13 changed files with 179 additions and 159 deletions

View File

@@ -12,8 +12,8 @@ from app.utils import user_has_permissions
@main.route("/services/<service_id>/conversation/<notification_id>")
@login_required
@user_has_permissions('view_activity')
@login_required
def conversation(service_id, notification_id):
user_number = get_user_number(service_id, notification_id)
@@ -28,8 +28,8 @@ def conversation(service_id, notification_id):
@main.route("/services/<service_id>/conversation/<notification_id>.json")
@login_required
@user_has_permissions('view_activity')
@login_required
def conversation_updates(service_id, notification_id):
return jsonify(get_conversation_partials(
@@ -40,8 +40,8 @@ def conversation_updates(service_id, notification_id):
@main.route("/services/<service_id>/conversation/<notification_id>/reply-with")
@main.route("/services/<service_id>/conversation/<notification_id>/reply-with/from-folder/<uuid:from_folder>")
@login_required
@user_has_permissions('send_messages')
@login_required
def conversation_reply(
service_id,
notification_id,
@@ -63,8 +63,8 @@ def conversation_reply(
@main.route("/services/<service_id>/conversation/<notification_id>/reply-with/<template_id>")
@login_required
@user_has_permissions('send_messages')
@login_required
def conversation_reply_with_template(
service_id,
notification_id,