[php-src] PR #19047: Add XSS attack protect in magic variables $_GET and $_POST

From: Date: Sun, 06 Jul 2025 07:04:47 +0000
Subject: [php-src] PR #19047: Add XSS attack protect in magic variables $_GET and $_POST
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-32339@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/19047 Author: Ange1PLSGreet **Title** - Add XSS Attack Protection for Magic Variables $_GET and $_POST **Description** - This pull request introduces XSS (Cross-Site Scripting) attack protection for the magic variables ``$_GET` and `$_POST``. By sanitizing their inputs, we mitigate the risk of attackers injecting malicious scripts into web pages. **Changes Made** - Enhanced Sanitization in ``add_post_var`: An extra sanitization step is added to the `add_post_var` function in `main/php_variables.c``. It removes common XSS-related characters and patterns from input values, neutralizing potential malicious scripts before they're registered as PHP variables. Extended Sanitization in ``php_default_treat_data`: Additional sanitization logic is implemented in both `PARSE_GET` and `PARSE_POST` cases of the `php_default_treat_data` function, strengthening input handling for `$_GET` and `$_POST``. **Testing** - Custom PHP Script with cURL: Instead of using PHPT, I wrote a custom PHP script and used cURL to test XSS protection. The script sends various XSS payloads via ``$_GET` and `$_POST` requests and verifies the sanitized output. It covers common XSS patterns like `<script>`` tags, javascript: URIs, and event-based injection. -- These are my test code ```php // TestGet.php <?php var_dump($_GET); ?> // TestPost.php <?php var_dump($_POST); ?> ``` ```bash curl "http://localhost:8000/TestGet.php?param1=<script>alert('xss')</script>" curl -X POST -d "param1=<script>alert('xss')</script>" http://localhost:8000/TestPost.php ``` **Manual Verification** - After running the test script, I manually verified that the sanitization worked without breaking existing functionality.

« previous php.git-pulls (#32339) next »