8079: Prevent users from changing their own token UUIDs.
authorTom Clegg <tom@curoverse.com>
Sun, 6 Mar 2016 19:50:22 +0000 (14:50 -0500)
committerTom Clegg <tom@curoverse.com>
Mon, 14 Mar 2016 19:05:52 +0000 (15:05 -0400)
services/api/app/models/api_client_authorization.rb
services/api/test/functional/arvados/v1/api_client_authorizations_controller_test.rb

index c587e5830af41549c5bd637c7ffa9472bbf51017..499a61b7d3e93116b50f3e96beffbe846466c676 100644 (file)
@@ -82,8 +82,9 @@ class ApiClientAuthorization < ArvadosModel
 
   def permission_to_update
     (permission_to_create and
-     not self.user_id_changed? and
-     not self.owner_uuid_changed?)
+     not uuid_changed? and
+     not user_id_changed? and
+     not owner_uuid_changed?)
   end
 
   def log_update
index e45bdc494e566af5d278a29bf652fd8985eb5fcc..1fb94ab311b0fb29c66f7aec15f65e64e6121a68 100644 (file)
@@ -126,4 +126,22 @@ class Arvados::V1::ApiClientAuthorizationsControllerTest < ActionController::Tes
       end
     end
   end
+
+  test "scoped token cannot change its own scopes" do
+    authorize_with :admin_vm
+    put :update, {
+      id: api_client_authorizations(:admin_vm).uuid,
+      api_client_authorization: {scopes: ['all']},
+    }
+    assert_response 403
+  end
+
+  test "token cannot change its own uuid" do
+    authorize_with :admin
+    put :update, {
+      id: api_client_authorizations(:admin).uuid,
+      api_client_authorization: {uuid: 'zzzzz-gj3su-zzzzzzzzzzzzzzz'},
+    }
+    assert_response 403
+  end
 end