rails-hardening-ruby-v1
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.cookies-serializer-marshal
Section titled “keryn.rails.ruby.cookies-serializer-marshal”warning ruby ruby, rails
The cookie serializer is :marshal or :hybrid. Marshal deserializes arbitrary Ruby objects, so anyone who obtains the secret key base (or finds a verifier bypass) turns a forged cookie into code execution. Use :json.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: depends_on something relies on a component it does not verify; it crosses the supply-chain boundary (code, models or prompts pulled in from outside).
Fix: Set config.action_dispatch.cookies_serializer = :json. Migrate existing sessions with :hybrid for one deploy only, then switch to :json.
References: https://guides.rubyonrails.org/configuring.html#config-action-dispatch-cookies-serializer
keryn.rails.ruby.tls-verify-none
Section titled “keryn.rails.ruby.tls-verify-none”warning ruby ruby, rails
Certificate verification is switched off (OpenSSL::SSL::VERIFY_NONE). Any host on the network path can impersonate the server and read or change the traffic. Keep VERIFY_PEER and fix the trust store instead.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: trusts one party believes another without evidence.
Fix: Use verify_mode = OpenSSL::SSL::VERIFY_PEER (the default) and point ca_file at the private CA when needed.
References: https://docs.ruby-lang.org/en/master/OpenSSL/SSL.html
keryn.rails.ruby.json-html-entities-unescaped
Section titled “keryn.rails.ruby.json-html-entities-unescaped”warning ruby ruby, rails
escape_html_entities_in_json is set to false. JSON embedded in an HTML page can then close a script tag or open markup (<, >, &). Leave the default (true) unless every JSON response is served as application/json only.
Confidence 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.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Delete the line or set ActiveSupport::JSON::Encoding.escape_html_entities_in_json = true.
References: https://api.rubyonrails.org/classes/ActiveSupport/JSON.html
keryn.rails.ruby.validation-format-line-anchors
Section titled “keryn.rails.ruby.validation-format-line-anchors”warning ruby ruby, rails
A format validation regex is not anchored to the whole string with \A … \z. ^ and $ match at every line in Ruby, so “ok\n<script>x</script>” passes a regex meant to accept one line, and an unanchored or half-anchored regex accepts any value that merely contains (or starts or ends with) a valid part. Anchor with \A and \z.
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: Write the expression with \A at the start and \z at the end. Rails raises when ^ or $ is used without multiline: true; do not set that flag to silence the error.
References: https://guides.rubyonrails.org/security.html#regular-expressions
keryn.rails.ruby.weak-rsa-key-size
Section titled “keryn.rails.ruby.weak-rsa-key-size”warning ruby ruby, rails
An RSA key shorter than 2048 bits is generated. Keys under 2048 bits can be factored with moderate resources. Use 2048 bits at least; 3072 for keys that outlive 2030.
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: OpenSSL::PKey::RSA.generate(3072).
References: https://docs.ruby-lang.org/en/master/OpenSSL/PKey/RSA.html
keryn.rails.ruby.csrf-protection-disabled
Section titled “keryn.rails.ruby.csrf-protection-disabled”warning ruby ruby, rails
CSRF token verification is skipped or turned off (skip_before_action :verify_authenticity_token, allow_forgery_protection = false). A third-party page can then submit state-changing requests with the visitor’s cookies. Skip it only for token-authenticated API endpoints, and name the actions.
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 skip, or limit it to the API actions that authenticate with a bearer token (skip_before_action :verify_authenticity_token, only: :webhook). Keep protect_from_forgery with: :exception.
References: https://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
keryn.rails.ruby.permit-privileged-attribute
Section titled “keryn.rails.ruby.permit-privileged-attribute”warning ruby ruby, rails
Strong parameters permit a privileged attribute (admin, role, banned, account_id, owner_id, …). Any client that can post the form can set it. Keep privileged attributes out of the permitted list and set them in code after an authorization check.
Confidence P2: a heuristic or a posture check: confirm by reading the code. 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: Remove the key from permit and assign it in the controller or service after checking the caller’s role.
References: https://guides.rubyonrails.org/action_controller_overview.html#strong-parameters
keryn.rails.ruby.secret-key-literal
Section titled “keryn.rails.ruby.secret-key-literal”warning ruby ruby, rails
The session signing secret (secret_token or secret_key_base) is a string literal in the source. Anyone with repository access can forge session cookies, and with the Marshal serializer, execute code. Read it from credentials or the environment.
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: Use Rails.application.credentials.secret_key_base or ENV.fetch(“SECRET_KEY_BASE”). Rotate the value that was committed.
References: https://guides.rubyonrails.org/security.html#custom-credentials