adachsoft / php-capability-scanner
Statically detects sensitive capabilities in PHP source code without executing it.
Package info
gitlab.com/a.adach/php-capability-scanner
pkg:composer/adachsoft/php-capability-scanner
Requires
- php: ^8.3
- adachsoft/collection: ^3.0
- nikic/php-parser: ^5.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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.