# general-injection-ruby-v1

> general-injection-ruby-v1: 19 Keryn rules for ruby (9 error, 10 warning).

Source: https://keryn.dev/rules/general-injection-ruby-v1/

19 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.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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**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://guides.rubyonrails.org/security.html#sql-injection) · [https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html](https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**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://guides.rubyonrails.org/security.html#command-line-injection) · [https://ruby-doc.org/core/Kernel.html#method-i-system](https://ruby-doc.org/core/Kernel.html#method-i-system)

## keryn.general.ruby.eval-request

`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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**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://guides.rubyonrails.org/security.html#injection) · [https://ruby-doc.org/core/Kernel.html#method-i-eval](https://ruby-doc.org/core/Kernel.html#method-i-eval)

## keryn.general.ruby.file-access-request

`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](https://keryn.dev/docs/edges/edge-kinds/#reads) one thing reads from another.

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

**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://guides.rubyonrails.org/security.html#file-uploads) · [https://community.owasp.org/attacks/Path_Traversal](https://community.owasp.org/attacks/Path_Traversal)

## keryn.general.ruby.open-redirect-request

`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](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

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

**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://guides.rubyonrails.org/security.html#redirection-and-files) · [https://api.rubyonrails.org/classes/ActionController/Redirecting.html](https://api.rubyonrails.org/classes/ActionController/Redirecting.html)

## 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](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

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

**Fix:** Render a fixed template (render :show, locals: &#123;name: params[:name]&#125;) 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://guides.rubyonrails.org/layouts_and_rendering.html) · [https://portswigger.net/web-security/server-side-template-injection](https://portswigger.net/web-security/server-side-template-injection)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

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

**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](https://docs.ruby-lang.org/en/master/ERB.html)

## 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](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:** 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://guides.rubyonrails.org/action_controller_overview.html#strong-parameters) · [https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-permit-21](https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-permit-21)

## 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](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:** 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](https://guides.rubyonrails.org/action_controller_overview.html#strong-parameters)

## 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](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-502](https://keryn.dev/taxonomies/cwe/#cwe-502-deserialization-of-untrusted-data) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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://ruby-doc.org/core/Marshal.html) · [https://docs.ruby-lang.org/en/master/Psych.html](https://docs.ruby-lang.org/en/master/Psych.html)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**Fix:** Look the name up in a fixed Hash (ALLOWED = &#123;"csv" =&gt; CsvExporter&#125;.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://guides.rubyonrails.org/security.html#unsafe-reflection) · [https://cwe.mitre.org/data/definitions/470.html](https://cwe.mitre.org/data/definitions/470.html)

## keryn.general.ruby.weak-hash-md5-sha1

`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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

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

**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://docs.ruby-lang.org/en/master/Digest.html) · [https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)

## keryn.general.ruby.regexp-from-request

`warning` ruby data-flow rule ruby, rails

A request value is compiled into a regular expression (Regexp.new, an interpolated /#&#123;...&#125;/ 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

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

**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](https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

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

**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](https://guides.rubyonrails.org/security.html#session-hijacking)

## keryn.general.ruby.html-safe-request

`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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**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://guides.rubyonrails.org/security.html#cross-site-scripting-xss) · [https://api.rubyonrails.org/classes/String.html#method-i-html_safe](https://api.rubyonrails.org/classes/String.html#method-i-html_safe)

## keryn.general.ruby.render-dynamic-markup

`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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

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

**References:** [https://guides.rubyonrails.org/layouts_and_rendering.html#using-render](https://guides.rubyonrails.org/layouts_and_rendering.html#using-render)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**Fix:** Replace `ls #&#123;dir&#125;` 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](https://ruby-doc.org/core/Kernel.html#method-i-60)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**Fix:** Replace interpolation with placeholders (where("age &gt; ?", 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://guides.rubyonrails.org/security.html#sql-injection) · [https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html](https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html)

## keryn.general.ruby.command-built-string

`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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

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

**Fix:** Replace system("rm #&#123;path&#125;") 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://guides.rubyonrails.org/security.html#command-line-injection) · [https://ruby-doc.org/core/Kernel.html#method-i-system](https://ruby-doc.org/core/Kernel.html#method-i-system)
