# general-injection-ruby-v2

> general-injection-ruby-v2: 3 Keryn rules for ruby (1 error, 2 warning).

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

3 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-multiline-literal

`error` ruby ruby, rails

A SQL string literal that spans several lines interpolates a request value (params, cookies, request headers) and is passed to an ActiveRecord query method or a raw connection call (where, joins, find\_by\_sql, execute, select\_rows, Arel.sql, ...). The finding sits on the line of the interpolation. The value can change the query. Use ? placeholders or hash conditions.

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:** Move the value out of the SQL text: where("age &gt; ?", limit), sanitize\_sql\_array(["... ?", value]), or quote identifiers with connection.quote\_column\_name / quote\_table\_name after checking them against an allowlist.

**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.sql-interpolation-multiline-literal

`warning` ruby ruby, rails

A SQL string literal that spans several lines interpolates a value and is passed to an ActiveRecord query method or a raw connection call (where, joins, find\_by\_sql, execute, select\_rows, Arel.sql, ...). The finding sits on the line of the interpolation. If the value is attacker-controlled the query changes. Use ? placeholders or hash conditions; 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:** Move the value out of the SQL text: where("age &gt; ?", limit), sanitize\_sql\_array(["... ?", value]), or quote identifiers with connection.quote\_column\_name / quote\_table\_name after checking them against an allowlist.

**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.render-instance-variable-from-request

`warning` ruby ruby, rails

A controller renders a template, action or file named by an instance variable that another method of the same controller (typically a before\_action) assigns from params. A visitor then chooses which template or file is rendered, which can expose other views or, on older Rails, files outside the view path. Map the request value through an allowlist before rendering.

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-73](https://keryn.dev/taxonomies/cwe/#cwe-73-external-control-of-file-name-or-path) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Keep a fixed map of allowed templates (PAGES = &#123;"about" =&gt; "pages/about"&#125;) and render PAGES.fetch(params[:page]) or head :not\_found; never pass the request value itself to render.

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