# rails-hardening-ruby-v2

> rails-hardening-ruby-v2: 8 Keryn rules for ruby (8 warning).

Source: https://keryn.dev/rules/rails-hardening-ruby-v2/

8 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do not.

- **Confidence**: **P0** exploitable as written; **P1** dangerous in context; **P2** a heuristic or a posture check: confirm by reading the code.

- **False-positive risk**: **low**: an exact API or flag, so hits are almost always real; **medium**: the pattern is legitimate in many programs, so check each hit; **high**: it finds a lead to confirm, so expect benign hits.

- **Edge**: The relationship the finding sits on. **reaches**: content or traffic gets to a thing; **calls**: one thing invokes another; **reads**: one thing reads from another; **writes**: one thing writes to another; **sends**: data leaves for another party; **grants**: authority is given or left unchecked; **depends_on**: something relies on a component it does not verify; **trusts**: one party believes another without evidence. The boundary it crosses, when there is one: **user->prompt** (untrusted input reaching a prompt); **model->code** (model output reaching code, a shell, a query or a page); **secret->outside** (a secret leaving the trusted side); **supply-chain** (code, models or prompts pulled in from outside).

- **Taxonomy chips**: References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.

## keryn.rails.ruby.rsa-weak-padding

`warning` ruby ruby, rails

An RSA operation uses PKCS#1 v1.5 padding (the default of public\_encrypt, private\_decrypt and PKey#encrypt), no padding, or SSLv23 padding. PKCS#1 v1.5 encryption is open to padding-oracle attacks (Bleichenbacher) and raw RSA without padding is malleable and deterministic. Use OAEP for encryption and PSS for signatures.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-780](https://keryn.dev/rules/?cwe=CWE-780) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Pass OpenSSL::PKey::RSA::PKCS1\_OAEP\_PADDING to public\_encrypt / private\_decrypt, or rsa\_padding\_mode: "oaep" to PKey#encrypt and #decrypt; sign and verify with rsa\_padding\_mode: "pss". Use private\_encrypt / public\_decrypt only for legacy interoperability.

**References:** [https://docs.ruby-lang.org/en/master/OpenSSL/PKey/RSA.html](https://docs.ruby-lang.org/en/master/OpenSSL/PKey/RSA.html) · [https://datatracker.ietf.org/doc/html/rfc8017#section-7.1](https://datatracker.ietf.org/doc/html/rfc8017#section-7.1)

## keryn.rails.ruby.default-route-wildcard

`warning` ruby ruby, rails

A catch-all route maps :controller and :action from the URL. Every public method of every controller becomes reachable over any HTTP verb, including helpers never meant as actions and state-changing actions over GET. Declare resources and explicit routes instead.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-749](https://keryn.dev/rules/?cwe=CWE-749) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Remove the legacy default route (map.connect ':controller/:action/:id' or match ':controller(/:action(/:id))') and declare resources :name, only: [...] or explicit get/post routes for each action.

**References:** [https://guides.rubyonrails.org/routing.html#non-resourceful-routes](https://guides.rubyonrails.org/routing.html#non-resourceful-routes)

## keryn.rails.ruby.session-cookie-insecure

`warning` ruby ruby, rails

The session configuration turns HttpOnly off for the session cookie or writes the cookie-signing secret into the source. Without HttpOnly any XSS reads the session cookie; a committed secret lets anyone with the repository forge sessions. Keep HttpOnly on and load the secret from the environment or credentials.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-1004](https://keryn.dev/rules/?cwe=CWE-1004) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Drop :httponly =&gt; false / :session\_http\_only =&gt; false, and read the secret with ENV.fetch("SECRET\_KEY\_BASE") or Rails.application.credentials.

**References:** [https://guides.rubyonrails.org/security.html#session-storage](https://guides.rubyonrails.org/security.html#session-storage) · [https://guides.rubyonrails.org/configuring.html#config-session-store](https://guides.rubyonrails.org/configuring.html#config-session-store)

## keryn.rails.ruby.basic-auth-hardcoded-password

`warning` ruby ruby, rails

HTTP basic authentication checks a password written in the source (a literal or a constant), or compares the password with ==. A committed password is shared with everyone who can read the repository, and == leaks the match length through timing. Load the credential from the environment and compare with ActiveSupport::SecurityUtils.secure\_compare.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-798](https://keryn.dev/taxonomies/cwe/#cwe-798-use-of-hard-coded-credentials) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Use http\_basic\_authenticate\_with name: ENV.fetch("ADMIN\_USER"), password: ENV.fetch("ADMIN\_PASSWORD"), or inside authenticate\_or\_request\_with\_http\_basic compare with ActiveSupport::SecurityUtils.secure\_compare(password, expected).

**References:** [https://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html](https://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html)

## keryn.rails.ruby.detailed-exceptions-enabled

`warning` ruby ruby, rails

The controller overrides show\_detailed\_exceptions? with something other than false. Whenever it returns true the error page shows stack traces, source excerpts and request details to the requester. Keep detailed exceptions to development, or to a check that cannot be influenced by the request.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-209](https://keryn.dev/rules/?cwe=CWE-209) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Delete the show\_detailed\_exceptions? override (or return false), and set config.consider\_all\_requests\_local = false in config/environments/production.rb.

**References:** [https://guides.rubyonrails.org/configuring.html#config-consider-all-requests-local](https://guides.rubyonrails.org/configuring.html#config-consider-all-requests-local)

## keryn.rails.ruby.detailed-exceptions-production

`warning` ruby ruby, rails

The production environment sets consider\_all\_requests\_local = true, so every visitor gets the developer error page with stack traces, source excerpts and request details. Set it to false in production.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-209](https://keryn.dev/rules/?cwe=CWE-209) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Delete the show\_detailed\_exceptions? override (or return false), and set config.consider\_all\_requests\_local = false in config/environments/production.rb.

**References:** [https://guides.rubyonrails.org/configuring.html#config-consider-all-requests-local](https://guides.rubyonrails.org/configuring.html#config-consider-all-requests-local)

## keryn.rails.ruby.skip-auth-filter-except

`warning` ruby ruby, rails

An authentication or CSRF filter is skipped with :except, so every action not listed (including actions added later) runs without it. Skip filters with :only and name the actions that may run unauthenticated.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-862](https://keryn.dev/taxonomies/cwe/#cwe-862-missing-authorization) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Replace skip\_before\_action :authenticate\_user!, except: [...] with skip\_before\_action :authenticate\_user!, only: [:public\_action].

**References:** [https://guides.rubyonrails.org/action_controller_overview.html#filters](https://guides.rubyonrails.org/action_controller_overview.html#filters)

## keryn.rails.ruby.mass-assignment-without-protection

`warning` ruby ruby, rails

:without\_protection =&gt; true switches off attr\_accessible / attr\_protected for this call, so every attribute in the hash is assigned, including role, admin and owner columns. Assign privileged attributes explicitly.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-915](https://keryn.dev/taxonomies/cwe/#cwe-915) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Remove :without\_protection and set the privileged attributes one by one after an authorization check, or move to strong parameters.

**References:** [https://guides.rubyonrails.org/v3.2/security.html#mass-assignment](https://guides.rubyonrails.org/v3.2/security.html#mass-assignment)
