Back

PHP 8.6 tightens session defaults after recent security flaws
SiTech AI Team3 min read

PHP 8.6 tightens session defaults after recent security flaws

PHP 8.6 was released on Thursday with stricter session defaults, null-string handling and other changes after recent critical vulnerabilities affected PHP applications.

PHP 8.6 was released on Thursday on the language's usual yearly schedule, bringing stricter default settings and other changes after a month in which critical vulnerabilities affected PHP applications. The PHP core development community and the PHP Foundation also released patched versions that closed seven critical remote code execution flaws. Users of PHP-based applications, including WordPress, Laravel and Symfony, had to update their PHP instances.

Session defaults get stricter

Core developer Jörg Sowa proposed more security-friendly defaults in June, and that proposal was accepted for PHP 8.6. Strict Mode will no longer accept uninitialized session IDs that PHP did not create itself; if an attacker-planted ID has no corresponding session file, a fresh random ID is generated instead. PHP will now add the HttpOnly flag to its session Set-Cookie header by default, blocking client-side JavaScript from reading the session ID. Previously, any script on the page could read it. The server will also withhold session cookies on cross-site POST requests, subrequests and iframes, sending them only on same-site requests and top-level GET navigations, such as clicking a normal link. Collectively, these changes should thwart session hijacking and cross-site request forgeries. They will not stop remote code execution hacks, though they will make it a lot more difficult for attackers to gain entry.

Other security and language changes

The PHP engine will be stricter when it encounters strings with null values. In many cases it will throw an error rather than silently letting the value pass. A C function will treat the null value as the end of the string, processing everything before the null byte and ignoring everything after. A number of other PHP functions will also no longer remain silent when things go awry; operations for closing a file or copying data will explicitly return false when terminating prematurely or failing, which developers could use to minimize data integrity bugs.

Beyond security, PHP 8.6 includes Partial Function Application, a native polling API, a Duration class that can track elapsed time across more than 250 years, and a clamp() function to keep a value within an acceptable range. Partial Function Application lets developers pre-fill some of a function's arguments to generate a reusable closure on the fly.

Deployment caveat

Backend software engineer Rajekevin Dourepoulle notes that the changes take effect after installation only if configurations are not specified elsewhere, such as in an application, framework or another php.ini file. If a deployment reuses an old php.ini, such as an Ansible template, a COPY php.ini in a Dockerfile, or a file copied from server to server, the explicit session.use_strict_mode = 0 line can override the new default.

Sources: The Register

SiTech

SiTech — AI-powered web development

We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.