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

Betterment/UnscopedFind False Positive #51

Open
6f6d6172 opened this issue Aug 12, 2024 · 0 comments
Open

Betterment/UnscopedFind False Positive #51

6f6d6172 opened this issue Aug 12, 2024 · 0 comments
Labels
good first issue Good for newcomers

Comments

@6f6d6172
Copy link
Contributor

  def test
    some_user.other_model.active.find_by_token(token)
  end

  def token
    params[:token]
  end

This raises an offense, even though we're operating in a trusted context (off of some_user). Interestingly, using find_by(token:) and find(token) do not raise offenses, despite fundamentally being the same level of risk. The way we look for dynamic method names may be to blame.

        METHOD_PATTERN = /^find_by_(.+?)(!)?$/
...
        # yoinked from Rails/DynamicFindBy
        def static_method_name(method_name)
          match = METHOD_PATTERN.match(method_name)
          return nil unless match

          match[2] ? 'find_by!' : 'find_by'
        end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant