Skip to main content

SKY-D255 · Security in code

File inclusion

CriticalCWE-98

PHP's include, require, include_once and require_once load a file and run it as PHP code. File inclusion happens when request data chooses which file is loaded. Skylos reports SKY-D255 when $_GET, $_POST, cookies or other request data reach the path of one of these statements.

Languages
PHP
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

With ?page=../../../../var/log/nginx/access a visitor can make the server run a log file into which they wrote PHP code, or read files such as /etc/passwd. Where allow_url_include is on, a URL loads code from the attacker's server.

What Skylos flags

public/index.php · PHPReported on line 4
<?php $page = $_GET['page'] ?? 'home';include __DIR__ . '/pages/' . $page . '.php';

What Skylos leaves alone

public/index.php · PHP
<?php $file = match ($_GET['page'] ?? 'home') {    'about' => 'about.php',    'contact' => 'contact.php',    default => 'home.php',};include __DIR__ . '/pages/' . $file;

Why Skylos leaves it alone

The request value only selects an arm of the match. Every arm returns a fixed file name, so the included path can only be one of three files. Skylos follows the values each arm returns, not the value that was matched.

How Skylos decides

  1. Runs PHP's flow-sensitive taint check over each function or file: request data starts at $_GET, $_POST, $_REQUEST, $_COOKIE, the name and type of uploaded files, and the request objects of common frameworks, and follows assignments, string building and branches.
  2. Finds include, include_once, require and require_once and checks the path expression after the keyword.
  3. Stops at values that cannot choose the file: numbers from casts and numeric functions, basename() for paths, match arms that return literals, and a guard whose failing branch exits, such as a strict in_array($page, [...], true) against a literal list.
  4. Reports CRITICAL when request data still reaches the path. Before 5.6.0 this was reported as SKY-D215.

How to fix it

Map the input to a fixed list of files, or reject anything that is not on a literal allowlist before the include runs. Keep allow_url_include off.

public/index.php · PHP · the fix, against the flagged file
<?php $page = $_GET['page'] ?? 'home';Added: if (!in_array($page, ['home', 'about', 'contact'], true)) {Added:     http_response_code(404);Added:     exit;Added: }include __DIR__ . '/pages/' . $page . '.php';

When it can be wrong

  • A check made in a helper function, such as assert_page($page) that exits on a bad value, is not seen, so the include stays reported.
  • A loose in_array() without the third argument true does not count as a guard, because PHP's loose comparison accepts unexpected values.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark a reviewed line and say why. A bare // noqa does not hide CRITICAL security findings.

    PHP
    include $path; // skylos: ignore[SKY-D255] path checked by assert_page()
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D255"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.