Skip to content

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

    general-injection-php-v1

    View as Markdown

    10 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 php data-flow rule php, symfony, laravel, wordpress

    A request value is written to the response (echo, print, printf, die/exit, <?= ?>, or a response body) without output escaping. A script or HTML payload in the value runs in the visitor’s browser. Escape for the context: htmlspecialchars($v, ENT_QUOTES, ‘UTF-8’) for HTML, esc_html / esc_attr in WordPress, or render through Twig / Blade, which escape by default.

    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: Escape at the point of output: echo htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, ‘UTF-8’). In templates use Twig or Blade ({{ }}) which escape automatically. Cast numeric values with (int). Return JSON with json_encode and a JSON content type instead of printing it into HTML; if it must sit inside a script tag use JSON_HEX_TAG.

    References: https://www.php.net/manual/en/function.htmlspecialchars.php · https://symfony.com/doc/current/templates.html#output-escaping · https://laravel.com/framework/docs/blade#displaying-data

    keryn.general.php.sql-injection-request-to-query

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

    error php data-flow rule php, mysqli, pdo, doctrine-dbal, laravel, wordpress

    A request value is built into SQL text passed to a query function (mysqli, PDO, pg_*, Doctrine DBAL, Laravel DB and raw query-builder methods). The value can change the query. Keep the SQL constant with ? or :name placeholders and pass values as bound parameters.

    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 prepared statements: $stmt = $pdo->prepare(‘SELECT * FROM t WHERE id = ?’); $stmt->execute([$id]). For Laravel use DB::select(‘… where id = ?’, [$id]) and whereRaw(‘x = ?’, [$v]). Identifiers (column, table, ORDER BY direction) cannot be bound: map them from a fixed allowlist with in_array(…, true). Cast numbers with (int).

    References: https://www.php.net/manual/en/security.database.sql-injection.php · https://www.php.net/manual/en/pdo.prepared-statements.php · https://laravel.com/framework/docs/queries#raw-expressions · https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/security.html

    keryn.general.php.sql-built-from-variable-audit

    Section titled “keryn.general.php.sql-built-from-variable-audit”

    warning php php, mysqli, pdo, doctrine-dbal, laravel, wordpress

    The SQL passed to a query function is a concatenation, an interpolated string or sprintf() that contains a non-constant part. Whatever the source of the variable, this style invites injection when the value is ever user-influenced. Switch to placeholders and bound parameters, or cast / quote every variable part.

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

    CWE-89 LLM05

    Fix: Replace string building with placeholders (? or :name) and pass values through execute() / bind parameters. Where a fragment cannot be bound (column or table name), choose it from a fixed allowlist. If the part is numeric, cast it with (int) at the point of use.

    References: https://www.php.net/manual/en/security.database.sql-injection.php · https://www.php.net/manual/en/pdo.prepared-statements.php · https://laravel.com/framework/docs/queries#raw-expressions · https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/security.html

    keryn.general.php.path-traversal-request-to-file

    Section titled “keryn.general.php.path-traversal-request-to-file”

    error php data-flow rule php, symfony, laravel, wordpress

    A request value reaches a file include, read, write, delete, download or Storage call without being reduced to a base name or confined to a directory. ../ sequences (or an absolute path) escape the intended folder, and include/require can run attacker-chosen code. Use basename(), or realpath() the result and check it starts with the base directory before use.

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

    Fix: Take only basename($name), or map an id to a path on the server. Otherwise resolve with realpath($base . ‘/’ . $name) and refuse unless it is not false and str_starts_with($real, realpath($base) . DIRECTORY_SEPARATOR). Never pass a request value to include/require; select from a fixed list of files.

    References: https://www.php.net/manual/en/function.basename.php · https://www.php.net/manual/en/function.realpath.php · https://www.php.net/manual/en/security.filesystem.php · https://laravel.com/framework/docs/filesystem · https://symfony.com/doc/current/components/http_foundation.html#serving-files

    keryn.general.php.command-injection-request-to-shell

    Section titled “keryn.general.php.command-injection-request-to-shell”

    error php data-flow rule php, symfony, laravel

    A request value reaches a shell execution function (exec, system, shell_exec, passthru, popen, proc_open, pcntl_exec or backticks) without shell escaping. Shell metacharacters in the value run extra commands. Pass the value through escapeshellarg(), or avoid the shell and call proc_open with an argument array.

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

    Fix: Wrap each user-supplied argument in escapeshellarg(). Better, skip the shell: proc_open([‘convert’, $file, $out], …) or Symfony Process with an argument array. Validate the value (cast to int, match an allowlist) before it gets near a command.

    References: https://www.php.net/manual/en/function.escapeshellarg.php · https://www.php.net/manual/en/function.escapeshellcmd.php · https://www.php.net/manual/en/function.proc-open.php · https://symfony.com/doc/current/components/process.html

    keryn.general.php.ssrf-request-to-http-client

    Section titled “keryn.general.php.ssrf-request-to-http-client”

    error php data-flow rule php, curl, guzzle, laravel, symfony-http-client

    A request value is used as the URL of a server-side HTTP request (curl, fopen/file_get_contents, Guzzle, Laravel Http, Symfony HttpClient). An attacker can make the server call internal addresses, cloud metadata endpoints or other hosts. filter_var(FILTER_VALIDATE_URL) only checks syntax and does not stop this; compare the parsed host against 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-918 LLM05

    Fix: Parse the URL and require an https scheme and a host that is in a fixed allowlist: in_array(parse_url($url, PHP_URL_HOST), $allowed, true). Better, accept an id or a path and build the URL from a fixed base. Block redirects (CURLOPT_FOLLOWLOCATION false, Guzzle allow_redirects false) and resolve and reject private or link-local addresses if arbitrary hosts are required.

    References: https://www.php.net/manual/en/function.parse-url.php · https://www.php.net/manual/en/function.curl-setopt.php · https://docs.guzzlephp.org/en/stable/request-options.html · https://laravel.com/framework/docs/http-client · https://symfony.com/doc/current/http_client.html

    keryn.general.php.open-redirect-request-to-location

    Section titled “keryn.general.php.open-redirect-request-to-location”

    warning php data-flow rule php, symfony, laravel, wordpress

    A request value decides where the browser is redirected (Location header, redirect(), RedirectResponse, wp_redirect). An attacker can send victims from your domain to a phishing page. Redirect only to a fixed route name, an allowlisted host, or a local path that starts with a single slash.

    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: Redirect to a route by name (redirect()->route(‘home’), $this->redirectToRoute(‘home’)) and carry state in the session. If a return URL is needed, accept it only when it starts with ‘/’ and not ‘//’ (and has no backslash), or when parse_url($u, PHP_URL_HOST) is in an allowlist. In WordPress use wp_safe_redirect().

    References: https://www.php.net/manual/en/function.header.php · https://laravel.com/framework/docs/responses#redirects · https://symfony.com/doc/current/controller.html#redirecting · https://www.php.net/manual/en/function.parse-url.php

    keryn.general.php.unserialize-untrusted-input

    Section titled “keryn.general.php.unserialize-untrusted-input”

    error php data-flow rule php, symfony, laravel, wordpress

    A request value is passed to unserialize() without allowed_classes set to false. PHP builds any class the attacker names and runs its magic methods (__wakeup, __destruct), which leads to object- injection and often remote code execution. Use json_decode() for data, or pass [‘allowed_classes’ => false].

    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

    Fix: Exchange data as JSON (json_decode($raw, true)). If unserialize() cannot be avoided, pass [‘allowed_classes’ => false] so only plain arrays and scalars come back, and sign the payload with hash_hmac and verify it with hash_equals before decoding. Never unserialize cookies, form fields or request bodies.

    References: https://www.php.net/manual/en/function.unserialize.php · https://www.php.net/manual/en/function.json-decode.php · https://www.php.net/manual/en/language.oop5.magic.php

    keryn.general.php.zip-slip-archive-entry-name

    Section titled “keryn.general.php.zip-slip-archive-entry-name”

    error php data-flow rule php, ziparchive, phar

    An archive entry name (ZipArchive getNameIndex / statIndex, or a PharData entry) is used to build the destination of a created file or directory. A crafted entry such as ../../public/shell.php writes outside the extraction folder (Zip Slip). Take basename(), or realpath the target and check it still starts with the extraction directory before writing.

    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: For each entry compute $target = $dest . DIRECTORY_SEPARATOR . $name, create the parent directory, then require str_starts_with(realpath(dirname($target)), realpath($dest) . DIRECTORY_SEPARATOR) before file_put_contents. Skip entries with absolute paths. Or use basename($name) and flatten the archive.

    References: https://www.php.net/manual/en/ziparchive.getnameindex.php · https://www.php.net/manual/en/ziparchive.statindex.php · https://www.php.net/manual/en/class.phardata.php · https://www.php.net/manual/en/function.realpath.php

    keryn.general.php.zip-extractto-uploaded-archive-audit

    Section titled “keryn.general.php.zip-extractto-uploaded-archive-audit”

    warning php php, ziparchive, laravel, symfony

    ZipArchive::extractTo() runs on an archive that was opened from an uploaded file. Confirm the entries are validated first (names, symlinks, number and size of files) and that the destination is not web-reachable; the archive content is attacker-controlled.

    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: writes one thing writes to another.

    CWE-22 CWE-409 LLM05

    Fix: Loop over the entries first: reject names that are absolute, contain .. or end in an executable extension, and cap numFiles and the total uncompressed size from statIndex. Pass only the validated names as the second argument of extractTo($dest, $names). Extract into a private directory, not under the web root.

    References: https://www.php.net/manual/en/ziparchive.extractto.php · https://www.php.net/manual/en/ziparchive.getnameindex.php · https://www.php.net/manual/en/ziparchive.statindex.php