Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brakeman does not understand enums #1492

Closed
obromios opened this issue Jul 10, 2020 · 1 comment
Closed

Brakeman does not understand enums #1492

obromios opened this issue Jul 10, 2020 · 1 comment

Comments

@obromios
Copy link

Background

Brakeman version: 4.8.2
Rails version: 6.0.3.2
Ruby version: 2.6.6

Rails application code

Consider a User model

    # app/models/user.rb
    class User
       enum status: [:sad, :bored, :happy]
    end

In a controller, I want to receive params[:status] and return all users with that status

i.e.

    # app/controllers/users_controller.rb
    class UsersController << ApplicationController
       def index_status
          status = "#{params[:status]}"
          if User.statuses.include? status
             @status = status.to_sym
             @countries = User.send(@status)
          else
            redirect_to root_path, notice: 'Invalid status'
        end
    end

*** What problem are you seeing?

The code works, but Brakeman gives me a dangerous send - User controlled method execution warning for the line

@countries = User.send(@status)

This was asked as a question on SO, and Justin posted a comment that Brakeman does not understand enums

@presidentbeef
Copy link
Owner

Fixed by #1618

Repository owner locked and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants