CVE-2023-48220 (Ruby, published 2024-02-20T18:15Z)
Description: value: Decidim is a participatory democracy framework. Starting in version 0.4.rc3 and prior to version 2.0.9 of the `devise_invitable` gem, the invites feature allows users to accept the invitation for an unlimited amount of time through the password reset functionality. This issue creates vulnerable dependencies starting in version 0.0.1.alpha3 and prior to versions 0.26.9, 0.27.5, and 0.28.0 of the `decidim,` `decidim-admin`, and `decidim-system` gems. When using the password reset functionality, the `devise_invitable` gem always accepts the pending invitation if the user has been invited. The only check done is if the user has been invited but the code does not ensure that the pending invitation is still valid as defined by the `invite_for` expiry period. Decidim sets this configuration to `2.weeks` so this configuration should be respected. The bug is in the `devise_invitable` gem and should be fixed there and the dependency should be upgraded in Decidim once the fix becomes available. `devise_invitable` to version `2.0.9` and above fix this issue. Versions 0.26.9, 0.27.5, and 0.28.0 of the `decidim,` `decidim-admin`, and `decidim-system` gems contain this fix. As a workaround, invitations can be cancelled directly from the database.
Severity: nan (CVSS v3 base score: )
Weakness: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/scambra/devise_invitable
Files changed:
lib/devise_invitable/model.rb
test/models/invitable_test.rb
test/models_test.rb
test/rails_app/app/active_record/user.rb
test/rails_app/app/mongoid/user.rb
test/rails_app/config/initializers/devise.rb
test/rails_app/db/migrate/20100401102949_create_tables.rb
Commit message: clear invitation token when password is reset


Vulnerable code:
    assert_include_modules User, :database_authenticatable, :registerable, :validatable, :confirmable, :invitable
  devise :database_authenticatable, :registerable, :validatable, :confirmable, :invitable
  devise :database_authenticatable, :registerable, :validatable, :confirmable, :invitable
  config.use_salt_as_remember_token = true
      t.encryptable

Fixed code:
        # Clear invitation token when reset password token is cleared too
        def clear_reset_password_token
          self.invitation_token = nil if invited?
          super
        end

  test 'should clear invitation token while resetting the password' do
    user = User.invite!(:email => "valid@email.com")
    user.send(:generate_reset_password_token!)
    assert_present user.reset_password_token
    assert_present user.invitation_token
    User.reset_password_by_token(:reset_password_token => user.reset_password_token, :password => '123456789', :password_confirmation => '123456789')
    assert_nil user.reload.invitation_token
  end

    assert_include_modules User, :database_authenticatable, :registerable, :validatable, :confirmable, :invitable, :recoverable
  devise :database_authenticatable, :registerable, :validatable, :confirmable, :invitable, :recoverable
  devise :database_authenticatable, :registerable, :validatable, :confirmable, :invitable, :recoverable
  config.use_salt_as_remember_token = false
      t.recoverable