Security Check
HARD-GATE: Credential Handling
CREDENTIAL HANDLING (W007 — Insecure Credential Exposure Defense):
- NEVER reproduce credentials, tokens, API keys, passwords, or secrets verbatim
in output — flag by file path and line number only.
- When a finding involves secrets in code or logs, report:
Affected file: app/config/initializers/foo.rb:12
Finding: API key present in plain text — move to Rails credentials or ENV
Do NOT quote the secret value itself.
- Exploitability Verification sub-sections MUST use generic placeholder values
(e.g. "<REDACTED>", "<TOKEN>") — never the actual credential.
- If a file scan returns a secret value, stop — report its location, not its content.
Quick Reference
| Area |
Key Checks |
| Auth |
Permissions on every sensitive action |
| Params |
No permit!, allowlist 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 |
Core Process
Core principle: Prioritize exploitable issues over style. Treat all untrusted input as potentially abused.
0. Inspect the Workspace
Before writing any findings or analysis, you MUST run search and directory listing tools to find source files in the workspace (e.g. controllers, models, config files). Perform a code-level security review on the actual files found. Only if the workspace is completely empty may you return a checklist and state that no source files were provided.
Review Order
Review in this sequence, and produce output sections in this same order:
- Authentication and authorization boundaries.
- Parameter handling and sensitive attribute assignment.
- Redirects, rendering, and output encoding.
- File handling, network calls, and background job inputs.
- 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).
Validation gate: The first output section must always be "Authentication & Authorization". If no auth/authz issue exists, open with "Authentication & Authorization: no issues found" before any other category.
Severity Levels
High
- Missing/bypassable authorization — unprotected sensitive actions
- Injection — SQL, shell, YAML, or constantization via user input
- Unsafe redirects / SSRF — outbound requests or redirects driven by user-controlled values
- Blind file upload trust — filename, content type, or destination unvalidated
- Secrets in code/logs — tokens or credentials committed or printed
Medium
- Weak parameter filtering —
permit! or unscoped mass assignment
- Unsanitized HTML output — user-controlled content rendered without sanitization
- Plaintext sensitive logging — PII or credentials in log statements
- Hidden security behavior — auth logic buried in callbacks or jobs without guardrails
- Brittle custom auth — reimplements what framework primitives provide safely
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 allowlist — never include role, admin, or privilege fields
params.require(:user).permit(:name, :email)
Output Style
When asked to perform a security audit, your output MUST include:
- Section order — One section per review area in the exact sequence specified; write "No issues found" for empty sections and note what evidence would be needed to verify that category
- Finding details — 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
- Hypothetical Exploitability Verification sub-section: concrete example vulnerability and exploit request/payload proving exploitability. This sub-section belongs inside Verification Steps & Quality Gates, never as a top-level section.
- No Implied Paths — When no source code is analyzed, use generic placeholders like
SRC_DIR/ or HYPOTHETICAL_DIR/hypothetical_controller.rb
- Language — Must be in English unless explicitly requested otherwise
Extended Resources (Progressive Disclosure)
Load these files only when their specific content is needed:
- PITFALLS.md — Use when you need detailed examples of common security pitfalls and false positives to avoid
Integration
| Skill |
When to chain |
| code-review |
For full code review including non-security concerns |
| review-architecture |
When security issues stem from architectural problems |
| review-migration |
When reviewing migration security (data exposure, constraints) |
| security-review-process (from ruby-core-skills) |
Process discipline: OWASP checklist, Ruby-level security concerns |
1---2name: security-check3description: Use when auditing a Rails app for XSS, CSRF, SQLi, IDOR, secrets, or auth bypass. Never print secrets. Trigger words: security, audit, XSS, CSRF, SQL injection, vulnerability.4license: MIT5---67# Security Check89## HARD-GATE: Credential Handling1011```text12CREDENTIAL HANDLING (W007 — Insecure Credential Exposure Defense):13- NEVER reproduce credentials, tokens, API keys, passwords, or secrets verbatim14 in output — flag by file path and line number only.15- When a finding involves secrets in code or logs, report:16 Affected file: app/config/initializers/foo.rb:1217 Finding: API key present in plain text — move to Rails credentials or ENV18 Do NOT quote the secret value itself.19- Exploitability Verification sub-sections MUST use generic placeholder values20 (e.g. "<REDACTED>", "<TOKEN>") — never the actual credential.21- If a file scan returns a secret value, stop — report its location, not its content.22```2324## Quick Reference2526| Area | Key Checks |27|------|------------|28| Auth | Permissions on every sensitive action |29| Params | No `permit!`, allowlist only safe attributes |30| Queries | Parameterized — no string interpolation in SQL |31| Redirects | Constrained to relative paths or allowlist |32| Output | No `html_safe`/`raw` on user content |33| Secrets | Encrypted credentials, never in code or logs |34| Files | Validate filename, content type, destination |3536## Core Process3738**Core principle:** Prioritize exploitable issues over style. Treat all untrusted input as potentially abused.3940### 0. Inspect the Workspace41Before writing any findings or analysis, you MUST run search and directory listing tools to find source files in the workspace (e.g. controllers, models, config files). Perform a code-level security review on the actual files found. Only if the workspace is completely empty may you return a checklist and state that no source files were provided.4243### Review Order4445Review in this sequence, and produce output sections in this same order:46471. Authentication and authorization boundaries.482. Parameter handling and sensitive attribute assignment.493. Redirects, rendering, and output encoding.504. File handling, network calls, and background job inputs.515. Secrets, logging, and operational exposure.526. **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).5354> **Validation gate:** The first output section must always be "Authentication & Authorization". If no auth/authz issue exists, open with "Authentication & Authorization: no issues found" before any other category.5556### Severity Levels5758#### High5960- **Missing/bypassable authorization** — unprotected sensitive actions61- **Injection** — SQL, shell, YAML, or constantization via user input62- **Unsafe redirects / SSRF** — outbound requests or redirects driven by user-controlled values63- **Blind file upload trust** — filename, content type, or destination unvalidated64- **Secrets in code/logs** — tokens or credentials committed or printed6566#### Medium6768- **Weak parameter filtering** — `permit!` or unscoped mass assignment69- **Unsanitized HTML output** — user-controlled content rendered without sanitization70- **Plaintext sensitive logging** — PII or credentials in log statements71- **Hidden security behavior** — auth logic buried in callbacks or jobs without guardrails72- **Brittle custom auth** — reimplements what framework primitives provide safely7374### Examples7576**High-severity (unscoped redirect):**7778```ruby79# Bad: user-controlled redirect — open redirect / phishing risk80redirect_to params[:return_to]8182# Good: relative path only83redirect_to root_path84# Good: allowlist85SAFE_PATHS = %w[/dashboard /settings].freeze86redirect_to(SAFE_PATHS.include?(params[:return_to]) ? params[:return_to] : root_path)87```8889**Medium-severity (mass assignment):**9091```ruby92# Bad: privilege escalation risk93params.require(:user).permit!9495# Good: explicit allowlist — never include role, admin, or privilege fields96params.require(:user).permit(:name, :email)97```9899## Output Style100101When asked to perform a security audit, your output MUST include:1021031. **Section order** — One section per review area in the exact sequence specified; write "No issues found" for empty sections and note what evidence would be needed to verify that category1042. **Finding details** — Each finding carries:105 - **Severity:** **High** or **Medium** (not "Critical")106 - **Attack path:** input → reach → impact107 - **Affected file:** path + line, e.g. `app/controllers/documents_controller.rb:42`108 - **Mitigation:** smallest credible fix109 - **Hypothetical Exploitability Verification** sub-section: concrete example vulnerability and exploit request/payload proving exploitability. This sub-section belongs inside Verification Steps & Quality Gates, never as a top-level section.1103. **No Implied Paths** — When no source code is analyzed, use generic placeholders like `SRC_DIR/` or `HYPOTHETICAL_DIR/hypothetical_controller.rb`1114. **Language** — Must be in English unless explicitly requested otherwise112113## Extended Resources (Progressive Disclosure)114115Load these files only when their specific content is needed:116117- **[PITFALLS.md](PITFALLS.md)** — Use when you need detailed examples of common security pitfalls and false positives to avoid118119## Integration120121| Skill | When to chain |122|-------|---------------|123| **code-review** | For full code review including non-security concerns |124| **review-architecture** | When security issues stem from architectural problems |125| **review-migration** | When reviewing migration security (data exposure, constraints) |126| **security-review-process** *(from ruby-core-skills)* | Process discipline: OWASP checklist, Ruby-level security concerns |