PHPWAF (PHP Web Application Firewall) is a lightweight, security-enhanced solution designed to protect PHP web applications from common web-based attacks, including SQL injection, Cross-Site Scripting (XSS), and XML External Entity (XXE) injection attempts. It filters incoming requests based on a set of customizable rules, ensuring your application is shielded from various threats.
- User Agent Filtering: Blocks requests from suspicious or malicious user agents.
- SQL Injection Protection: Detects and blocks SQL injection attempts in GET and POST parameters.
- XSS Protection: Identifies and mitigates potential Cross-Site Scripting (XSS) attacks.
- XXE Protection: Filters XML input for possible XXE injection attempts.
- Request Logging: Logs all blocked requests to a file for future review and auditing.
- PHP >= 7.4
- Web server (Apache, Nginx, etc.)
-
Clone the repository:
git clone https://github.com/mnovel/PHPWAF.git cd PHPWAF -
Include PHPWAF in your project:
- Include the
Security.phpfile in your project where you handle incoming requests.
- Include the
-
Integrate with your project:
- Call the
Securityclass at the top of your PHP scripts to initiate request filtering:
<?php require 'Security.php'; // Run security filters Security::filterUserAgent(); Security::parametersFilter(); ?>
- Call the
-
User Agent Filtering:
- PHPWAF checks the
User-Agentheader to block requests from known bots or potentially harmful sources. If the user agent does not match the allowed list, the request will be blocked, and a log entry will be created.
- PHPWAF checks the
-
Parameter Filtering:
- GET and POST parameters are scanned for potential SQL injection attempts, XSS payloads, and XXE injections. If any suspicious patterns are detected, the request will be blocked.
-
Logging:
- All blocked requests are logged into the
blocked_requests.logfile, including details about the blocked attempt and the reason for blocking.
- All blocked requests are logged into the
[2024-10-12 14:30:05] SQL Injection Attempt: union select * from users
[2024-10-12 14:32:12] XSS Attempt: <script>alert('XSS')</script>
Logs will help you monitor potential attack attempts and adjust your rules as necessary.
We welcome contributions! Feel free to open issues or submit pull requests to improve PHPWAF. Whether you want to add new filtering techniques or enhance the existing features, we would love your input.
This project is licensed under the MIT License.