Rails Security Review
Use this skill when the task is to review or harden Rails code from a security perspective.
Core principle: Prioritize exploitable issues over style. Assume any untrusted input can be abused.
HARD-GATE: Authorization Findings Lead the Report
BEFORE returning your security review, verify:
1. The FIRST finding section in your output is "Authentication & Authorization"
2. SQL injection, XSS, or other findings come AFTER auth/authz — even if
they feel more severe or were discovered first
3. If no auth/authz issue exists, the report still opens with an explicit
"Authentication & Authorization: no issues found" line BEFORE any other
finding category
Quick Reference
| Area |
Key Checks |
| Auth |
Permissions on every sensitive action |
| Params |
No permit!, whitelist only safe attributes |
| Queries |
Parameterized — no string interpolation in SQL |
| Redirects |
Constrained to relative paths or allowlist |
| Output |
No html_safe/raw on user content |
| Secrets |
Encrypted credentials, never in code or logs |
| Files |
Validate filename, content type, destination |
Review Order
- Check authentication and authorization boundaries.
- Check parameter handling and sensitive attribute assignment.
- Check redirects, rendering, and output encoding.
- Check file handling, network calls, and background job inputs.
- Check secrets, logging, and operational exposure.
- Verify each finding: Confirm it is exploitable with a concrete attack scenario before reporting. Exclude false positives (e.g.,
html_safe on a developer-defined constant, not user input).
Severity Levels
High
- Missing or bypassable authorization checks
- SQL, shell, YAML, or constantization injection paths
- Unsafe redirects or SSRF-capable outbound requests
- File upload handling that trusts filename, content type, or destination blindly
- Secrets or tokens stored in code, logs, or unsafe config
Medium
- Unscoped mass assignment through weak parameter filtering
- User-controlled HTML rendered without clear sanitization
- Sensitive data logged in plaintext
- Security-relevant behavior hidden in callbacks or background jobs without guardrails
- Brittle custom auth logic where framework primitives would be safer
Review Checklist
- Are permissions enforced on every sensitive action?
- Are untrusted inputs validated before database, filesystem, or network use?
- Are redirects and URLs constrained?
- Are secrets stored and logged safely?
- Are security assumptions explicit and testable?
Examples
High-severity (unscoped redirect):
# Bad: user-controlled redirect — open redirect / phishing risk
redirect_to params[:return_to]
# Good: relative path only
redirect_to root_path
# Good: allowlist
SAFE_PATHS = %w[/dashboard /settings].freeze
redirect_to(SAFE_PATHS.include?(params[:return_to]) ? params[:return_to] : root_path)
Medium-severity (mass assignment):
# Bad: privilege escalation risk
params.require(:user).permit!
# Good: explicit whitelist — never include role, admin, or privilege fields
params.require(:user).permit(:name, :email)
Pitfalls
See PITFALLS.md for the full list. Critical anti-patterns: permit! on any parameter set, html_safe on user content, SQL string interpolation, secrets in committed files.
Output Style
Section order per the HARD-GATE. Every heading appears even when empty (write "No issues found.").
## Authentication & Authorization
## Parameter Handling & Mass Assignment
## Query Safety (SQL / NoSQL / shell injection)
## Output Encoding & Redirects
## Secrets, Logging & Operational Exposure
Each finding carries:
- Severity: High or Medium (not "Critical")
- Attack path: input → reach → impact
- Affected file: path + line, e.g.
app/controllers/documents_controller.rb:42
- Mitigation: smallest credible fix
Integration
| Skill |
When to chain |
| rails-code-review |
For full code review including non-security concerns |
| rails-architecture-review |
When security issues stem from architectural problems |
| rails-migration-safety |
When reviewing migration security (data exposure, constraints) |
1---
2name: rails-security-review
3license: MIT
4description: >
5 Performs security audits and vulnerability assessments on Ruby on Rails application
6 code. Use when reviewing Rails code for security risks, assessing authentication or
7 authorization, auditing parameter handling, redirects, file uploads, secrets management,
8 or checking for XSS, CSRF, SSRF, SQL injection, and other common vulnerabilities.
9metadata:
10 source: https://skillmd.com/skills/aibot88/rails-security-review
11---
12
13# Rails Security Review
14
15Use this skill when the task is to review or harden Rails code from a security perspective.
16
17**Core principle:** Prioritize exploitable issues over style. Assume any untrusted input can be abused.
18
19## HARD-GATE: Authorization Findings Lead the Report
20
21```
22BEFORE returning your security review, verify:
23 1. The FIRST finding section in your output is "Authentication & Authorization"
24 2. SQL injection, XSS, or other findings come AFTER auth/authz — even if
25 they feel more severe or were discovered first
26 3. If no auth/authz issue exists, the report still opens with an explicit
27 "Authentication & Authorization: no issues found" line BEFORE any other
28 finding category
29```
30
31## Quick Reference
32
33| Area | Key Checks |
34|------|------------|
35| Auth | Permissions on every sensitive action |
36| Params | No `permit!`, whitelist only safe attributes |
37| Queries | Parameterized — no string interpolation in SQL |
38| Redirects | Constrained to relative paths or allowlist |
39| Output | No `html_safe`/`raw` on user content |
40| Secrets | Encrypted credentials, never in code or logs |
41| Files | Validate filename, content type, destination |
42
43## Review Order
44
451. Check authentication and authorization boundaries.
462. Check parameter handling and sensitive attribute assignment.
473. Check redirects, rendering, and output encoding.
484. Check file handling, network calls, and background job inputs.
495. Check secrets, logging, and operational exposure.
506. **Verify each finding:** Confirm it is exploitable with a concrete attack scenario before reporting. Exclude false positives (e.g., `html_safe` on a developer-defined constant, not user input).
51
52## Severity Levels
53
54### High
55
56- Missing or bypassable authorization checks
57- SQL, shell, YAML, or constantization injection paths
58- Unsafe redirects or SSRF-capable outbound requests
59- File upload handling that trusts filename, content type, or destination blindly
60- Secrets or tokens stored in code, logs, or unsafe config
61
62### Medium
63
64- Unscoped mass assignment through weak parameter filtering
65- User-controlled HTML rendered without clear sanitization
66- Sensitive data logged in plaintext
67- Security-relevant behavior hidden in callbacks or background jobs without guardrails
68- Brittle custom auth logic where framework primitives would be safer
69
70## Review Checklist
71
72- Are permissions enforced on every sensitive action?
73- Are untrusted inputs validated before database, filesystem, or network use?
74- Are redirects and URLs constrained?
75- Are secrets stored and logged safely?
76- Are security assumptions explicit and testable?
77
78## Examples
79
80**High-severity (unscoped redirect):**
81
82```ruby
83# Bad: user-controlled redirect — open redirect / phishing risk
84redirect_to params[:return_to]
85
86# Good: relative path only
87redirect_to root_path
88# Good: allowlist
89SAFE_PATHS = %w[/dashboard /settings].freeze
90redirect_to(SAFE_PATHS.include?(params[:return_to]) ? params[:return_to] : root_path)
91```
92
93**Medium-severity (mass assignment):**
94
95```ruby
96# Bad: privilege escalation risk
97params.require(:user).permit!
98
99# Good: explicit whitelist — never include role, admin, or privilege fields
100params.require(:user).permit(:name, :email)
101```
102
103## Pitfalls
104
105See [PITFALLS.md](./PITFALLS.md) for the full list. Critical anti-patterns: `permit!` on any parameter set, `html_safe` on user content, SQL string interpolation, secrets in committed files.
106
107## Output Style
108
109Section order per the HARD-GATE. Every heading appears even when empty (write "No issues found.").
110
111```
112## Authentication & Authorization
113## Parameter Handling & Mass Assignment
114## Query Safety (SQL / NoSQL / shell injection)
115## Output Encoding & Redirects
116## Secrets, Logging & Operational Exposure
117```
118
119Each finding carries:
120- **Severity:** **High** or **Medium** (not "Critical")
121- **Attack path:** input → reach → impact
122- **Affected file:** path + line, e.g. `app/controllers/documents_controller.rb:42`
123- **Mitigation:** smallest credible fix
124
125## Integration
126
127| Skill | When to chain |
128|-------|---------------|
129| **rails-code-review** | For full code review including non-security concerns |
130| **rails-architecture-review** | When security issues stem from architectural problems |
131| **rails-migration-safety** | When reviewing migration security (data exposure, constraints) |