Re: Common-sense security hardening for the next PHP
| From: | Craig Francis | Date: | Sat, 21 Nov 2026 10:43:03 +0000 |
| Subject: | Re: Common-sense security hardening for the next PHP | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-133164@lists.php.net to get a copy of this message | ||
On Thu, 19 Nov 2026 at 23:24, Gregory Magarshak <greg@qbix.com> wrote:
> [...] I take back about $interpolation inside <<<PHP et al. ... We may
> need some new syntax like <<<<PHP, which treats $foo and {$foo}
> differently.
>
> But the bigger point is — if we can get PHP 9 to simply close all the
> holes separating *developer-written code* from *dynamically constructed
> strings*, we’ll finally prevent a huge class of attacker-controlled
> arbitrary RCE.
>
You can do this today, use the
literal-string type in Psalm and PHPStan;
unfortunately the vast majority of developers will never use static
analysis tools.
It addresses the taint-checking/escaping issues, it works for database
abstractions like Doctrine where('u.id = ' . $_GET['id']), it
doesn't
require everyone to rewrite their code to use something like Heredoc, and
you can concatenate literal-string values together (this really helps
adoption).
Christoph Kern did a lot of work in this area, Mike Samuel summarised it as
"Distinguish strings from a trusted developer, from strings that may be
attacker controlled", and Erik Poll wrote this paper:
https://www.cs.ru.nl/~erikpoll/papers/secure_input_handling.pdf
Or this summary I put together:
https://eiv.dev/
Unfortunately, when I put this forward, it was rejected:
https://wiki.php.net/rfc/is_literal
After the vote a couple of people said they wanted it to be implemented as
a type as well (when I've got some more time/money I'll finish this);
otherwise it seemed that most people were concerned about the length of the
discussion, a naming mistake, and voting closed a day before the 8.1
deadline.
That said, Python already has the LiteralString type; Go can use an
"un-exported string type" (string must be in the compiled code); C++ can
use a "consteval annotation"; C# can use a "ConstantExpected annotation"; Scala
can use "String with Singleton"; Java can use a @CompileTimeConstant
annotation from ErrorProne; Rust can use a "procedural macro"; and Node can
use goog.string.Const in Google's Closure Library.
Craig