You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UnscopedFind has made the assumption that if you're doing a find off of an object (e.g. current_user), your query will be scoped to whatever belongs to that object. However, it turns out there's an unscoped method which when called at any point will remove any scopes, effectively letting you find any object regardless of who owns it.
For example, current_user.cats.find(params[:id]) will not raise an offense because the find call on cats is scoped to the current user. This same logic is erroneously extended to current_user.cats.unscoped.find(params[:id]), which does the same query but without the where clause that scopes it to the current user.
This cop should be modified to flag any uses of unscoped.
I was able to put together this diff that is the bare minimum needed to start detecting unscoped calls, but I haven't taken the time to sit down and list out test cases or write any specs.
UnscopedFind has made the assumption that if you're doing a
find
off of an object (e.g.current_user
), your query will be scoped to whatever belongs to that object. However, it turns out there's an unscoped method which when called at any point will remove any scopes, effectively letting you find any object regardless of who owns it.For example,
current_user.cats.find(params[:id])
will not raise an offense because thefind
call oncats
is scoped to the current user. This same logic is erroneously extended tocurrent_user.cats.unscoped.find(params[:id])
, which does the same query but without the where clause that scopes it to the current user.This cop should be modified to flag any uses of
unscoped
.I was able to put together this diff that is the bare minimum needed to start detecting
unscoped
calls, but I haven't taken the time to sit down and list out test cases or write any specs.tl;dr todo
unscoped
The text was updated successfully, but these errors were encountered: