diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a28aa8e..ae1b667c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,33 @@ jobs: run: | ./node_modules/eslint/bin/eslint.js "app/javascript/**/*.js" + brakeman: + name: Brakeman + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.4.1 + - name: Cache gems + uses: actions/cache@v4 + with: + path: vendor/bundle + key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gem- + - name: Install gems + run: | + gem install bundler + bundle config path vendor/bundle + bundle install --jobs 4 --retry 4 + yarn install + sudo apt-get update + sudo apt-get install libvips + - name: Run Brakeman + run: bundle exec brakeman -q --exit-on-warn + rspec: name: RSpec runs-on: ubuntu-latest diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4a195104..47a88e05 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -45,17 +45,16 @@ class UsersController < ApplicationController return redirect_to settings_users_path, notice: I18n.t('unable_to_update_user') if Docuseal.demo? attrs = user_params.compact_blank.merge(user_params.slice(:archived_at)) - attrs.delete(:role) if !role_valid?(attrs[:role]) || current_user == @user if params.dig(:user, :account_id).present? - account = Account.accessible_by(current_ability).find(params[:user][:account_id]) + account = Account.accessible_by(current_ability).find(params.dig(:user, :account_id)) authorize!(:manage, account) @user.account = account end - if @user.update(attrs) + if @user.update(attrs.except(current_user == @user ? :role : nil)) redirect_back fallback_location: settings_users_path, notice: I18n.t('user_has_been_updated') else render turbo_stream: turbo_stream.replace(:modal, template: 'users/edit'), status: :unprocessable_entity @@ -84,8 +83,11 @@ class UsersController < ApplicationController def user_params if params.key?(:user) - params.require(:user).permit(:email, :first_name, :last_name, :password, - :role, :archived_at, :account_id) + permitted_params = %i[email first_name last_name password archived_at] + + permitted_params << :role if role_valid?(params.dig(:user, :role)) + + params.require(:user).permit(permitted_params) else {} end diff --git a/config/brakeman.ignore b/config/brakeman.ignore new file mode 100644 index 00000000..0b0632ab --- /dev/null +++ b/config/brakeman.ignore @@ -0,0 +1,8 @@ +{ + "ignored_warnings": [ + { + "fingerprint": "25f4ce5fee1e1180fa1919dc4ee78db3ab3457a956e4679503aa745771a43836", + "note": "Permitted parameters are necessary for creating submitters via API" + } + ] +}