Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128199 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 288041A00BC for ; Wed, 23 Jul 2025 18:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753294987; bh=i6tJJxyXMgWds6ztYU7XLL9YwMUJOFzAwJMozZ8GD4I=; h=Date:From:Subject:To:From; b=mcF0P0qXN6KMAUBqyGprA8w+0IEqnySNCtxVG/bYF4yXVKdEaTl8OCRFjnD18UTpb rjw2bX4yVsptZes3FvnmsNIHLzS1/Qd/+GJeZz3lrMWI66WMTsADTj7OslnOdrJARV 4YRwL9t2dEGZ7Tu6ZcsLQUIkRpPLGlbVfvUmUZldaqqsw3qb9wbo4Y53sgZ6zLxcNR bcVakyxS36QsuceUVdfsQNQGUVBQwoRb6WHaXqJbj7Um7i7AiDHqTMBqxwTmOWd8Ca PcIQayDQD7B/n6L/nxnaK4GzKzHUNhbTRu4IcI0hsyFLC/azYx/W/4/VDB/MHIEH+S wtwhg4bE5a8gQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D439180059 for ; Wed, 23 Jul 2025 18:23:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from pmxout2.rz.tu-bs.de (pmxout2.rz.tu-bs.de [134.169.4.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 23 Jul 2025 18:23:06 +0000 (UTC) X-KumoRef: eyJfQF8iOiJcXF8vIiwicmVjaXBpZW50IjoiaW50ZXJuYWxzQGxpc3RzLnBocC5uZXQifQ== DKIM-Signature: v=1; a=rsa-sha256; d=tu-braunschweig.de; s=exchange_neu; c=relaxed/relaxed; bh=i6tJJxyXMgWds6ztYU7XLL9YwMUJOFzAwJMozZ8GD4I=; h=from:from:reply-to:subject:subject:date:date:to:to:cc:resent-date: resent-from:resent-to:resent-cc:in-reply-to:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:list-owner:list-archive; t=1753295089; b=ZedVuzVPcG47k+XU8HloaV6xxWFBLQpLJxtq+Bkdkafvios9WU+mlkiEeosDSnCRcLVOErQka GdOkIyIGyjkEvJmtuADPbmvUUEgh0X1XljqApNstHExGGRD1Qjf7+6D4vWlWIJNkzU1vmpff+IM rWBLGlQn9BxEY8oD/meGvaqprs42RrHuljnXiCS6/gOPLJ0HE6eEagdot3Q+3jKAvHVriYJAn8V 7j4FHKBAhB41pmQpgwrbbQiHpp0iYWJATK/KwQD64GmEundAC/SjPpdoTIdQjUDselPqn2YAGqs 9zece5szDIPxBuYNV+ukfF/U5Dn1KEn+CEdQr655Z6dQ==; Received: from hermes10.ad.tu-bs.de (134.169.4.138) by kumo1.rz.tu-bs.de (KumoMTA 134.169.4.161) with ESMTP id 51bb647f67f211f0995802a7f8fa5b1c for ; Wed, 23 Jul 2025 18:24:49 +0000 Received: from [10.32.0.253] (134.169.9.110) by Hermes10.ad.tu-bs.de (134.169.4.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Wed, 23 Jul 2025 20:24:49 +0200 Message-ID: Date: Wed, 23 Jul 2025 20:24:49 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PHP-DEV] Study on unsafe extract() usage To: Content-Language: de-DE, en-US Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [134.169.9.110] X-ClientProxiedBy: Hermes09.ad.tu-bs.de (134.169.4.137) To Hermes10.ad.tu-bs.de (134.169.4.138) From: jannik.hartung@tu-braunschweig.de (Jannik Hartung) Hey everyone, as part of our security research, we studied the attack surface of the=20 extract() function when being called with user-controlled input. Calling=20 extract($_GET) allows an attacker to overwrite all variables in the=20 current scope, which could lead to vulnerabilities. We analyzed the use=20 of extract() in 28325 open source projects on GitHub looking for cases=20 where extract() is called with user-controlled input. extract() was=20 called 4923 times and 146 of those calls involved user-input. The=20 majority of findings were vulnerable due to being able to overwrite=20 superglobals. We would like to share the findings and start a discussion on if and how=20 the risks of unsafe extract() usage could be reduced without breaking=20 backwards compatibility. The vulnerable extract() calls could be=20 exploited primarily by overwriting superglobals who's state is expected=20 to be immutable by the user like $_SESSION or $_SERVER or empty like=20 $_POST on a GET request. Similar to how changing $GLOBALS through=20 extract() is already forbidden, we propose to block overwriting all=20 superglobals through extract(). This would prevent most of the=20 vulnerabilities found in the dataset and we cannot think of a valid use=20 case for allowing this behavior. Here is where we rely on your feedback=20 and experience. The semantics of every EXTR_ flag need to be documented, considered, and=20 understood properly as invalid usage could still leave the application=20 vulnerable. Calling extract() in the global scope is particularly risky=20 and the warning in the documentation could be expanded to describe the=20 risks in more depth. Using EXTR_IF_EXISTS in the global scope for=20 example would still allow overwriting superglobals instead of the=20 documented intended use case of defining a list of valid variables to=20 extract beforehand. Since empty prefix strings are allowed, even EXTR_PREFIX_ALL would allow=20 to overwrite superglobals since SESSION would become _SESSION -> _SESSION. We propose to disallow the use of empty=20 prefix strings in extract() to prevent this. No such code pattern was=20 found in the dataset, but we wanted to mention it since an empty prefix=20 string looks like a bug when using the EXTR_PREFIX_* flags. You can find more details in our paper [0], especially the case studies=20 of vulnerable usage scenarios and possible exploits in chapter 5. We=20 propose further possible mitigations in section 6.4 that wouldn't fit in=20 this email. If the proposed mitigations are not feasible, we hope the=20 raw study results could be of use for further discussion on their own. We are looking forward to your feedback and any discussion on this=20 topic. The proposed changes aim to improve the security of PHP=20 applications in the hopes to avoid breaking existing code. Kind regards Jannik Hartung Institute for Application Security (IAS) Technische Universit=C3=A4t Braunschweig [0] https://www.ias.tu-bs.de/publications/extract-woot-2025.pdf