yousha / php-security-linter
A PHP tool to lint PHP files for security issues based on CIS and OWASP best practices.
Requires
- php: >=8.0
- ext-pcre: *
- ext-tokenizer: *
Requires (Dev)
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP tool to lint PHP files for security issues based on CIS and OWASP best practices.
Contents
- Overview
- Features
- Requirements
- Installation
- Usage
- FAQ
- Support
- Changelog
- ToDo
- Contributing
- Code of Conduct
- DCO
- Contributors
- Notice
- License
Overview
PHP Security Linter is a static application security testing (SAST) tool for identifying potentially insecure patterns in PHP source code. It applies CIS- and OWASP-oriented rules, with optional MITRE ATT&CK behavior indicators. It analyzes source files without executing the application and can report risks such as injection, cross-site scripting (XSS), insecure configuration, and sensitive-data exposure.
Findings are heuristic indicators that require review in the context of the application. The linter does not prove that a vulnerability is exploitable and should be used alongside code review, testing, and other security controls.
Features
- 48 registered rules
- Fast static analysis
- Console output
- SARIF 2.1.0 output
- Configurable ruleset
- DevSecOps ready
- Exclusion support
- Supported platforms: Windows, GNU/Linux
Requirements
- Windows or GNU/Linux OS
- PHP 8.0 or newer
- Composer 2 or newer
Screenshots
Diagrams
- C3 — Component View (UML):
- Dataflow — UML Activity Diagram:
Installation
Via Composer per project:
composer require --dev yousha/php-security-linter
Or via Composer globally:
composer global require yousha/php-security-linter
Usage
Lint current directory:
php vendor/bin/php-sl --path=.
Or (Windows):
vendor\bin\php-sl.bat --path=.
Lint a directory:
php vendor/bin/php-sl --path=./src
Lint with path exclusion:
php vendor/bin/php-sl --path=./app --exclude=storage,tests
Excluding a specific directory, path exclusion, and rule exclusion:
php bin/php-sl --path=./src --exclude=storage --exclude-rules=CIS-003,OWASP-001
Generate a SARIF 2.1.0 report and write it to a file:
php vendor/bin/php-sl --path=./src --format=sarif --output=results.sarif
Write SARIF to standard output:
php vendor/bin/php-sl --path=./src --format=sarif > results.sarif
Exit codes
| Code | Meaning |
|---|---|
| 0 | Clean scan |
| 1 | One or more findings |
| 2 | Invalid CLI input or scan error |
| 3 | Fatal error |
| 4 | One or more files/directories could not be scanned |
Cross-platform notes
- Line endings are normalized (CRLF → LF) before rule matching.
- Path exclusion is case-insensitive.
- Absolute paths (
/…andX:\…) and mixed separators are handled. - On Windows use
vendor\bin\php-sl.bat(Composer wrapper).
Commands
| Option | Description |
|---|---|
-p, --path |
Path to scan (required) |
--exclude |
Comma-separated paths to exclude |
--exclude-rules |
Comma-separated rule IDs to ignore |
--include-attack |
Enable three MITRE ATT&CK review rules |
--list-rules |
List available rule IDs |
--format |
Output format: text (default) or sarif |
--output |
Write SARIF output to a file (requires --format=sarif) |
--help |
Show help message |
Example output
Scan Results ======================================== File: /src/auth.php ✗ [CRITICAL] OWASP: SQL Injection vulnerability detected (Line 42) ✗ [HIGH] CIS: Hardcoded database credentials (Line 15) File: /src/utils.php ✗ [MEDIUM] OWASP: XSS vulnerability possible (Line 88) Summary: Scanned 24 files, found 3 potential issues.
Tests
Run the PHPUnit test suite:
composer test
Or:
php vendor/bin/phpunit tests/
FAQ
See FAQ.txt file.
Support
For any question, issues and feature requests, open an issue..
Changelog
See CHANGELOG.txt file.
ToDo
See TODO.txt file.
Contributing
Contributions are welcome! Please follow these steps:
- Fork repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
For more details see CONTRIBUTING.txt.
Code of Conduct
See CODE_OF_CONDUCT.txt file.
DCO
See DCO.txt file.
Contributors
See CONTRIBUTORS.txt file.
Notice
See NOTICE.txt file.
License
This open-source software is distributed under the GPL-3.0 license. See LICENSE file.
