CVE-2022-2901 (published 2022-09-06T10:15Z)

Improper Authorization in GitHub repository chatwoot/chatwoot prior to 2.8.

CVSS v3 base score: 7.1, HIGH (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:N)

Weakness information:
cwe_id: CWE-285
cwe_name: Improper Authorization
description: The product does not perform or incorrectly performs an authorization check when an actor attempts to access a resource or perform an action.
extended_description: 
            Assuming a user with a given identity, authorization is the process of determining whether that user can access a given resource, based on the user's privileges and any permissions or other access-control specifications that apply to the resource.
            When access control checks are not applied consistently - or not at all - users are able to access data or perform actions that they should not be allowed to perform. This can lead to a wide range of problems, including information exposures, denial of service, and arbitrary code execution.
         
         

Fix information:
repo_url: https://github.com/chatwoot/chatwoot
commit_details: repo_url: https://github.com/chatwoot/chatwoot
author: Tejaswini Chile
author_date: 2022-09-02 23:09:29+05:30
msg: fix: Validations for updating team members (#5384)

fixes: chatwoot/product#539

Co-authored-by: Sojan Jose <sojan@pepalo.com>
repository: repo_url: https://github.com/chatwoot/chatwoot
repo_name: chatwoot/chatwoot
description: Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬
repo_language: Ruby
owner: chatwoot
file_changes: filename: team_members_controller.rb
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,7 @@
 class Api::V1::Accounts::TeamMembersController < Api::V1::Accounts::BaseController
   before_action :fetch_team
   before_action :check_authorization
+  before_action :validate_member_id_params, only: [:create, :update, :destroy]
 
   def index
     @team_members = @team.team_members.map(&:user)
@@ -45,4 +46,10 @@ class Api::V1::Accounts::TeamMembersController < Api::V1::Accounts::BaseControll
   def fetch_team
     @team = Current.account.teams.find(params[:team_id])
   end
+
+  def validate_member_id_params
+    invalid_ids = params[:user_ids].map(&:to_i) - @team.account.user_ids
+
+    render json: { error: 'Invalid User IDs' }, status: :unauthorized and return if invalid_ids.present?
+  end
 end

programming_language: Ruby
filename: team_members_controller_spec.rb
change_type: ModificationType.MODIFY
diff: @@ -2,6 +2,7 @@ require 'rails_helper'
 
 RSpec.describe 'Team Members API', type: :request do
   let(:account) { create(:account) }
+  let(:account_2) { create(:account) }
   let!(:team) { create(:team, account: account) }
 
   describe 'GET /api/v1/accounts/{account.id}/teams/{team_id}/team_members' do
@@ -120,6 +121,7 @@ RSpec.describe 'Team Members API', type: :request do
 
     context 'when it is an authenticated user' do
       let(:agent) { create(:user, account: account, role: :agent) }
+      let(:agent_2) { create(:user, account: account_2, role: :agent) }
       let(:administrator) { create(:user, account: account, role: :administrator) }
 
       it 'return unauthorized for agent' do
@@ -145,6 +147,19 @@ RSpec.describe 'Team Members API', type: :request do
         json_response = JSON.parse(response.body)
         expect(json_response.count).to eq(user_ids.count)
       end
+
+      it 'ignores the user ids when its not a valid account user id' do
+        params = { user_ids: [agent_2.id] }
+
+        patch "/api/v1/accounts/#{account.id}/teams/#{team.id}/team_members",
+              params: params,
+              headers: administrator.create_new_auth_token,
+              as: :json
+
+        expect(response).to have_http_status(:unauthorized)
+        json_response = JSON.parse(response.body)
+        expect(json_response['error']).to eq('Invalid User IDs')
+      end
     end
   end
 end

programming_language: Ruby