rails-hardening-ruby-v2
8 rules · Keryn Software Licence · rules 0.8.0 · all packs
How to read a rule
- Severity
- How bad the finding is if it is real:
errorfails a default gate,warningandinfodo 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
Section titled “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 one thing invokes another.
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://datatracker.ietf.org/doc/html/rfc8017#section-7.1
keryn.rails.ruby.default-route-wildcard
Section titled “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 one thing invokes another.
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
keryn.rails.ruby.session-cookie-insecure
Section titled “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 one thing invokes another.
Fix: Drop :httponly => false / :session_http_only => 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/configuring.html#config-session-store
keryn.rails.ruby.basic-auth-hardcoded-password
Section titled “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 authority is given or left unchecked.
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
keryn.rails.ruby.detailed-exceptions-enabled
Section titled “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 one thing invokes another.
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
keryn.rails.ruby.detailed-exceptions-production
Section titled “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 one thing invokes another.
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
keryn.rails.ruby.skip-auth-filter-except
Section titled “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 authority is given or left unchecked.
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
keryn.rails.ruby.mass-assignment-without-protection
Section titled “keryn.rails.ruby.mass-assignment-without-protection”warning ruby ruby, rails
:without_protection => 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 one thing invokes another.
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