Search by

adachsoft / php-capability-scanner

Arkadiusz Adach

Statically detects sensitive capabilities in PHP source code without executing it.

Package info

gitlab.com/a.adach/php-capability-scanner

Issues

pkg:composer/adachsoft/php-capability-scanner

Statistics

Installs: 12

Dependents: 2

Suggesters: 0

Stars: 0

v0.1.0 2026-11-23 21:20 UTC

This package is auto-updated.

Last update: 2026-11-23 20:20:38 UTC


README

adachsoft/php-capability-scanner statically analyzes PHP source and reports sensitive capabilities without executing the code. It parses source into an abstract syntax tree and returns each detection with its capability, symbol, and source line.

Features

  • Detects network, filesystem, process, environment, database, dynamic-code, runtime-configuration, and mail operations.
  • Includes default rules and supports additional function, class, function-prefix, and superglobal rules.
  • Ignores matches in comments and strings; resolves class aliases before matching.
  • Reports PHP syntax errors as PhpSourceParseException.

Requirements

  • PHP 8.3 or newer

Installation

composer require adachsoft/php-capability-scanner

Usage

use AdachSoft\PhpCapabilityScanner\PhpCapabilityScannerFactory;

$scanner = (new PhpCapabilityScannerFactory())->create();
$detected = $scanner->scan("<?php\nfile_get_contents('/var/data.txt');");

foreach ($detected as $item) {
    printf("%s: %s on line %d\n", $item->capability->value, $item->symbol, $item->line);
}

$capabilities = $detected->capabilities(); // Unique capabilities, in detection order.

See usage examples for custom rules and exception handling.

Default rules

Default rules cover common network clients and stream functions, file and directory operations, process execution, environment access, database APIs, dynamic code and includes, runtime configuration, and mail libraries. For example, the scanner recognizes curl_*, file_put_contents, exec, getenv, PDO, eval, and mail.

The scanner is syntax-based and cannot identify every sensitive operation. It does not execute code, inspect dependencies, infer arbitrary runtime values, or resolve all indirect behavior. A missing detection is not proof that source is safe; use results as one input to a broader security review.