Search by

yousha / php-security-linter

yousha

A PHP tool to lint PHP files for security issues based on CIS and OWASP best practices.

Package info

github.com/Yousha/php-security-linter

Homepage

Issues

pkg:composer/yousha/php-security-linter

Statistics

Installs: 685

Dependents: 0

Suggesters: 0

Stars: 12

3.2.0.7 2026-11-25 21:41 UTC

This package is auto-updated.

Last update: 2026-11-25 21:42:12 UTC


README

A PHP tool to lint PHP files for security issues based on CIS and OWASP best practices.

current version Build and Test CodeQL Dependabot Updates PHP issues repo size GitHub license contributions welcome

Contents

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

  1. Windows or GNU/Linux OS
  2. PHP 8.0 or newer
  3. Composer 2 or newer

Screenshots

CLI scan of two PHP files showing OWASP findings and an opt-in ATT&CK finding

Diagrams

  • C3 — Component View (UML):

C4 C3 Component View — PHP Security Linter

  • Dataflow — UML Activity Diagram:

UML activity diagram showing CLI validation, rule selection, PHP file traversal, exclusions, regex and token analysis, findings, warnings, report generation, and exit status

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 (/… and X:\…) 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:

  1. Fork repository.
  2. Create a new branch for your feature or bugfix.
  3. 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.