Auth and Security for Ruby on Railss
Authentication and security in Rails covers proving who a user is and protecting the app from common attacks. Rails ships has_secure_password and an authentication generator, while gems like Devise offer more. Built-in defences handle CSRF, SQL injection, XSS escaping and secure cookies, and authorisation controls what a signed-in user may do.
Stage: Features · Part of the Ruby on Rails roadmap · Last reviewed 19 November 2026
What to learn in Auth and Security
- Add password login with has_secure_password and bcrypt
- Keep the current user in a session and protect routes
- Explain how CSRF tokens protect form submissions
- Avoid SQL injection by using parameterised queries
- Add role checks using Pundit or a similar pattern
Auth and Security interview questions
How does Rails protect against SQL injection?
Active Record queries with hash conditions or placeholders, like where('name = ?', name), send values separately from the SQL text so they cannot change the query. Building SQL by interpolating user input into strings bypasses this protection and must be avoided.
What is the difference between authentication and authorisation?
Authentication verifies identity, for example with an email and password. Authorisation decides what that identity may do, such as editing only their own posts. Rails apps often use Devise or built-in code for the first and Pundit or CanCanCan for the second.
Where Auth and Security fits in the Ruby on Rails roadmap
Auth and Security belongs to the Features stage (intermediate level), which takes about 25 hours. Real applications.
Other units in this stage
Back to the full Ruby on Rails roadmap