Repository navigation
Rails 8 Tutorials
Welcome to the Rails 8 security tutorials! Rails 8 was released in November 2024 and includes several security improvements. These tutorials are organized according to the OWASP Top 10 2025 framework.
Good News: Most vulnerabilities from Rails 5 still apply to Rails 8, making RailsGoat highly relevant for Rails 8 security training!
Why? Because most web application vulnerabilities are caused by developer mistakes, not framework flaws. Even with Rails 8's improved defaults, developers can still introduce security issues by:
- Disabling built-in protections
- Using unsafe methods like
.html_safe - Writing custom authentication logic
- Not validating user input properly
- Exposing sensitive data through APIs
Access control issues occur when users can access resources they shouldn't. Rails 8 doesn't prevent these if developers don't implement proper authorization checks.
Tutorials:
- A4 - Insecure Direct Object Reference (IDOR)
- A7 - Missing Function Level Access Control
- Extras - Mass Assignment
Rails 8 Note: Parameter handling improvements with params.expect() can help prevent some access control issues when used correctly. See Rails 8 Parameter Handling
Security misconfigurations occur when security settings are incorrectly implemented or left at insecure defaults.
Tutorials:
- R4 - A5 - Security Misconfiguration
- R4 - A8 - Cross Site Request Forgery (CSRF)
- R8 - A3 - Content Security Policy (CSP) Improvements
Rails 8 Improvement: Better defaults for CSP and security headers, but developers can still misconfigure or disable protections.
Supply chain vulnerabilities involve insecure dependencies, missing integrity checks, and outdated components.
Tutorials:
-
A03 - Software Supply Chain (Rails 8) - NEW! Covers:
- Missing Subresource Integrity (SRI) on CDN assets
- Outdated dependencies with known vulnerabilities
- Lack of Software Bill of Materials (SBOM)
- Insecure gem sources
- Dependency integrity validation
Demonstration Endpoints:
- GET
/tutorials/supply_chain- Educational overview of supply chain vulnerabilities - GET
/tutorials/check_dependencies- Simulated dependency scanning
Rails 8 Note: RailsGoat intentionally demonstrates supply chain vulnerabilities by loading CDN assets without SRI checks in app/views/layouts/application.html.erb:16-17
Failures related to cryptography, including weak encryption, poor key management, and insecure hashing.
Tutorials:
- A6 - Sensitive Data Exposure
- Password hashing vulnerabilities (MD5 vs BCrypt)
- Unencrypted data storage
Rails 8 Improvement: New authentication generator uses BCrypt by default. See R8 - Authentication Improvements
Injection flaws occur when untrusted data is sent to an interpreter as part of a command or query.
Tutorials:
- R5 - A1 - SQL Injection
- R5 - A1 - Command Injection
- R5 - A1 - Code Injection
- A3 - Cross-Site Scripting (XSS)
- R8 - A1 - Regular Expression Denial of Service (ReDoS) - NEW!
Rails 8 NEW Protection: Automatic 1-second timeout on regular expressions prevents ReDoS attacks from hanging the application indefinitely. See the ReDoS tutorial for details on:
- Catastrophic backtracking patterns like
(a+)+ - Rails 8's
Regexp.timeoutprotection - Demonstration endpoints at
/tutorials/redos_emailand/tutorials/redos_username
Rails 8 Note: All Rails 5 injection vulnerabilities still apply. Rails can't prevent injection if developers use string interpolation or .html_safe incorrectly.
Insecure design represents missing or ineffective control design, different from implementation defects.
Tutorials:
- Business logic flaws
- Insufficient workflow validation
- Extras - Logic Flaws
Rails 8 Note: No framework changes affect this vulnerability category. Design flaws require secure architecture decisions by developers.
Authentication failures include broken authentication mechanisms, session management issues, and weak credential handling.
Tutorials:
- A2 - Broken Authentication and Session Management
- Weak password hashing (MD5 vs BCrypt)
- Session fixation vulnerabilities
- Credential stuffing vulnerabilities
Rails 8 Improvement: New authentication generator (rails generate authentication) provides secure authentication out-of-the-box with:
- BCrypt password hashing
-
authenticate_bymethod to prevent timing attacks - Secure session management
- Password reset functionality
See R8 - Authentication Improvements for details.
Failures related to making assumptions about data integrity without verification.
Tutorials:
- Insecure deserialization
- Parameter tampering
- Missing integrity validation
Rails 8 Improvement: Enhanced parameter handling with params.expect() provides stricter parameter filtering. See R8 - Parameter Handling
Insufficient logging, monitoring, and incident response capabilities.
Tutorials:
- Missing security event logging
- Inadequate monitoring
- No alerting for security events
Rails 8 Note: Rails provides logging infrastructure, but developers must implement security-specific logging and monitoring.
Improper exception handling that exposes sensitive information or system details.
Tutorials:
- Error messages exposing stack traces
- Unhandled exceptions revealing system information
- Debug information in production
Rails 8 Note: Same as Rails 5 - developers must properly handle exceptions and not expose sensitive error details in production.
-
ReDoS Protection ✅ NEW
- Automatic 1-second timeout on regular expressions
- Prevents catastrophic backtracking from hanging applications
- Configured via
Regexp.timeout = 1.0inconfig/initializers/regexp_timeout.rb
-
Authentication Generator ✅ Improved
- Secure authentication out-of-the-box
- BCrypt password hashing by default
-
authenticate_bymethod prevents timing attacks
-
Enhanced Parameter Handling ✅ Enhanced
-
params.expect()method for stricter parameter filtering - Better protection against mass assignment
- More explicit parameter handling
-
-
Content Security Policy Enhancements ✅ Improved
- Better CSP defaults
- Automatic nonce generation
- Enhanced XSS protection
-
Software Supply Chain Security ✅ NEW Tutorial
- Demonstrates missing SRI on CDN assets
- Shows dependency vulnerability risks
- Educational endpoints for scanning and awareness
| Vulnerability Type | Rails 5 | Rails 8 | OWASP 2025 Category |
|---|---|---|---|
| SQL Injection | Vulnerable if using string interpolation | Same | A05:2025 - Injection |
| Command Injection | Vulnerable with system() | Same | A05:2025 - Injection |
| XSS | Vulnerable with .html_safe | Same | A05:2025 - Injection |
| ReDoS | No protection | Auto timeout ✅ | A05:2025 - Injection |
| CSRF | Protected by default | Same | A02:2025 - Misconfiguration |
| IDOR | Vulnerable without auth checks | Same | A01:2025 - Broken Access Control |
| Weak Passwords | Vulnerable if using MD5 | BCrypt generator available ✅ | A04:2025 - Cryptographic Failures |
| Authentication | Manual implementation | Generator available ✅ | A07:2025 - Authentication Failures |
| Parameter Filtering | params.permit() | params.expect() ✅ | A08:2025 - Data Integrity |
| CSP | Supported | Enhanced ✅ | A02:2025 - Misconfiguration |
| Supply Chain | Not addressed | New tutorial ✅ | A03:2025 - Supply Chain Failures |
| Mass Assignment | Vulnerable without permit | params.expect() helps ✅ | A01:2025 - Broken Access Control |
| Open Redirects | Vulnerable without validation | Same | Additional Vulnerability |
Legend:
- ❌ Same = No framework changes, developers must still be careful
- ✅ Improved/NEW = Rails 8 provides better tools or protection
What Changed From Rails 5 to Rails 8? - Comprehensive security comparison and migration notes
Bottom Line: Rails 8 makes it easier to build secure apps with better defaults and tools, but the same vulnerabilities exist when developers make mistakes or disable security features. RailsGoat demonstrates these vulnerabilities are still exploitable even in Rails 8 when security best practices are not followed.
Sections are divided by their OWASP Top Ten label (A1-A10) and marked as R4 and R5 for Rails 4 and 5.