3 ms·
One tip (of the many, many good ones in there) that I'd like to pull out for you is using scoped finds, as it establishes security by convention rather than req
by patio11 17y ago
One tip (of the many, many good ones in there) that I'd like to pull out for you is using scoped finds, as it establishes security by convention rather than requiring programmers to make the right choices every time.
Actual examples from my code base:
@word_list = @user.word_lists.find(params[:wl])
versus the alternative (of which there are multiple variations):
@word_list = WordList.find(params[:wl], :conditions => {:user_id => @user})
This will work fine... right until one of your programmers forgets to put that condition statement in there. Then, you'll allow folks arbitrary access to other people's data, silently. I have seen a lot of Rails code that guards against this by checking access before critical actions -- again, this will work fine until you forget to do it. Instead, establish the convention that you only instantiate the model objects through something which guarantees authorization, and then the existence of the model object is proof that access to it is authorized. (Adjust as required if you work in banking or state secrets. I write bingo cards for a living.)