Skip to content

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

    vulnfix-gaps-c-ruby-v1

    View as Markdown

    14 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.

    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 authority is given or left unchecked.

    CWE-242 LLM05

    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

    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 authority is given or left unchecked.

    CWE-120 LLM05

    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

    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 authority is given or left unchecked.

    CWE-120 LLM05

    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

    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 authority is given or left unchecked.

    CWE-120 LLM05

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

    References: https://en.cppreference.com/w/c/io/fprintf

    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 authority is given or left unchecked.

    CWE-120 LLM05

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

    References: https://en.cppreference.com/w/c/io/vfprintf

    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 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: 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

    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 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 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

    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 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: 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

    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 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: Pass a block (obj.instance_eval { … }) 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

    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 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 LLM03

    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/Security.md

    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 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 LLM03

    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/Psych.html#method-c-unsafe_load

    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 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: 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

    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 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: 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

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

    CWE-1336 LLM05

    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