Skip to content

Commit cb6301e

Browse files
authored
Multiple security fixes (#6222)
* Security fix 1 * security fix 2 * Fix 3 * Fix 4 * Fix 5 * Fix 6 * Fix 7 * Fix 8 * Fix 9 * Rubo
1 parent 4d67cd7 commit cb6301e

16 files changed

+149
-50
lines changed

app/controllers/api/v1/admin/invitations_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def create
6262
end
6363

6464
def destroy
65-
invitation = Invitation.find(params[:id])
66-
if invitation.destroy
65+
invitation = Invitation.find_by(id: params[:id], provider: current_provider)
66+
67+
if invitation&.destroy
6768
render_data status: :ok
6869
else
6970
render_error status: :not_found

app/controllers/api/v1/admin/role_permissions_controller.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class RolePermissionsController < ApiController
2727
# GET /api/v1/admin/role_permissions
2828
# Returns a hash of all Role Permissions
2929
def index
30-
roles_permissions = RolePermission.joins(:permission)
31-
.where(role_id: params[:role_id])
32-
.pluck(:name, :value)
30+
roles_permissions = RolePermission.joins(:permission, :role)
31+
.where(role_id: params[:role_id], roles: { provider: current_provider })
32+
.pluck('permissions.name', 'role_permissions.value')
3333
.to_h
3434

3535
render_data data: roles_permissions, status: :ok
@@ -38,7 +38,8 @@ def index
3838
# POST /api/v1/admin/role_permissions
3939
# Updates the permission for the specified role
4040
def update
41-
role_permission = RolePermission.joins(:permission).find_by(role_id: role_params[:role_id], permission: { name: role_params[:name] })
41+
role_permission = RolePermission.joins(:permission, :role).find_by(role_id: role_params[:role_id], roles: { provider: current_provider },
42+
permission: { name: role_params[:name] })
4243

4344
return render_error status: :not_found unless role_permission
4445
return render_error status: :bad_request unless role_permission.update(value: role_params[:value].to_s)

app/controllers/api/v1/admin/roles_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def role_params
8080
end
8181

8282
def find_role
83-
@role = Role.find params[:id]
83+
@role = Role.with_provider(current_provider).find(params[:id])
8484
end
8585
end
8686
end

app/controllers/api/v1/admin/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class UsersController < ApiController
2727
# GET /api/v1/admin/users/:id.json
2828
# Updates the specified user's status
2929
def update
30-
user = User.find(params[:id])
30+
user = User.with_provider(current_provider).find(params[:id])
3131
initial_status = user.status
3232

3333
if user.update(user_params)

app/controllers/api/v1/meetings_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def running
100100
private
101101

102102
def find_room
103-
@room = Room.find_by!(friendly_id: params[:friendly_id])
103+
@room = Room.includes(:user).with_provider(current_provider).find_by!(friendly_id: params[:friendly_id])
104104
end
105105

106106
def authorized_as_viewer?(viewer_code:)

app/controllers/api/v1/recordings_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class RecordingsController < ApiController
2525
before_action only: %i[destroy] do
2626
ensure_authorized('ManageRecordings', record_id: params[:id])
2727
end
28-
before_action only: %i[update update_visibility recording_url] do
28+
before_action only: %i[update update_visibility] do
29+
ensure_authorized(%w[ManageRecordings SharedRoom], record_id: params[:id])
30+
end
31+
before_action only: %i[recording_url] do
2932
ensure_authorized(%w[ManageRecordings SharedRoom PublicRecordings], record_id: params[:id])
3033
end
3134

app/controllers/api/v1/rooms_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def recordings_processing
156156
private
157157

158158
def find_room
159-
@room = Room.find_by!(friendly_id: params[:friendly_id])
159+
@room = Room.includes(:user).with_provider(current_provider).find_by!(friendly_id: params[:friendly_id])
160160
end
161161

162162
def room_params

app/controllers/api/v1/sessions_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ def create
4747
# Will return an error if the user is NOT from the current provider and if the user is NOT a super admin
4848
return render_error status: :forbidden if !user.super_admin? && (user.provider != current_provider || external_auth?)
4949

50-
# Password is not set (local user migrated from v2)
51-
if user.external_id.blank? && user.password_digest.blank?
52-
token = user.generate_reset_token!
53-
return render_error data: token, errors: 'PasswordNotSet'
54-
end
55-
5650
if user.authenticate(session_params[:password])
5751
return render_error data: user.id, errors: Rails.configuration.custom_error_msgs[:unverified_user] unless user.verified?
5852
return render_error errors: Rails.configuration.custom_error_msgs[:pending_user] if user.pending?

config/environments/production.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,5 @@
174174
config.active_record.attributes_for_inspect = [:id]
175175

176176
# Enable DNS rebinding protection and other `Host` header attacks.
177-
# config.hosts = [
178-
# "example.com", # Allow requests from example.com
179-
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
180-
# ]
181-
# Skip DNS rebinding protection for the default health check endpoint.
182-
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
177+
config.hosts << ENV.fetch('URL_HOST') if ENV['URL_HOST'].present?
183178
end

spec/controllers/admin/invitations_controller_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,12 @@
117117
expect { delete :destroy, params: { id: 'invalid-id' } }.not_to change(Invitation, :count)
118118
expect(response).to have_http_status(:not_found)
119119
end
120+
121+
it 'does not delete invitations from another provider' do
122+
invitation = create(:invitation, provider: 'other-provider')
123+
124+
expect { delete :destroy, params: { id: invitation.id } }.not_to change(Invitation, :count)
125+
expect(response).to have_http_status(:not_found)
126+
end
120127
end
121128
end

0 commit comments

Comments
 (0)