@the-bearded-bear/claude-craft 9.0.0 → 9.1.0-next.fb067bb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dev/i18n/base/Ruby/checklists/new-feature.md +113 -0
- package/Dev/i18n/base/Ruby/checklists/pre-commit.md +111 -0
- package/Dev/i18n/base/Ruby/checks/all.md +249 -0
- package/Dev/i18n/base/Ruby/checks/architecture.md +180 -0
- package/Dev/i18n/base/Ruby/checks/code-quality.md +179 -0
- package/Dev/i18n/base/Ruby/checks/security.md +183 -0
- package/Dev/i18n/base/Ruby/checks/testing.md +185 -0
- package/Dev/i18n/base/Ruby/commands/check.md +28 -0
- package/Dev/i18n/base/Ruby/rules/00-project-context.md.template +277 -0
- package/Dev/i18n/base/Ruby/templates/model.md +253 -0
- package/Dev/i18n/base/Ruby/templates/request-spec.md +273 -0
- package/Dev/i18n/base/Ruby/templates/service-object.md +212 -0
- package/Dev/i18n/de/Common/rules/12-context-management.md +1 -0
- package/Dev/i18n/de/Ruby/CLAUDE.md.template +92 -0
- package/Dev/i18n/de/Ruby/agents/ruby-reviewer.md +667 -0
- package/Dev/i18n/de/Ruby/checks/all.md +249 -0
- package/Dev/i18n/de/Ruby/commands/check.md +28 -0
- package/Dev/i18n/de/Ruby/rules/02-architecture-ruby.md +547 -0
- package/Dev/i18n/de/Ruby/rules/03-coding-standards.md +451 -0
- package/Dev/i18n/de/Ruby/rules/06-tooling.md +472 -0
- package/Dev/i18n/de/Ruby/rules/07-testing-ruby.md +542 -0
- package/Dev/i18n/de/Ruby/rules/08-quality-tools.md +397 -0
- package/Dev/i18n/de/Ruby/rules/11-security-ruby.md +566 -0
- package/Dev/i18n/en/Common/rules/12-context-management.md +1 -0
- package/Dev/i18n/en/Ruby/CLAUDE.md.template +92 -0
- package/Dev/i18n/en/Ruby/agents/ruby-reviewer.md +667 -0
- package/Dev/i18n/en/Ruby/checks/all.md +249 -0
- package/Dev/i18n/en/Ruby/commands/check.md +28 -0
- package/Dev/i18n/en/Ruby/rules/02-architecture-ruby.md +547 -0
- package/Dev/i18n/en/Ruby/rules/03-coding-standards.md +451 -0
- package/Dev/i18n/en/Ruby/rules/06-tooling.md +472 -0
- package/Dev/i18n/en/Ruby/rules/07-testing-ruby.md +542 -0
- package/Dev/i18n/en/Ruby/rules/08-quality-tools.md +397 -0
- package/Dev/i18n/en/Ruby/rules/11-security-ruby.md +566 -0
- package/Dev/i18n/es/Common/rules/12-context-management.md +1 -0
- package/Dev/i18n/es/Ruby/CLAUDE.md.template +92 -0
- package/Dev/i18n/es/Ruby/agents/ruby-reviewer.md +667 -0
- package/Dev/i18n/es/Ruby/checks/all.md +250 -0
- package/Dev/i18n/es/Ruby/commands/check.md +28 -0
- package/Dev/i18n/es/Ruby/rules/02-architecture-ruby.md +547 -0
- package/Dev/i18n/es/Ruby/rules/03-coding-standards.md +451 -0
- package/Dev/i18n/es/Ruby/rules/06-tooling.md +472 -0
- package/Dev/i18n/es/Ruby/rules/07-testing-ruby.md +542 -0
- package/Dev/i18n/es/Ruby/rules/08-quality-tools.md +397 -0
- package/Dev/i18n/es/Ruby/rules/11-security-ruby.md +566 -0
- package/Dev/i18n/fr/Common/rules/12-context-management.md +1 -0
- package/Dev/i18n/fr/Ruby/CLAUDE.md.template +92 -0
- package/Dev/i18n/fr/Ruby/agents/ruby-reviewer.md +667 -0
- package/Dev/i18n/fr/Ruby/checks/all.md +249 -0
- package/Dev/i18n/fr/Ruby/commands/check.md +28 -0
- package/Dev/i18n/fr/Ruby/rules/02-architecture-ruby.md +547 -0
- package/Dev/i18n/fr/Ruby/rules/03-coding-standards.md +451 -0
- package/Dev/i18n/fr/Ruby/rules/06-tooling.md +472 -0
- package/Dev/i18n/fr/Ruby/rules/07-testing-ruby.md +542 -0
- package/Dev/i18n/fr/Ruby/rules/08-quality-tools.md +397 -0
- package/Dev/i18n/fr/Ruby/rules/11-security-ruby.md +566 -0
- package/Dev/i18n/pt/Common/rules/12-context-management.md +1 -0
- package/Dev/i18n/pt/Ruby/CLAUDE.md.template +92 -0
- package/Dev/i18n/pt/Ruby/agents/ruby-reviewer.md +667 -0
- package/Dev/i18n/pt/Ruby/checks/all.md +249 -0
- package/Dev/i18n/pt/Ruby/commands/check.md +28 -0
- package/Dev/i18n/pt/Ruby/rules/02-architecture-ruby.md +547 -0
- package/Dev/i18n/pt/Ruby/rules/03-coding-standards.md +451 -0
- package/Dev/i18n/pt/Ruby/rules/06-tooling.md +472 -0
- package/Dev/i18n/pt/Ruby/rules/07-testing-ruby.md +542 -0
- package/Dev/i18n/pt/Ruby/rules/08-quality-tools.md +397 -0
- package/Dev/i18n/pt/Ruby/rules/11-security-ruby.md +566 -0
- package/Dev/scripts/check-config.sh +1 -1
- package/Dev/scripts/install-from-config.sh +3 -0
- package/Dev/scripts/install-ruby-rules.sh +155 -0
- package/Dev/stack-profiles/ruby/permissions.txt +4 -0
- package/Dev/stack-profiles/ruby/quality.md +3 -0
- package/Dev/stack-profiles/ruby/stack.txt +2 -0
- package/README.md +8 -3
- package/bundles/cursor/.cursorrules +4 -3
- package/bundles/windsurf/.windsurfrules +4 -3
- package/cli/lib/doctor.js +1 -1
- package/cli/lib/tech-registry.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Check Ruby / Rails Code Quality
|
|
2
|
+
|
|
3
|
+
## Arguments
|
|
4
|
+
|
|
5
|
+
$ARGUMENTS (optional: path to project to analyze)
|
|
6
|
+
|
|
7
|
+
## Plan Mode
|
|
8
|
+
|
|
9
|
+
> Plan mode is activated automatically when the scope spans multiple modules or requires cross-cutting investigation.
|
|
10
|
+
|
|
11
|
+
## MISSION
|
|
12
|
+
|
|
13
|
+
Audit code quality of the Ruby 4.0 / Rails 8.1 project: linting, idiomatic Ruby, simplicity, error handling, naming, and optional static typing. All commands run in Docker.
|
|
14
|
+
|
|
15
|
+
### Step 1: RuboCop (6 points)
|
|
16
|
+
|
|
17
|
+
Rails 8 ships `rubocop-rails-omakase` by default; teams may extend it with `rubocop-rails`, `rubocop-performance`, and `rubocop-rspec` or `rubocop-minitest`.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
docker compose exec app bin/rubocop
|
|
21
|
+
docker compose exec app bundle exec rubocop --format offenses
|
|
22
|
+
docker compose exec app bundle exec rubocop --format json > rubocop.json
|
|
23
|
+
docker compose exec app grep -rnE "rubocop:disable" app lib spec test | wc -l
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Checklist:
|
|
27
|
+
- [ ] `.rubocop.yml` exists and inherits a maintained style (omakase or equivalent)
|
|
28
|
+
- [ ] Zero offenses on the default branch
|
|
29
|
+
- [ ] `rubocop:disable` comments are rare, scoped to one line, and justified
|
|
30
|
+
- [ ] `.rubocop_todo.yml` (if any) is shrinking over time, not growing
|
|
31
|
+
- [ ] Linting runs in CI (`bin/ci` or GitHub Actions)
|
|
32
|
+
|
|
33
|
+
**Scoring**: 6 pts. 0 offenses = 6; 1-10 = 4; 11-50 = 2; > 50 or no config = 0. Deduct 1 for unjustified disables.
|
|
34
|
+
|
|
35
|
+
### Step 2: Idiomatic Ruby 4.0 (5 points)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
docker compose exec app ruby -v
|
|
39
|
+
docker compose exec app sh -c 'grep -rL "frozen_string_literal" app lib --include="*.rb" | head -20'
|
|
40
|
+
docker compose exec app grep -rnE "\.map\(&:\w+\)\.flatten|\.select.*\.first|each_with_object\(\[\]\)" app | head
|
|
41
|
+
docker compose exec app grep -rnE "\beval\(|instance_variable_get|\.send\(params" app lib | head
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Checklist:
|
|
45
|
+
- [ ] `# frozen_string_literal: true` in every Ruby file (or enforced by RuboCop `Style/FrozenStringLiteralComment`)
|
|
46
|
+
- [ ] Keyword arguments for methods with more than 2 parameters; no positional lists longer than 4
|
|
47
|
+
- [ ] Pattern matching (`case/in`) or `Data.define` / `Struct` with `keyword_init` for value-like objects instead of ad hoc hashes
|
|
48
|
+
- [ ] Safe navigation (`&.`), `then` and `tap` used sparingly and readably
|
|
49
|
+
- [ ] Enumerable methods preferred over manual loops and array mutation (`map`, `select`, `sum`)
|
|
50
|
+
- [ ] No monkey patching of core classes outside `config/initializers` with a comment; prefer refinements or wrappers
|
|
51
|
+
- [ ] No `eval`, `instance_variable_get`, or `send` with user-controlled input
|
|
52
|
+
- [ ] `.ruby-version` pins Ruby (4.0.x preferred); the Gemfile `ruby` line matches
|
|
53
|
+
- [ ] Experimental features (`Ruby::Box`) are not used in production code
|
|
54
|
+
- [ ] YJIT enabled in production when the runtime build supports it (ZJIT is the new compiler, YJIT remains available and proven)
|
|
55
|
+
|
|
56
|
+
**Scoring**: 5 pts, minus 0.5 per violated item (min 0).
|
|
57
|
+
|
|
58
|
+
### Step 3: KISS / DRY / YAGNI and Complexity (4 points)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
docker compose exec app bundle exec rubocop --only Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/ClassLength
|
|
62
|
+
# Optional deeper metrics when the gems are in the bundle
|
|
63
|
+
docker compose exec app bundle exec flog -g app | head -20
|
|
64
|
+
docker compose exec app bundle exec flay app | head -20
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Project targets (rule 05): methods < 10 lines (limit 20), cyclomatic complexity < 5 (limit 10), nesting <= 3, parameters <= 4.
|
|
68
|
+
|
|
69
|
+
Checklist:
|
|
70
|
+
- [ ] Guard clauses and early returns instead of nested `if`
|
|
71
|
+
- [ ] No duplicated business rules (rule of three before abstracting)
|
|
72
|
+
- [ ] No speculative abstractions: one-implementation interfaces, unused options, unused parameters
|
|
73
|
+
- [ ] No metaprogramming (`define_method`, `method_missing`) where plain methods work
|
|
74
|
+
- [ ] No dead code and no leftover debug statements
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
docker compose exec app bin/rails notes
|
|
78
|
+
docker compose exec app grep -rnE "binding\.irb|byebug|debugger|^\s*(puts|pp) " app lib | head
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Scoring**: 4 pts. Deduct 1 per 5 methods exceeding limits, 1 for duplication hotspots, 1 for leftover debug statements, 1 for speculative abstractions.
|
|
82
|
+
|
|
83
|
+
### Step 4: Error Handling (4 points)
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
docker compose exec app grep -rnE "rescue Exception|^\s*rescue\s*$" app lib | head -20
|
|
87
|
+
docker compose exec app grep -rnE -A1 "^\s*rescue" app lib | grep -E "^\S+-\s*nil\s*$" | head
|
|
88
|
+
docker compose exec app grep -rnE "rescue_from" app/controllers
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Checklist:
|
|
92
|
+
- [ ] No bare `rescue` or `rescue Exception`; rescue the narrowest class
|
|
93
|
+
- [ ] No swallowed errors (`rescue` then `nil`); handle, log with context, or re-raise
|
|
94
|
+
- [ ] Domain errors are explicit classes inheriting `StandardError` under a namespace
|
|
95
|
+
- [ ] Controllers map errors through `rescue_from` or a shared concern; no stack traces in responses
|
|
96
|
+
- [ ] Bang methods (`save!`, `update!`, `create!`) used where failure must abort a transaction
|
|
97
|
+
- [ ] Jobs declare `retry_on` / `discard_on` for known transient/permanent failures
|
|
98
|
+
- [ ] Errors reported through `Rails.error.report` or an error tracker
|
|
99
|
+
|
|
100
|
+
**Scoring**: 4 pts, minus 1 per violated item group.
|
|
101
|
+
|
|
102
|
+
### Step 5: Naming and Documentation (3 points)
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
docker compose exec app bundle exec rubocop --only Naming
|
|
106
|
+
docker compose exec app bundle exec yard stats --list-undoc | tail -20
|
|
107
|
+
docker compose exec app ls README.md CHANGELOG.md docs
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Checklist:
|
|
111
|
+
- [ ] Classes/modules `CamelCase`, methods and variables `snake_case`, constants `SCREAMING_SNAKE_CASE`
|
|
112
|
+
- [ ] Predicate methods end in `?`; `!` only when a safer counterpart exists
|
|
113
|
+
- [ ] File names match constants (Zeitwerk)
|
|
114
|
+
- [ ] Comments explain WHY, not WHAT; no commented-out code
|
|
115
|
+
- [ ] Public service/query APIs have a short header comment with inputs and return value
|
|
116
|
+
- [ ] README documents Docker setup, `bin/setup`, `bin/ci`, and deployment (Kamal)
|
|
117
|
+
|
|
118
|
+
**Scoring**: 3 pts (1 naming, 1 comments, 1 README/docs).
|
|
119
|
+
|
|
120
|
+
### Step 6: Typing and Tooling (3 points)
|
|
121
|
+
|
|
122
|
+
Typing is optional in Ruby. Never penalize a project that deliberately has none when tests compensate.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
docker compose exec app ls sig rbs_collection.yaml sorbet
|
|
126
|
+
docker compose exec app bundle exec steep check | tail -10
|
|
127
|
+
docker compose exec app bundle exec srb tc | tail -10
|
|
128
|
+
docker compose exec app bin/ci
|
|
129
|
+
docker compose exec app bundle outdated --strict | head -20
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Checklist:
|
|
133
|
+
- [ ] If RBS/Steep or Sorbet is adopted, it passes with no errors in CI
|
|
134
|
+
- [ ] `bin/ci` (Rails 8.1) exists and runs lint, security scans, and tests
|
|
135
|
+
- [ ] `bundler-audit` and Brakeman are part of CI
|
|
136
|
+
- [ ] Gems are justified and maintained; `bundle outdated --strict` is reviewed regularly
|
|
137
|
+
|
|
138
|
+
**Scoring**: 3 pts (1 typing if adopted or tests compensate, 1 CI pipeline, 1 dependency hygiene).
|
|
139
|
+
|
|
140
|
+
## OUTPUT FORMAT
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
RUBY / RAILS CODE QUALITY AUDIT
|
|
144
|
+
===============================
|
|
145
|
+
|
|
146
|
+
SCORE: XX/25
|
|
147
|
+
|
|
148
|
+
RuboCop offenses: N Files without frozen_string_literal: N Methods over limit: N
|
|
149
|
+
|
|
150
|
+
SUB-SCORES:
|
|
151
|
+
RuboCop : XX/6
|
|
152
|
+
Idiomatic Ruby : XX/5
|
|
153
|
+
KISS / DRY / YAGNI : XX/4
|
|
154
|
+
Error handling : XX/4
|
|
155
|
+
Naming and documentation : XX/3
|
|
156
|
+
Typing and tooling : XX/3
|
|
157
|
+
|
|
158
|
+
STRENGTHS:
|
|
159
|
+
- [...]
|
|
160
|
+
|
|
161
|
+
ISSUES (by severity):
|
|
162
|
+
- CRITICAL: [file:line] [description] -> [fix]
|
|
163
|
+
- IMPORTANT: ...
|
|
164
|
+
- MINOR: ...
|
|
165
|
+
|
|
166
|
+
AUTO-FIXABLE:
|
|
167
|
+
docker compose exec app bundle exec rubocop -a # safe corrections
|
|
168
|
+
docker compose exec app bundle exec rubocop -A # unsafe: review the diff first
|
|
169
|
+
|
|
170
|
+
RECOMMENDATIONS:
|
|
171
|
+
1. [Action] (effort, impact)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## IMPORTANT NOTES
|
|
175
|
+
|
|
176
|
+
- Run `rubocop -a` only on a clean git tree and review the diff; never `-A` blindly
|
|
177
|
+
- Match the project's existing RuboCop profile; do not impose another style
|
|
178
|
+
- Cite `file:line` for every issue
|
|
179
|
+
- Treat Rails-generated files (`db/schema.rb`, `bin/*`) as excluded from style findings
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Check Ruby / Rails Security
|
|
2
|
+
|
|
3
|
+
## Arguments
|
|
4
|
+
|
|
5
|
+
$ARGUMENTS (optional: path to project to analyze)
|
|
6
|
+
|
|
7
|
+
## Plan Mode
|
|
8
|
+
|
|
9
|
+
> Plan mode is activated automatically when the scope spans multiple modules or requires cross-cutting investigation.
|
|
10
|
+
|
|
11
|
+
## MISSION
|
|
12
|
+
|
|
13
|
+
Security audit of a Ruby 4.0 / Rails 8.1 application, aligned with OWASP Top 10:2025. Combine automated scanners (Brakeman, bundler-audit) with targeted manual review. All commands run in Docker. Security findings are ALWAYS top priority in the consolidated report.
|
|
14
|
+
|
|
15
|
+
### Step 1: Brakeman Static Analysis (6 points)
|
|
16
|
+
|
|
17
|
+
Rails 8 ships Brakeman by default (`bin/brakeman`).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
docker compose exec app bin/brakeman --no-pager -q
|
|
21
|
+
docker compose exec app bundle exec brakeman -f json -o brakeman.json
|
|
22
|
+
docker compose exec app bundle exec brakeman --no-pager -q --confidence-level 1
|
|
23
|
+
ls config/brakeman.ignore
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Checklist:
|
|
27
|
+
- [ ] Brakeman runs in CI and fails the build on new warnings
|
|
28
|
+
- [ ] Zero High-confidence warnings
|
|
29
|
+
- [ ] `config/brakeman.ignore` entries each have a note explaining why the warning is a false positive
|
|
30
|
+
- [ ] Brakeman version is current (it tracks Rails releases)
|
|
31
|
+
|
|
32
|
+
**Scoring**: 6 pts. Any High confidence warning (SQL injection, command injection, mass assignment, unsafe deserialization, XSS) = -3 each (min 0). Medium = -1 each. Unjustified ignore entries = -1.
|
|
33
|
+
|
|
34
|
+
### Step 2: Dependency Vulnerabilities (4 points)
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
docker compose exec app bundle exec bundler-audit check --update
|
|
38
|
+
docker compose exec app bundle outdated --strict | head -20
|
|
39
|
+
docker compose exec app bin/rails about
|
|
40
|
+
ls .github/dependabot.yml renovate.json
|
|
41
|
+
docker compose exec app grep -nE "^\s*gem .*(git:|github:)" Gemfile
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Checklist:
|
|
45
|
+
- [ ] `bundler-audit` reports no known advisories (or each is documented with a mitigation)
|
|
46
|
+
- [ ] Rails and Ruby are on supported releases: Rails 8.1 is supported until 2027-10-10; Rails 8.0 reaches end of life on 2026-11-07; Ruby 4.0.x is current
|
|
47
|
+
- [ ] Dependabot or Renovate configured for `bundler`, `github-actions`, and `docker`
|
|
48
|
+
- [ ] `Gemfile.lock` committed; gems pinned through the lockfile
|
|
49
|
+
- [ ] No gems from Git branches without a pinned `ref`
|
|
50
|
+
- [ ] Container image and system packages scanned (Trivy or Grype) in CI
|
|
51
|
+
|
|
52
|
+
**Scoring**: 4 pts. Critical advisory = -2, High = -1, EOL framework version = -1.
|
|
53
|
+
|
|
54
|
+
### Step 3: Secrets and Credentials (4 points)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
docker compose exec app ls config/credentials* config/master.key .env*
|
|
58
|
+
git ls-files | grep -E "master\.key|\.env$|\.pem$"
|
|
59
|
+
docker compose exec app grep -rnEi "(api[_-]?key|secret|password|token)\s*[:=]\s*['\"][A-Za-z0-9_\-]{12,}" app config lib --include="*.rb" --include="*.yml"
|
|
60
|
+
docker compose exec app grep -rn "secret_key_base" config
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Checklist:
|
|
64
|
+
- [ ] `config/master.key` and all `config/credentials/*.key` are gitignored and never committed
|
|
65
|
+
- [ ] Secrets stored in encrypted credentials (`bin/rails credentials:edit --environment production`) or in a secrets manager / Kamal secrets
|
|
66
|
+
- [ ] No hardcoded keys, tokens, or passwords in source, YAML, Dockerfiles, or CI files
|
|
67
|
+
- [ ] `RAILS_MASTER_KEY` injected at deploy time only
|
|
68
|
+
- [ ] `config.filter_parameters` covers passwords, tokens, and personal data so they never reach logs
|
|
69
|
+
- [ ] Sensitive columns use Active Record Encryption (`encrypts :ssn`) with keys in credentials; deterministic encryption only where querying is required
|
|
70
|
+
|
|
71
|
+
**Scoring**: 4 pts. Committed secret = 0 for the whole step.
|
|
72
|
+
|
|
73
|
+
### Step 4: Authentication and Authorization (4 points)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
docker compose exec app grep -rnE "has_secure_password|authenticate_by|generates_token_for|devise" app Gemfile
|
|
77
|
+
docker compose exec app grep -rnE "skip_before_action|allow_unauthenticated_access|skip_forgery_protection|protect_from_forgery" app
|
|
78
|
+
docker compose exec app grep -rnE "authorize|policy_scope|can\?|load_and_authorize" app/controllers | wc -l
|
|
79
|
+
docker compose exec app grep -rnE "\.find\(params\[:id\]\)" app/controllers | head -20
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Checklist:
|
|
83
|
+
- [ ] Authentication uses the Rails 8 generator (`bin/rails generate authentication`), Devise, or an equivalent maintained solution; no home-grown crypto
|
|
84
|
+
- [ ] Passwords: `has_secure_password` (bcrypt) is the Rails default and acceptable; Argon2id is preferred for new non-Rails-default code (minimum OWASP 19 MiB / t=2 / p=1). Never MD5 or SHA1. Bcrypt inputs are limited to 72 bytes
|
|
85
|
+
- [ ] Use `User.authenticate_by(email:, password:)` for timing-safe credential checks
|
|
86
|
+
- [ ] Password reset and email confirmation tokens via `generates_token_for` (expiring, signed)
|
|
87
|
+
- [ ] Sessions: cookies `httponly`, `secure`, `same_site: :lax` or `:strict`; session reset on login (`reset_session`)
|
|
88
|
+
- [ ] CSRF protection active (`protect_from_forgery` is the default via `ActionController::Base`); `skip_forgery_protection` only on token-authenticated API controllers
|
|
89
|
+
- [ ] Every controller action authorized (deny by default); `allow_unauthenticated_access` or `skip_before_action :authenticate` is explicit and minimal
|
|
90
|
+
- [ ] IDOR prevented: records are loaded through the current user's scope (`current_user.orders.find(params[:id])`), not `Order.find`
|
|
91
|
+
- [ ] MFA available for privileged accounts; brute-force protection active (see Step 6)
|
|
92
|
+
- [ ] Multi-tenant apps scope every query by tenant (default scope or `acts_as_tenant`) and have isolation tests
|
|
93
|
+
|
|
94
|
+
**Scoring**: 4 pts. Missing authorization on a data-returning action = -2. IDOR pattern = -1 each (min 0).
|
|
95
|
+
|
|
96
|
+
### Step 5: Injection, XSS, Mass Assignment (4 points)
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# SQL injection: interpolation in query fragments
|
|
100
|
+
docker compose exec app grep -rnE "(where|order|group|having|joins|select|pluck|find_by_sql|exists\?|calculate)\([^)]*#\{" app lib
|
|
101
|
+
docker compose exec app grep -rnE "connection\.(execute|select_all|exec_query)\(.*#\{" app lib
|
|
102
|
+
# XSS: unsafe output
|
|
103
|
+
docker compose exec app grep -rnE "html_safe|raw\(|raw @|<%==|sanitize\(.*tags" app
|
|
104
|
+
# Mass assignment
|
|
105
|
+
docker compose exec app grep -rnE "permit!|params\.to_unsafe_h|params\[:\w+\]\)$" app/controllers
|
|
106
|
+
# Command injection, unsafe deserialization, open redirects
|
|
107
|
+
docker compose exec app grep -rnE "system\(|exec\(|\`.*#\{|%x|Open3|Kernel\.open|YAML\.load\(|Marshal\.load" app lib
|
|
108
|
+
docker compose exec app grep -rnE "redirect_to params|redirect_to \w+\.(referer|referrer)" app
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Checklist:
|
|
112
|
+
- [ ] SQL built only with placeholders or hash conditions: `where("email = ?", email)` or `where(email: email)`, never `"... #{value}"`; `order` column names whitelisted
|
|
113
|
+
- [ ] Views rely on ERB auto-escaping; `html_safe` / `raw` / `<%==` only on trusted, sanitized content and never on user input
|
|
114
|
+
- [ ] Rich text rendered via `sanitize` with an explicit allowlist or Action Text
|
|
115
|
+
- [ ] Strong parameters on every create/update: `params.expect(user: [:name, :email])` (Rails 8) or `params.require(:user).permit(...)`; never `permit!`; role/admin flags never permitted from user input
|
|
116
|
+
- [ ] No `system`, backticks, or `Open3` with interpolated user input; arguments passed as arrays
|
|
117
|
+
- [ ] No `YAML.load` or `Marshal.load` on untrusted data (`YAML.safe_load` with permitted classes)
|
|
118
|
+
- [ ] `redirect_to` targets validated (`url_from`, `allow_other_host: false`)
|
|
119
|
+
- [ ] File uploads: Active Storage content-type validation, size limits, no user-controlled filenames on disk, served from a separate domain or with `Content-Disposition: attachment`
|
|
120
|
+
- [ ] Outbound HTTP to user-supplied URLs guarded against SSRF (allowlist, block private ranges)
|
|
121
|
+
|
|
122
|
+
**Scoring**: 4 pts. Each confirmed injection = -2; each unsafe `html_safe` on user data = -1; `permit!` = -1 (min 0).
|
|
123
|
+
|
|
124
|
+
### Step 6: Secure Configuration, Headers, Rate Limiting (3 points)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
docker compose exec app grep -nE "force_ssl|assume_ssl|hosts|consider_all_requests_local|log_level" config/environments/production.rb
|
|
128
|
+
docker compose exec app cat config/initializers/content_security_policy.rb
|
|
129
|
+
docker compose exec app grep -rnE "rate_limit|Rack::Attack" app config Gemfile
|
|
130
|
+
docker compose exec app grep -rnE "default_headers|Permissions-Policy|Referrer-Policy" config
|
|
131
|
+
docker compose exec app grep -nE "cors|Rack::Cors" Gemfile config -r
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Checklist:
|
|
135
|
+
- [ ] Production: `config.force_ssl = true` and `config.assume_ssl = true` behind a TLS-terminating proxy (Thruster/Kamal proxy); HSTS active
|
|
136
|
+
- [ ] `config.consider_all_requests_local = false`; generic error pages; no stack traces exposed
|
|
137
|
+
- [ ] `config.hosts` allowlist set (DNS rebinding protection), with a health check exclusion for `/up`
|
|
138
|
+
- [ ] Content Security Policy initializer enabled and enforced (not report-only forever); nonces for inline scripts when needed
|
|
139
|
+
- [ ] Security headers present: `X-Content-Type-Options: nosniff`, `Referrer-Policy`, `Permissions-Policy`, COOP/CORP where applicable
|
|
140
|
+
- [ ] Rate limiting on login, password reset, signup, and expensive endpoints: Rails 8 `rate_limit to: 10, within: 3.minutes, only: :create` in controllers, or `rack-attack` for IP-level throttling
|
|
141
|
+
- [ ] CORS restricted to explicit origins (no `*` with credentials)
|
|
142
|
+
- [ ] Logs exclude secrets (`filter_parameters`); log retention >= 1 year where compliance requires; auth failures are logged and alerted
|
|
143
|
+
- [ ] Rails 8.1 `bin/ci` includes Brakeman and bundler-audit steps
|
|
144
|
+
|
|
145
|
+
**Scoring**: 3 pts (1 transport/errors/hosts, 1 CSP and headers, 1 rate limiting and CORS).
|
|
146
|
+
|
|
147
|
+
## OUTPUT FORMAT
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
RUBY / RAILS SECURITY AUDIT
|
|
151
|
+
===========================
|
|
152
|
+
|
|
153
|
+
SCORE: XX/25
|
|
154
|
+
|
|
155
|
+
Brakeman: H high / M medium / L weak bundler-audit: N advisories
|
|
156
|
+
|
|
157
|
+
SUB-SCORES:
|
|
158
|
+
Brakeman : XX/6
|
|
159
|
+
Dependencies : XX/4
|
|
160
|
+
Secrets and credentials : XX/4
|
|
161
|
+
Authentication / authorization: XX/4
|
|
162
|
+
Injection / XSS / mass assign.: XX/4
|
|
163
|
+
Configuration / headers / rate limiting: XX/3
|
|
164
|
+
|
|
165
|
+
STRENGTHS:
|
|
166
|
+
- [...]
|
|
167
|
+
|
|
168
|
+
VULNERABILITIES (by severity):
|
|
169
|
+
- CRITICAL: [OWASP category] [file:line] [description] -> [fix]
|
|
170
|
+
- HIGH: ...
|
|
171
|
+
- MEDIUM: ...
|
|
172
|
+
- LOW: ...
|
|
173
|
+
|
|
174
|
+
RECOMMENDATIONS:
|
|
175
|
+
1. [Action] (effort, impact)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## IMPORTANT NOTES
|
|
179
|
+
|
|
180
|
+
- Never print secret values in the report; cite the file and line only
|
|
181
|
+
- Verify every scanner hit before reporting it (Brakeman produces false positives)
|
|
182
|
+
- A confirmed exploitable finding (injection, auth bypass, committed secret) caps the overall security score at 12/25
|
|
183
|
+
- Do not run exploit payloads against shared or production environments
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Check Ruby / Rails Testing
|
|
2
|
+
|
|
3
|
+
## Arguments
|
|
4
|
+
|
|
5
|
+
$ARGUMENTS (optional: path to project to analyze)
|
|
6
|
+
|
|
7
|
+
## Plan Mode
|
|
8
|
+
|
|
9
|
+
> Plan mode is activated automatically when the scope spans multiple modules or requires cross-cutting investigation.
|
|
10
|
+
|
|
11
|
+
## MISSION
|
|
12
|
+
|
|
13
|
+
Audit the test suite of the Rails 8.1 / Ruby 4.0 project. Both frameworks are supported: **RSpec** (`rspec-rails`, `spec/`) and **Minitest** (Rails default, `test/`). Detect which one is used and apply the matching commands. TDD (Red, Green, Refactor) and coverage >= 80% are mandatory. All commands run in Docker.
|
|
14
|
+
|
|
15
|
+
### Step 1: Detect Framework and Run the Suite
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
docker compose exec app ls spec test
|
|
19
|
+
docker compose exec app grep -nE "rspec-rails|minitest|factory_bot|capybara|simplecov|shoulda|webmock|vcr" Gemfile
|
|
20
|
+
# RSpec
|
|
21
|
+
docker compose exec app bundle exec rspec --format progress
|
|
22
|
+
# Minitest
|
|
23
|
+
docker compose exec app bin/rails test
|
|
24
|
+
docker compose exec app bin/rails test:system
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Record: framework, number of examples, failures, pending/skipped, duration.
|
|
28
|
+
|
|
29
|
+
### Step 2: Code Coverage (7 points)
|
|
30
|
+
|
|
31
|
+
SimpleCov must be loaded first in `spec/spec_helper.rb` or `test/test_helper.rb` (before application code).
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
docker compose exec app grep -rn "SimpleCov" spec/spec_helper.rb test/test_helper.rb .simplecov
|
|
35
|
+
docker compose exec app env COVERAGE=true bundle exec rspec
|
|
36
|
+
docker compose exec app env COVERAGE=true bin/rails test
|
|
37
|
+
docker compose exec app cat coverage/.last_run.json
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Checklist:
|
|
41
|
+
- [ ] SimpleCov configured with `minimum_coverage 80` (and ideally `minimum_coverage_by_file 60`)
|
|
42
|
+
- [ ] Branch coverage enabled (`enable_coverage :branch`)
|
|
43
|
+
- [ ] Parallel runs merged (`SimpleCov.collate` or `use_merging`)
|
|
44
|
+
- [ ] Coverage enforced in CI
|
|
45
|
+
- [ ] Mutation testing (`mutant` or equivalent) used on critical domain code, since coverage alone gives false confidence
|
|
46
|
+
|
|
47
|
+
**Scoring**: 7 pts. >= 90% = 7; 80-89% = 5; 70-79% = 3; 50-69% = 1; < 50% or no coverage tool = 0.
|
|
48
|
+
|
|
49
|
+
### Step 3: Model and Object Unit Tests (6 points)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
docker compose exec app sh -c 'ls app/models/*.rb | wc -l; ls spec/models test/models | wc -l'
|
|
53
|
+
docker compose exec app sh -c 'ls app/services app/queries app/forms app/policies app/jobs'
|
|
54
|
+
docker compose exec app sh -c 'ls spec/services spec/queries spec/jobs test/services test/jobs'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Checklist:
|
|
58
|
+
- [ ] Every model has tests for validations, associations (shoulda-matchers or explicit), scopes, and domain methods
|
|
59
|
+
- [ ] Every service, form, query, and policy object has tests for the success path and each failure path
|
|
60
|
+
- [ ] Jobs tested for behavior and idempotency (`perform_enqueued_jobs`, `assert_enqueued_with`)
|
|
61
|
+
- [ ] Mailers tested for recipients, subject, and key content
|
|
62
|
+
- [ ] Edge cases covered: nil, empty, boundary values, time zones (`travel_to` / `freeze_time`)
|
|
63
|
+
- [ ] Tests follow AAA (Arrange, Act, Assert), one behavior per example, descriptive names
|
|
64
|
+
- [ ] Bug fixes come with a regression test written first (fails before the fix)
|
|
65
|
+
|
|
66
|
+
**Scoring**: 6 pts. Proportional to the share of models/objects with meaningful tests (assertions on behavior, not implementation).
|
|
67
|
+
|
|
68
|
+
### Step 4: Request and Integration Tests (5 points)
|
|
69
|
+
|
|
70
|
+
Prefer request specs (RSpec `type: :request`) or integration tests (`ActionDispatch::IntegrationTest`) over controller tests.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
docker compose exec app sh -c 'ls spec/requests test/integration test/controllers'
|
|
74
|
+
docker compose exec app grep -rnE "type: :controller|ActionController::TestCase" spec test
|
|
75
|
+
docker compose exec app grep -rnE "get |post |patch |put |delete " spec/requests test/integration | wc -l
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Checklist:
|
|
79
|
+
- [ ] Each routed resource has request tests for success, validation failure (422), unauthenticated (401/redirect), and unauthorized (403/404) cases
|
|
80
|
+
- [ ] Response status, body shape (JSON schema or key assertions), and persistence side effects asserted
|
|
81
|
+
- [ ] Authentication helper used (sign in through the session flow, not by stubbing internals)
|
|
82
|
+
- [ ] Tenant isolation tests: a user cannot read or modify another tenant's records
|
|
83
|
+
- [ ] Rate-limited endpoints tested (`rate_limit` returns 429 after the threshold)
|
|
84
|
+
- [ ] No legacy controller specs for new code
|
|
85
|
+
|
|
86
|
+
**Scoring**: 5 pts. Deduct 1 per critical resource without request tests, max -5.
|
|
87
|
+
|
|
88
|
+
### Step 5: System Tests (3 points)
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
docker compose exec app sh -c 'ls spec/system test/system'
|
|
92
|
+
docker compose exec app grep -nE "driven_by|capybara|selenium|cuprite|playwright" spec/rails_helper.rb test/application_system_test_case.rb Gemfile
|
|
93
|
+
docker compose exec app bin/rails test:system
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Checklist:
|
|
97
|
+
- [ ] Critical user journeys (signup, login, core purchase/creation flow) covered by Capybara system tests
|
|
98
|
+
- [ ] Headless browser available in the Docker test image (Chrome/Chromium via Selenium or Cuprite)
|
|
99
|
+
- [ ] Hotwire interactions (Turbo Frames/Streams, Stimulus) verified through real browser behavior
|
|
100
|
+
- [ ] Tests wait with Capybara's built-in synchronization (`assert_selector`, `have_content`), never `sleep`
|
|
101
|
+
- [ ] System tests stay a small share of the suite (about 10%, pyramid: 70% unit, 20% integration, 10% E2E)
|
|
102
|
+
- [ ] Failure screenshots saved as CI artifacts
|
|
103
|
+
|
|
104
|
+
**Scoring**: 3 pts (1 coverage of critical journeys, 1 stability, 1 Hotwire/JS coverage).
|
|
105
|
+
|
|
106
|
+
### Step 6: Factories, Fixtures and Data (2 points)
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
docker compose exec app sh -c 'ls spec/factories test/factories test/fixtures spec/fixtures'
|
|
110
|
+
docker compose exec app bundle exec rake factory_bot:lint
|
|
111
|
+
docker compose exec app grep -rnE "create\(:|create_list" spec test | wc -l
|
|
112
|
+
docker compose exec app grep -rnE "build_stubbed|build\(" spec test | wc -l
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Checklist:
|
|
116
|
+
- [ ] FactoryBot factories (or Rails fixtures, consistently) produce valid records; `factory_bot:lint` passes
|
|
117
|
+
- [ ] Factories are minimal; traits express variants; no deep association chains created by default
|
|
118
|
+
- [ ] `build` / `build_stubbed` preferred over `create` when persistence is not needed
|
|
119
|
+
- [ ] Fixtures (if used) are small, labeled, and not shared through hidden coupling
|
|
120
|
+
- [ ] Sensitive production data is never copied into fixtures or factories
|
|
121
|
+
|
|
122
|
+
**Scoring**: 2 pts (1 validity and lint, 1 minimalism and speed).
|
|
123
|
+
|
|
124
|
+
### Step 7: Isolation, Speed and Reliability (2 points)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
docker compose exec app bundle exec rspec --order random --profile 10
|
|
128
|
+
docker compose exec app bin/rails test --seed 12345
|
|
129
|
+
docker compose exec app grep -rnE "sleep\(|sleep [0-9]|Time\.now|Date\.today|allow_any_instance_of|expect_any_instance_of" spec test
|
|
130
|
+
docker compose exec app grep -rnE "xit |xdescribe|skip |pending" spec test | wc -l
|
|
131
|
+
docker compose exec app grep -rnE "webmock|vcr|WebMock" Gemfile spec test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Checklist:
|
|
135
|
+
- [ ] Tests run in random order and pass with different seeds
|
|
136
|
+
- [ ] Each test uses transactional isolation or database cleaning; no order dependence
|
|
137
|
+
- [ ] Time is injected (`travel_to`, `freeze_time`), never `sleep`
|
|
138
|
+
- [ ] External HTTP is blocked and stubbed (WebMock/VCR); no real network in tests
|
|
139
|
+
- [ ] Mocks limited to boundaries (HTTP, clock, payments); no `allow_any_instance_of`, no mocking the object under test
|
|
140
|
+
- [ ] No skipped/pending tests without a ticket; no commented-out tests
|
|
141
|
+
- [ ] Suite is parallelized (`parallelize(workers: :number_of_processors)` or `parallel_tests`) and the unit suite runs in minutes at most
|
|
142
|
+
- [ ] Flaky tests tracked and fixed, not retried blindly
|
|
143
|
+
|
|
144
|
+
**Scoring**: 2 pts (1 isolation and determinism, 1 mocking discipline and speed).
|
|
145
|
+
|
|
146
|
+
## OUTPUT FORMAT
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
RUBY / RAILS TESTING AUDIT
|
|
150
|
+
==========================
|
|
151
|
+
|
|
152
|
+
SCORE: XX/25
|
|
153
|
+
|
|
154
|
+
Framework: [RSpec/Minitest] Examples: N Failures: N Skipped: N Duration: Ns
|
|
155
|
+
Coverage: XX% (line) XX% (branch)
|
|
156
|
+
|
|
157
|
+
SUB-SCORES:
|
|
158
|
+
Code coverage : XX/7
|
|
159
|
+
Model / object unit tests : XX/6
|
|
160
|
+
Request / integration tests : XX/5
|
|
161
|
+
System tests : XX/3
|
|
162
|
+
Factories / fixtures : XX/2
|
|
163
|
+
Isolation / speed : XX/2
|
|
164
|
+
|
|
165
|
+
STRENGTHS:
|
|
166
|
+
- [...]
|
|
167
|
+
|
|
168
|
+
ISSUES (by severity):
|
|
169
|
+
- CRITICAL: [file or resource] [description] -> [fix]
|
|
170
|
+
- IMPORTANT: ...
|
|
171
|
+
- MINOR: ...
|
|
172
|
+
|
|
173
|
+
UNTESTED CODE (top 10 by risk):
|
|
174
|
+
- [path] (coverage XX%)
|
|
175
|
+
|
|
176
|
+
RECOMMENDATIONS:
|
|
177
|
+
1. [Action] (effort, impact)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## IMPORTANT NOTES
|
|
181
|
+
|
|
182
|
+
- If the suite fails, report the failures first; a red suite caps the testing score at 10/25
|
|
183
|
+
- Do not modify tests during the audit; only report
|
|
184
|
+
- Judge tests on behavior (WHAT), not implementation (HOW)
|
|
185
|
+
- Support both RSpec and Minitest; never recommend a migration between them as an audit finding
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Ruby/Rails audit by axis: architecture, code-quality, security, testing, or all (scored aggregate)"
|
|
3
|
+
argument-hint: "<architecture|code-quality|security|testing|all> [path]"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Ruby / Rails Check
|
|
7
|
+
|
|
8
|
+
## Arguments
|
|
9
|
+
|
|
10
|
+
$ARGUMENTS
|
|
11
|
+
|
|
12
|
+
The first argument is the axis; the rest (for example a project path) is passed on. Without an axis, run `all`.
|
|
13
|
+
|
|
14
|
+
| Axis | Checklist to follow |
|
|
15
|
+
|------|---------------------|
|
|
16
|
+
| `architecture` | `.claude/references/ruby/checks/architecture.md` |
|
|
17
|
+
| `code-quality` | `.claude/references/ruby/checks/code-quality.md` |
|
|
18
|
+
| `security` | `.claude/references/ruby/checks/security.md` |
|
|
19
|
+
| `testing` | `.claude/references/ruby/checks/testing.md` |
|
|
20
|
+
| `all` | `.claude/references/ruby/checks/all.md`: the 4 axes, then a consolidated report scored out of 100 |
|
|
21
|
+
|
|
22
|
+
## MISSION
|
|
23
|
+
|
|
24
|
+
1. Read the first argument. If it is not one of the 5 axes above, list them with an example (`/ruby:check security app/`) and stop.
|
|
25
|
+
2. Read the checklist file of that axis and follow it step by step. In that file, `$ARGUMENTS` stands for the arguments that follow the axis.
|
|
26
|
+
3. Produce the report in the output format the checklist defines.
|
|
27
|
+
|
|
28
|
+
Examples: `/ruby:check architecture`, `/ruby:check testing ./app`, `/ruby:check all`.
|