# vulnfix-gaps-c-ruby-v1

> vulnfix-gaps-c-ruby-v1: 14 Keryn rules for c, cpp, ruby (6 error, 8 warning).

Source: https://keryn.dev/rules/vulnfix-gaps-c-ruby-v1/

14 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.vfgap.gets-c

`error` c, cpp c, cpp

gets() reads a line into a buffer with no size limit, so any input longer than the buffer overwrites the stack. No caller can use it safely; it was removed from C11 and C++14.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

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

**Fix:** Read with fgets(buf, sizeof buf, stdin) (or getline) and handle the truncated-line case.

**References:** [https://en.cppreference.com/w/c/io/gets](https://en.cppreference.com/w/c/io/gets)

## keryn.vfgap.strcpy-non-literal-c

`warning` c, cpp c, cpp

strcpy copies until the source's terminating NUL without knowing the destination's size. When the source is not a literal, a longer string than the buffer overflows it. Copy with an explicit bound.

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

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

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

**Fix:** Use snprintf(dst, sizeof dst, "%s", src), strlcpy where available, or a length-checked memcpy; in C++ use std::string.

**References:** [https://en.cppreference.com/w/c/string/byte/strcpy](https://en.cppreference.com/w/c/string/byte/strcpy)

## keryn.vfgap.strcat-non-literal-c

`warning` c, cpp c, cpp

strcat appends the source after the destination's current contents with no idea how much room is left. When the appended string is not a literal, it can run past the end of the buffer.

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

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

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

**Fix:** Track the remaining space and append with snprintf(dst + len, size - len, "%s", src) or strlcat; in C++ use std::string.

**References:** [https://en.cppreference.com/w/c/string/byte/strcat](https://en.cppreference.com/w/c/string/byte/strcat)

## keryn.vfgap.sprintf-unbounded-c

`warning` c, cpp c, cpp

sprintf formats into a buffer without a size, so a long argument (a %s of external data, a large number) writes past the end of the buffer. Format with the buffer size.

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

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

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

**Fix:** Use snprintf(buf, sizeof buf, fmt, ...) and check its return value for truncation.

**References:** [https://en.cppreference.com/w/c/io/fprintf](https://en.cppreference.com/w/c/io/fprintf)

## keryn.vfgap.vsprintf-unbounded-c

`warning` c, cpp c, cpp

vsprintf formats a va\_list into a buffer without a size, so the caller's arguments decide how much is written. Use the bounded variant.

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

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

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

**Fix:** Use vsnprintf(buf, sizeof buf, fmt, ap) and check its return value for truncation.

**References:** [https://en.cppreference.com/w/c/io/vfprintf](https://en.cppreference.com/w/c/io/vfprintf)

## keryn.vfgap.system-non-literal-c

`error` c, cpp c, cpp

system() hands its whole argument to /bin/sh -c. When the command string is built at run time, shell metacharacters in any part of it execute as commands.

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; 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:** Start the program directly with fork/execve or posix\_spawn and an argument vector; allow-list the executable and never splice external text into a shell string.

**References:** [https://pubs.opengroup.org/onlinepubs/9799919799/functions/system.html](https://pubs.opengroup.org/onlinepubs/9799919799/functions/system.html)

## keryn.vfgap.popen-non-literal-c

`error` c, cpp c, cpp

popen() runs its command through /bin/sh -c. When the command string is built at run time, shell metacharacters in any part of it execute as commands.

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; 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 pipe plus posix\_spawn (or fork/execve) with an argument vector; allow-list the executable and never splice external text into a shell string.

**References:** [https://pubs.opengroup.org/onlinepubs/9799919799/functions/popen.html](https://pubs.opengroup.org/onlinepubs/9799919799/functions/popen.html)

## keryn.vfgap.eval-non-literal-rb

`error` ruby ruby

eval runs a string as Ruby code. When the string is built at run time, whoever controls any part of it (a request, a model's output, a config value) runs code in this process.

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; 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:** Parse the data instead of evaluating it (JSON.parse, a lookup table of allowed operations); never pass external text to eval.

**References:** [https://docs.ruby-lang.org/en/master/Kernel.html#method-i-eval](https://docs.ruby-lang.org/en/master/Kernel.html#method-i-eval)

## keryn.vfgap.instance-eval-string-rb

`warning` ruby ruby

instance\_eval with a string argument compiles that string as Ruby code with the receiver as self. When the string is not a literal, its author runs code in this process. The block form is not affected.

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-95](https://keryn.dev/rules/?cwe=CWE-95) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Pass a block (obj.instance\_eval &#123; ... &#125;) or call explicit, allow-listed methods with public\_send instead of evaluating a string.

**References:** [https://docs.ruby-lang.org/en/master/BasicObject.html#method-i-instance_eval](https://docs.ruby-lang.org/en/master/BasicObject.html#method-i-instance_eval)

## keryn.vfgap.oj-load-object-mode-rb

`warning` ruby oj

Oj.load without a data-only mode uses Oj's default mode, which (unless reconfigured) is :object: the document can name Ruby classes to instantiate, so untrusted JSON builds arbitrary objects.

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

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) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain)

**Fix:** Use Oj.safe\_load, or pass mode: :strict (or :compat) on every Oj.load of external data.

**References:** [https://github.com/ohler55/oj/blob/develop/pages/Modes.md](https://github.com/ohler55/oj/blob/develop/pages/Modes.md) · [https://github.com/ohler55/oj/blob/develop/pages/Security.md](https://github.com/ohler55/oj/blob/develop/pages/Security.md)

## keryn.vfgap.marshal-yaml-unsafe-load-rb

`warning` ruby ruby

Marshal.load and YAML.unsafe\_load rebuild arbitrary Ruby objects from their input, and a crafted payload chains existing classes into code execution. Only load data this process wrote and authenticated.

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

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) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain)

**Fix:** Exchange JSON (JSON.parse) or YAML.safe\_load with an explicit permitted\_classes list; sign anything that must stay in Marshal format.

**References:** [https://docs.ruby-lang.org/en/master/Marshal.html](https://docs.ruby-lang.org/en/master/Marshal.html) · [https://docs.ruby-lang.org/en/master/Psych.html#method-c-unsafe_load](https://docs.ruby-lang.org/en/master/Psych.html#method-c-unsafe_load)

## keryn.vfgap.system-shell-string-rb

`error` ruby ruby

system with a single string argument runs it through the shell. When that string is built at run time, shell metacharacters in any part of it execute as commands.

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; 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:** Pass the program and each argument separately (system("git", "log", ref)) so no shell is involved, and allow-list the program.

**References:** [https://docs.ruby-lang.org/en/master/Kernel.html#method-i-system](https://docs.ruby-lang.org/en/master/Kernel.html#method-i-system)

## keryn.vfgap.io-popen-shell-string-rb

`error` ruby ruby

IO.popen with a command string runs it through the shell. When the string is built at run time, shell metacharacters in any part of it execute as commands. The array form starts the program directly.

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; 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:** Pass an argument array (IO.popen(["git", "log", ref])) or use Open3 with separate arguments, and allow-list the program.

**References:** [https://docs.ruby-lang.org/en/master/IO.html#method-c-popen](https://docs.ruby-lang.org/en/master/IO.html#method-c-popen)

## keryn.vfgap.erb-new-dynamic-template-rb

`warning` ruby erb

ERB.new compiles its template text into Ruby code that result() runs. A template assembled from request data, a database row or a model's output lets its author run code (server-side template injection).

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-1336](https://keryn.dev/rules/?cwe=CWE-1336) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Keep templates as files shipped with the application and pass external data only as values through a binding or result\_with\_hash; never build template text from input.

**References:** [https://docs.ruby-lang.org/en/master/ERB.html](https://docs.ruby-lang.org/en/master/ERB.html)
