Close-up of PHP code on a dark screen, illustrating the PHP 8.6 release and its new secure session defaults

PHP 8.6 ships with secure session defaults, at last

Photo: Yu. Samoilov on Flickr, CC BY 2.0

Timing is everything. PHP 8.6 landed on Thursday, right on its yearly schedule, as if the last six weeks hadn’t been a nonstop fire drill for anyone running a PHP server. And the headline feature isn’t a shiny new syntax trick. It’s PHP finally admitting that some of its defaults were, let’s say, generous.

Quick recap for those who spent November under a rock (lucky you). Since October, a pile of vulnerabilities has let unauthenticated attackers crash PHP workers or run code on the box. WordPress, Laravel, Symfony, your cousin’s forum from 2009: everyone had to patch, fast. The core team and the PHP Foundation shipped a coordinated batch (8.5.13, 8.4.28, 8.3.37, 8.2.36 and 8.6) that closes seven critical remote code execution bugs in one go. It was the same scramble we saw when 178 big sites served malware through one compromised vendor: the web stack is only as calm as its weakest shared component.

What PHP 8.6 changes in sessions

The interesting bit is older than the crisis. Back in June, core developer Jörg Sowa pointed out that three settings of the session extension (strict mode, HttpOnly and SameSite) existed precisely to protect you, yet shipped “with defaults that leave applications unnecessarily exposed”. His proposal got accepted, and PHP 8.6 is where it takes effect, as The Register reports.

Concretely: strict mode is on, so PHP refuses session IDs it didn’t generate itself. Before, an attacker could hand a victim a made-up ID and wait. Session cookies now carry the HttpOnly flag by default, which means any random script on the page can no longer read your session ID. Yes, it could before. And SameSite is set so that cookies stay home on cross-site POSTs, iframes and subrequests. Forged forms on a shady site stop triggering authenticated actions in your name.

None of this stops an RCE. But session fixation, cookie theft and CSRF are the bread and butter of boring, everyday attacks, and those just got harder without you writing a single line.

Null bytes and functions that stop lying

The engine also gets grumpier about strings containing null bytes. In many places, “\0” now throws instead of sliding through silently. If you’ve ever read a CVE writeup, you know why: a C function sees the null byte as the end of the string and happily ignores whatever comes after it. Attackers love that. Fewer silent passes, fewer surprises.

In the same mood, a bunch of functions stop pretending everything went fine. Closing a file or copying data will explicitly return false when it fails midway, instead of shrugging. Not glamorous, but that’s the kind of thing that turns a mysterious corrupted upload into an actual error you can log.

For the fun side, PHP 8.6 brings partial function application (pre-fill some arguments, get a closure back), a native polling API for event-driven networking, a Duration class that can count elapsed time over 250 years, and a tiny clamp() function that every codebase has reimplemented at least twice.

The php.ini trap

Here’s the part I’d actually print and tape to the server rack. Those new defaults only apply if nothing else sets them. Backend engineer Rajekevin Dourepoulle spelled it out: if your deployment reuses an old php.ini, an Ansible template, a COPY php.ini in a Dockerfile, or a file copied from server to server, “you move to 8.6 and gain nothing”, because an explicit session.use_strict_mode = 0 line overrides the shiny new default.

So before you celebrate, grep your config for use_strict_mode, cookie_httponly and cookie_samesite, and either delete those lines or set them to the secure values on purpose. Same advice if you tune things through a caching layer or a panel; I’ve seen more than one WordPress caching setup quietly carry a decade-old php.ini along for the ride.

And if you’re wondering whether the PHP project learned anything from this autumn: in a retrospective last month, the Foundation admitted that consensus-driven gridlock had stalled complex fixes for months, and promised to ship faster if a vulnerability leaks before the agreed date. We’ve seen what a slow patch pipeline costs elsewhere, so I’ll take the promise and check back in a year.

PHP 8.6 locks the doors by default. Just make sure your old config isn’t holding one open.


Discover more from TechPassion

Subscribe to get the latest posts sent to your email.

Comments
Add a comment

Leave a Reply