Skip to content

    Type a page, a command such as keryn scan, or a rule id.

    general-injection-ruby-v1

    View as Markdown

    19 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: 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.general.ruby.sql-injection-request-to-query

    Section titled “keryn.general.ruby.sql-injection-request-to-query”

    error ruby data-flow rule ruby, rails

    A request value (params, cookies, headers) is passed as SQL text to an ActiveRecord query method or to a raw connection call (where, order, group, joins, select, pluck, from, find_by_sql, execute, Arel.sql, …). The value can change the query. Use a hash or placeholder form (where(name: value), where(“name = ?”, value)), allowlist column and direction names, and cast numbers with to_i.

    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; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-89 LLM05

    Fix: Use hash conditions (where(name: params[:name])) or placeholders (where(“name = ?”, params[:name])). For order, group and pluck map the request value through an allowlist (SORTABLE.fetch(params[:sort], “id”)). Quote identifiers with connection.quote_column_name and values with connection.quote; use sanitize_sql_like for LIKE patterns.

    References: https://guides.rubyonrails.org/security.html#sql-injection · https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html

    keryn.general.ruby.command-injection-request

    Section titled “keryn.general.ruby.command-injection-request”

    error ruby data-flow rule ruby, rails

    A request value reaches an operating-system command (system, exec, spawn, backticks or %x, IO.popen, Open3, PTY.spawn, Kernel#open). The attacker can append commands or pass options. Pass the command and its arguments as separate list elements without a shell, validate the value against an allowlist, and never build the command line from request text.

    Confidence P0: exploitable as written. 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).

    CWE-78 LLM05

    Fix: Use the multi-argument form system(“convert”, “–”, path) so no shell parses the text, validate the value against a fixed allowlist, and use File.basename / Shellwords.escape only as a second layer. Replace open(url) with URI.parse(url).open or Net::HTTP after validating the host.

    References: https://guides.rubyonrails.org/security.html#command-line-injection · https://ruby-doc.org/core/Kernel.html#method-i-system

    error ruby data-flow rule ruby, rails

    A request value is evaluated as Ruby code (eval, instance_eval, class_eval, module_eval, binding.eval, Kernel#eval). The attacker runs arbitrary code in the Rails process. Replace evaluation with a lookup in an allowlist of operations.

    Confidence P0: exploitable as written. 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).

    CWE-95 LLM05

    Fix: Never evaluate request text. Map the request value to a fixed set of permitted operations (a Hash of lambdas) and reject unknown keys. For arithmetic or expressions use a parser that has no access to Ruby objects.

    References: https://guides.rubyonrails.org/security.html#injection · https://ruby-doc.org/core/Kernel.html#method-i-eval

    error ruby data-flow rule ruby, rails

    A request value is used as a file name or path (File.read/open/new/write/delete, IO.read, send_file, FileUtils, Dir, Pathname, render file:). With ../ segments or an absolute path the attacker reads or overwrites files outside the intended directory. Reduce the value to File.basename, or look it up in an allowlist, and confirm the expanded path stays inside the base directory.

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

    Edge inspected: reads one thing reads from another.

    CWE-22 LLM05

    Fix: Take File.basename(value) and join it to a fixed directory, or resolve through an id-to-path table. After File.expand_path check that the result starts with the base directory plus File::SEPARATOR. Do not pass request text to send_file.

    References: https://guides.rubyonrails.org/security.html#file-uploads · https://community.owasp.org/attacks/Path_Traversal

    warning ruby data-flow rule ruby, rails

    A request value decides where redirect_to sends the browser. A link with an attacker-chosen URL sends users to a phishing page from your domain. Redirect to a path built from a fixed route helper, use only_path: true, or compare the host against an allowlist first.

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

    Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).

    CWE-601 LLM05

    Fix: Use redirect_to(path_helper_url(id: params[:id])), or redirect_to(url_from(params[:next])) on Rails 7+, or validate: URI.parse(value).host must be nil or in an allowlist. A relative-path check must also reject values beginning with // or a backslash.

    References: https://guides.rubyonrails.org/security.html#redirection-and-files · https://api.rubyonrails.org/classes/ActionController/Redirecting.html

    keryn.general.ruby.render-request-to-template

    Section titled “keryn.general.ruby.render-request-to-template”

    error ruby data-flow rule ruby, rails

    A request value is rendered as a template or response body (render inline:, render text:, render html:, render file:, render template:, render action:, or the legacy render with a path). inline: and file: let the attacker run Ruby through ERB; text: and html: write unescaped markup into the page. Render a fixed template and pass the value as a local, or choose the template from an allowlist.

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

    Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).

    CWE-94 LLM05

    Fix: Render a fixed template (render :show, locals: {name: params[:name]}) and let the template escape the value. When the template name must vary, map the request value through an allowlist of template names. Use render plain: for text that is not markup.

    References: https://guides.rubyonrails.org/layouts_and_rendering.html · https://portswigger.net/web-security/server-side-template-injection

    keryn.general.ruby.erb-template-from-request

    Section titled “keryn.general.ruby.erb-template-from-request”

    error ruby data-flow rule ruby, rails

    A request value becomes the source of an ERB (or Haml, Slim) template. Template source executes Ruby, so the attacker runs code in the process. Keep templates in files and pass request data as locals.

    Confidence P0: exploitable as written. False-positive risk low: an exact API or flag, so hits are almost always real.

    Edge inspected: calls one thing invokes another.

    CWE-1336 LLM05

    Fix: Load templates from files in the repository (ERB.new(File.read(TEMPLATE_PATH))) and pass the request value only as a binding variable. Never compile text that came from a request, a cookie, or a user-editable record without a sandboxed engine such as Liquid.

    References: https://docs.ruby-lang.org/en/master/ERB.html

    keryn.general.ruby.mass-assignment-permit-all

    Section titled “keryn.general.ruby.mass-assignment-permit-all”

    warning ruby ruby, rails

    Strong parameters are switched off: params.permit! marks every submitted key as permitted, and permit_all_parameters = true does so for the whole application. A caller can set any attribute, such as admin, role or owner_id. List the permitted keys 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.

    CWE-915 LLM05

    Fix: Replace params.permit! with params.require(:user).permit(:name, :email) listing each field the form really submits, and delete config.action_controller.permit_all_parameters = true.

    References: https://guides.rubyonrails.org/action_controller_overview.html#strong-parameters · https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-permit-21

    keryn.general.ruby.mass-assignment-unpermitted-params

    Section titled “keryn.general.ruby.mass-assignment-unpermitted-params”

    warning ruby ruby, rails

    The raw params hash (or a whole sub-hash of it) is passed to a model constructor, create_with, update, assign_attributes or find_or_create_by. Without strong parameters (permit) the caller chooses which attributes are set, including privileged ones. Pass params.require(:x).permit(…) with an explicit key list.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: calls one thing invokes another.

    CWE-915 LLM05

    Fix: Add a private method that returns params.require(:user).permit(:name, :email) and pass that. Keep privileged attributes (admin, role, tenant ids) out of the permitted list and set them in code.

    References: https://guides.rubyonrails.org/action_controller_overview.html#strong-parameters

    keryn.general.ruby.unsafe-deserialization-request

    Section titled “keryn.general.ruby.unsafe-deserialization-request”

    error ruby data-flow rule ruby, rails

    A request value is deserialized with a loader that instantiates arbitrary Ruby objects (YAML.load on Psych before 4, YAML.unsafe_load, Marshal.load, Oj.load in object mode, JSON.load with create_additions). Crafted input runs code through gadget chains. Parse with YAML.safe_load, JSON.parse or Oj in strict mode.

    Confidence P0: exploitable as written. 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).

    CWE-502 LLM05

    Fix: Use YAML.safe_load(value, permitted_classes: [], aliases: false), JSON.parse(value), Oj.load(value, mode: :strict). Never Marshal.load data a client can alter, including cookies and cache entries not integrity-protected.

    References: https://ruby-doc.org/core/Marshal.html · https://docs.ruby-lang.org/en/master/Psych.html

    keryn.general.ruby.unsafe-reflection-request

    Section titled “keryn.general.ruby.unsafe-reflection-request”

    error ruby data-flow rule ruby, rails

    A request value chooses a class or method by name (constantize, safe_constantize, const_get, send, public_send, __send__, method, try, to_proc). The attacker picks any class or method, including dangerous ones such as Kernel#system. Map the request value through an allowlist of permitted names.

    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; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-470 LLM05

    Fix: Look the name up in a fixed Hash (ALLOWED = {“csv” => CsvExporter}.freeze; ALLOWED.fetch(params[:kind])) and call the result. Reject any value that is not a key. Prefer public_send with an allowlisted symbol over send.

    References: https://guides.rubyonrails.org/security.html#unsafe-reflection · https://cwe.mitre.org/data/definitions/470.html

    warning ruby ruby, rails

    MD5 or SHA-1 is used (Digest::MD5, Digest::SHA1, OpenSSL::Digest with “md5” or “sha1”). Both are broken for collision resistance and unfit for passwords, signatures, tokens or integrity checks. Use SHA-256 or better, and bcrypt, scrypt or Argon2 for passwords.

    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: calls one thing invokes another.

    CWE-328 LLM05

    Fix: Use Digest::SHA256 or OpenSSL::Digest.new(“SHA256”) for checksums, OpenSSL::HMAC with SHA-256 for message authentication, and BCrypt::Password (has_secure_password) for passwords. A non-security checksum may keep MD5 if the code says so.

    References: https://docs.ruby-lang.org/en/master/Digest.html · https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html

    warning ruby data-flow rule ruby, rails

    A request value is compiled into a regular expression (Regexp.new, an interpolated /#{…}/ literal). A pattern with nested quantifiers hangs the worker (ReDoS), and the attacker also controls what the pattern matches. Escape the value with Regexp.escape, or match with String#include?.

    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.

    CWE-1333 LLM05

    Fix: Wrap the value: Regexp.new(Regexp.escape(params[:q])). Set Regexp.timeout (Ruby 3.2+) to bound matching time.

    References: https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS

    keryn.general.ruby.session-key-from-request

    Section titled “keryn.general.ruby.session-key-from-request”

    warning ruby ruby, rails

    A request value is the key (or part of the key) written into the session. An attacker who chooses the key can overwrite security state such as user_id or admin. Use fixed session keys.

    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: calls one thing invokes another.

    CWE-472 LLM05

    Fix: Write only fixed keys (session[:theme] = value). If a dynamic key is needed, take it from an allowlist.

    References: https://guides.rubyonrails.org/security.html#session-hijacking

    error ruby data-flow rule ruby, rails

    A request value is marked as safe HTML (html_safe, raw, safe_concat, content_tag with :escape false) or written straight into a response. Rails then skips output escaping and a script payload runs in the visitor’s browser. Leave request values escaped (the default), or sanitize with a strict allowlist.

    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; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-79 LLM05

    Fix: Remove html_safe / raw on request-derived text so ERB escapes it. If limited markup is needed, sanitize(value, tags: %w[b i]) with an explicit tag list. Return JSON with render json: instead of building HTML by hand.

    References: https://guides.rubyonrails.org/security.html#cross-site-scripting-xss · https://api.rubyonrails.org/classes/String.html#method-i-html_safe

    warning ruby ruby, rails

    render inline: compiles its argument as an ERB template, and render text: / html: write markup straight into the page. When the string is built by interpolation or concatenation any attacker-influenced piece becomes template code or unescaped HTML. Render a file template with locals, or render plain: / json: for non-markup.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-79 LLM05

    Fix: Move the markup into a view and pass values as locals (render :greeting, locals: {name: name}); ERB escapes them. For plain text use render plain:.

    References: https://guides.rubyonrails.org/layouts_and_rendering.html#using-render

    keryn.general.ruby.command-backtick-interpolated

    Section titled “keryn.general.ruby.command-backtick-interpolated”

    warning ruby ruby, rails

    A backtick or %x command contains an interpolated value, so the shell parses whatever the value holds. If the value is attacker-controlled the attacker runs commands. Use the list form of system, or Open3.capture2 with separate arguments.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-78 LLM05

    Fix: Replace ls #{dir} with Open3.capture2(“ls”, “–”, dir). Escape with Shellwords.escape only when a shell is unavoidable.

    References: https://ruby-doc.org/core/Kernel.html#method-i-60

    keryn.general.ruby.sql-built-string-in-query

    Section titled “keryn.general.ruby.sql-built-string-in-query”

    warning ruby data-flow rule ruby, rails

    SQL text built by string interpolation or concatenation reaches an ActiveRecord query method or a raw connection call (where, order, group, joins, select, pluck, from, find_by_sql, execute, Arel.sql, …), directly or through a local variable. If any interpolated value is attacker-controlled the query changes. Prefer hash conditions or ? placeholders; interpolate only constants and allowlisted identifiers.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-89 LLM05

    Fix: Replace interpolation with placeholders (where(“age > ?”, limit)) or hash conditions. Where an identifier must vary (table, column, direction), choose it from a fixed allowlist or quote it with connection.quote_column_name / quote_table_name.

    References: https://guides.rubyonrails.org/security.html#sql-injection · https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html

    warning ruby data-flow rule ruby, rails

    A shell command line built by interpolation or concatenation reaches system, exec, spawn, backticks or %x, IO.popen or Open3, directly or through a local variable. If any part is attacker-controlled the shell runs attacker commands. Pass arguments as separate list elements so no shell is involved.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-78 LLM05

    Fix: Replace system(“rm #{path}”) with system(“rm”, “–”, path) and Open3.capture2(“ls”, dir). If a shell is unavoidable, Shellwords.escape every interpolated value.

    References: https://guides.rubyonrails.org/security.html#command-line-injection · https://ruby-doc.org/core/Kernel.html#method-i-system