Turning On MySQL TLS for Sites I Don’t Control

I run a shared hosting platform with a lot of customer WordPress sites on it (thousands), and every one of them talks to a MySQL cluster over the network. I wanted that traffic encrypted and the server’s certificate verified, without editing a single customer site. PHP has no way to do that, so I wrote php-mysqlnd-tls, an extension that turns it on from php.ini:

mysqlnd_tls.enabled = On
mysqlnd_tls.hosts   = "db.example.com"

Only the Client Can Ask

In the MySQL protocol the server speaks first, and the client then decides whether to request TLS before it logs in. The server can accept a plaintext login or refuse it, but it can’t upgrade one.

The mysql command line client asks by default, but PHP doesn’t. On a stock PHP build, both mysqli and PDO connect through mysqlnd (for mysqli it’s been the only driver since PHP 8.2), and mysqlnd uses TLS only when the application requests it: MYSQLI_CLIENT_SSL, mysqli::ssl_set(), or the PDO::MYSQL_ATTR_SSL_* options. There’s no php.ini setting for it.

One Line per Site Is Still Too Many

WordPress can ask, with one line in wp-config.php:

define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);

That’s one edit per site, in a file the customer owns. Customers restore old backups, migrate sites in from other hosts, and reinstall from scratch, and each of those quietly puts the site back on plaintext. The line also does nothing for sites that aren’t WordPress.

Even where the line is set, WordPress passes the flag and nothing else, and with the flag alone mysqlnd doesn’t verify the server’s certificate. The connection is encrypted, but nothing checks who’s on the other end.

I could have added that line myself. PHP’s auto_prepend_file setting runs a file ahead of every script, so one prepended file could define the constant for every site. That means running my code inside every request to every customer’s site, which is a security issue. It’s a permissions issue too: the file has to be readable by each site’s own user and sit inside each site’s open_basedir, or PHP refuses to open it. And it’s still WordPress only.

The server side is no help. Set require_secure_transport = ON and MySQL refuses every plaintext login, which on day one means every site that hasn’t been edited. Requiring it user by user, with ALTER USER ... REQUIRE SSL, helps with a slow rollout, but it doesn’t solve the other issues: each of those sites still has to ask for TLS.

The Tunnel I Used Before

My old answer was a TLS tunnel that’s invisible to the sites: a proxy on each web server accepts plaintext MySQL connections and carries them inside TLS to the MySQL cluster, where a second proxy unwraps them.

The problem is that every database connection from every site goes through the tunnel, which makes it a single point of failure between two systems that were built to stay up. When it goes down, the web servers and MySQL are both still up, and every site shows a database error anyway.

MySQL also never sees TLS. The tunnel hands mysqld an ordinary plaintext TCP connection, so require_secure_transport and REQUIRE SSL can never be turned on.

Native TLS has neither problem: there’s nothing in between to fail, and both ends know the connection is encrypted, so the server can enforce it. I just needed a way to turn it on.

Moving the Decision to php.ini

mysqlnd has a plugin API that lets an extension replace the methods of its connection object. php-mysqlnd-tls replaces connect with a wrapper: for a host on the list it adds the TLS flag, sets the verification flags and the trust store, and calls the original. That’s about 250 lines of C. It never reads mysqlnd’s internal structures, which is why one source tree builds on every PHP version from 7.4 to 8.6.

For a host on the list, the setting decides what every site gets:

The site What it gets
Asks for nothing TLS, with the certificate and host name verified
Already asks for TLS (the WordPress define) The same; nothing conflicts
Sets its own CA, or asks for no verification The administrator’s trust store and verify setting
Sends a client certificate Kept, so accounts that require one keep working
Connects to a server that doesn’t offer TLS Refused. There’s no fallback to plaintext
Connects to any other host, or over a Unix socket Left exactly as it was

Only the Hosts You List

The policy applies to the hosts named in mysqlnd_tls.hosts and to nothing else. I list my own cluster, so every connection to it is encrypted and verified, whatever the site asked for.

A customer who connects to an external MySQL server is left alone. If their site asks for TLS, it gets TLS with its own settings, and if it connects in plaintext, that still works. It’s their server and their decision. The extension lets me enforce encryption on the servers I control without breaking a site that points somewhere else.

Rolling It Out

Every setting is PHP_INI_SYSTEM, so ini_set(), .htaccess, and .user.ini can’t change it. The administrator can still enable it per site, which makes it easy to roll out a few sites at a time:

<VirtualHost *:80>
    ServerName www.example.com
    php_admin_flag mysqlnd_tls.enabled on
</VirtualHost>

It installs with PIE. Each release carries pre-built binaries for PHP 7.4 through 8.6 on x86_64 and arm64, so most Linux servers don’t need a compiler:

pie install mikepultz/php-mysqlnd-tls

Then Enforce It on the Server

The extension makes PHP ask for TLS, but it can’t stop a client that doesn’t load it: anyone who can run php -n connects however they like, and so does anything that isn’t PHP. The session status shows what a connection actually got:

$row = $mysqli->query("show session status like 'Ssl_cipher'")->fetch_row();

echo ($row[1] === '') ? 'plaintext' : 'encrypted with ' . $row[1];

Once no client is still connecting in plaintext, set require_secure_transport = ON. That’s the setting I couldn’t touch at the start, and it’s on now.

The extension has been running in production for weeks now, and it works great.

Patching PHP’s Two Critical RCEs

On 21 October the PHP project released 8.5.12, 8.4.27, 8.3.36 and 8.2.35 to fix two remote code execution vulnerabilities, CVE-2026-109618 and CVE-2026-109619. Both are rated 9.2 on CVSS v4, and neither needs authentication. Both advisories say updating is the only complete fix.

Fixed Versions

Branch Fixed in
8.5 8.5.12
8.4 8.4.27
8.3 8.3.36
8.2 8.2.35
8.1 and older No upstream release. The PHP security team published minimal source backports for 7.4, 8.0 and 8.1; Debian and Ubuntu users can get fixed builds from packages.sury.org; otherwise check your LTS vendor.

Linux distributions received the patches in advance, so most systems get the fix as a normal package update.

The Two Bugs

CVE-2026-109618 is in out-of-memory handling. PHP aborts on an out-of-memory error with longjmp(). If that happens while it’s still parsing the request body, request data is left half-initialized, and request shutdown later processes it as valid. Crafted multipart requests can trigger this while staying inside PHP’s input limits. The fix removes longjmp() from out-of-memory handling.

CVE-2026-109619 is a use-after-free. A request that’s interrupted by a fatal error, a timeout or running out of memory can leave freed state behind on the worker, and a later request on the same worker can read it before initialization resets it. Confirmed paths include session upload progress, which is on by default and doesn’t need session_start(), and PHP 8.5’s fatal_error_backtraces. The impact includes memory disclosure as well as code execution.

Exposure by Server API

SAPI CVE-2026-109618 CVE-2026-109619
Apache mod_php Code execution validated with default limits, before application code runs Code execution confirmed
PHP-FPM Exploitable by source analysis, not fully demonstrated Code execution validated through session upload progress; depends on the application
php-cgi, FrankenPHP, LiteSpeed Listed as at risk by php.net

Checking What You Run

The CLI and the web server often run different PHP packages, so check the one serving requests:

php -v                      # CLI only
php-fpm -v                  # often versioned: php-fpm8.3 -v
apachectl -M | grep -i php  # is mod_php loaded?
apt policy php8.3-fpm       # Debian/Ubuntu: installed version and its repo

On Debian and Ubuntu, fixed builds reached packages.sury.org before the ppa:ondrej/php Launchpad PPA, so confirm the installed version if you use the PPA. Ondřej Surý is tracking the rollout, including the end-of-life branches, in this issue.

After updating, restart PHP-FPM or Apache so no worker is still running the old build. The full details, including interim settings for systems that can’t update immediately, are in the php.net advisory.

Reading a Spamhaus Listing Without Panicking

The first reaction to a Spamhaus listing is usually to find the delisting form. That is almost always the wrong first move, because the return code already tells you which of several unrelated problems you have, and three of them cannot be fixed by delisting at all.

The Code Is the Diagnosis

A DNSBL answers with an address in 127.0.0.0/8, and the last octet identifies which dataset matched. Querying the combined zone gives you one lookup and a code that says which list you are on:

$ dig +short 2.0.113.203.zen.spamhaus.org A
127.0.0.4

Note the reversed octets. The address 203.0.113.2 becomes 2.0.113.203 in the query. The codes map like this:

127.0.0.2    SBL       manually researched spam source
127.0.0.3    CSS       automatically detected low-reputation sender
127.0.0.4    XBL       compromised or exploited machine
127.0.0.9    DROP      resource controlled by bad actors
127.0.0.10   PBL       dynamic space, declared by the ISP
127.0.0.11   PBL       dynamic space, inferred by Spamhaus
127.0.0.20   AuthBL    credential bruteforcing or hijacking
127.0.0.30   BCL       malware command and control

An empty answer means not listed. Always fetch the TXT record too, since it carries the reference URL for that specific listing.

What Each One Means for You

PBL, 127.0.0.10 or 127.0.0.11, is not a reputation problem and it is the most common cause of confusion. It says the address is in a range that should not be running a mail server, either because the ISP declared it dynamic or because Spamhaus inferred it. You have done nothing wrong. If you are sending from a residential or default cloud IP, the fix is to send through a proper relay or get static space with a matching declaration from the provider. Delisting an address whose range is still marked dynamic accomplishes nothing durable.

XBL, 127.0.0.4, means the address is emitting traffic characteristic of a compromised machine. Treat it as an incident. Something is infected, or something is being proxied through, or you have an open relay or a web form somebody is abusing. Delist after you find it and the listing returns within hours, which at least confirms the diagnosis.

CSS, 127.0.0.3, is automated and driven by sending behavior: poor list hygiene, high bounce rates, spam-trap hits, sudden volume changes from a cold address. This is the one that most often reflects marketing practice rather than a technical fault, and the technical team frequently cannot fix it alone.

SBL, 127.0.0.2, is manually researched by a human at Spamhaus. Something specific and documented happened, the TXT record will point to the evidence, and there is no automated path out. Read the reference before contacting anyone.

DROP and BCL are severe. DROP marks space believed to be under criminal control, and BCL marks malware command-and-control infrastructure. If either appears against space you own, the conversation is with your provider and probably with an incident responder.

Delisting Without Fixing the Cause

Every automated list re-lists. That is the point of automation. Requesting removal while the underlying condition persists buys hours, and it also trains you to treat the listing as the problem instead of the symptom.

The order that works is to identify the code, find and fix the cause, verify the cause is actually gone, and then request removal. For CSS in particular, verification means watching your own outbound metrics for long enough to know the behavior changed, since a quiet weekend proves nothing.

Check the Basics While You Are There

Listings frequently arrive alongside configuration problems that make delivery worse independently. Reverse DNS that does not exist or does not match the HELO name, SPF that does not cover the sending host, DMARC set to a policy nobody tested. None of those cause a Spamhaus listing directly, and all of them compound the damage while you are listed.

$ dig +short -x 203.0.113.2
mail.example.com.
$ dig +short mail.example.com A
203.0.113.2

Forward and reverse should agree. The email health check on mrdns.com runs that alongside SPF, DKIM, and DMARC in one pass, and the blacklist check covers the wider set of lists in case this is not the only one you are on.

One operational note if you are querying at any volume: the free DNS interface is intended for individual mail servers checking their own inbound traffic. Anything programmatic or repeated belongs on Spamhaus’s data query service, and running bulk lookups against the public zone will get you blocked, which then looks exactly like a clean result.

systemd Hardening for Long-Running Daemons

A long-running daemon that talks to the network and a database is the thing an attacker wants most, and it is usually the thing running with the fewest restrictions. systemd ships a large set of sandboxing directives that cost nothing at runtime and are almost never used, mostly because the documentation presents forty options with no indication of which ones matter.

Measure First

systemd will grade the unit for you, which is a better starting point than reading the manual page end to end:

systemd-analyze security tracker.service

You get a per-directive table and an overall exposure score from 0 to 10. A default unit with no hardening scores around 9.6, which the tool cheerfully labels UNSAFE. The score is a rough heuristic rather than a real measure of risk, and it is genuinely useful for ordering the work, since it sorts by exposure and shows what each setting would buy.

The Directives Worth Setting

These are the ones I put on every service, in rough order of value per unit of trouble:

[Service]
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
ProtectProc=invisible
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
RemoveIPC=yes
MemoryDenyWriteExecute=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
CapabilityBoundingSet=
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX

NoNewPrivileges=yes is the single highest-value line. It blocks setuid escalation for the process and everything it spawns, and almost nothing legitimately needs the alternative.

ProtectSystem=strict mounts the entire filesystem read-only apart from /dev, /proc, and /sys. Combined with ProtectHome=yes, a compromised process cannot write anywhere at all until you grant specific paths back:

ReadWritePaths=/var/lib/tracker /var/log/tracker
RuntimeDirectory=tracker
StateDirectory=tracker

The RuntimeDirectory and StateDirectory forms are better than listing paths by hand, because systemd creates them with the right ownership and cleans up runtime state on stop.

CapabilityBoundingSet= with an empty value drops every capability. Most daemons need none, and the common exception is binding a port below 1024, which needs CAP_NET_BIND_SERVICE added back. Better still, use a socket unit and let systemd hold the privileged socket so the service never needs the capability at all.

RestrictAddressFamilies is worth the thought. A daemon doing DNS and PostgreSQL over TCP needs AF_INET, AF_INET6, and AF_UNIX for the local socket. It has no business creating a raw packet socket or an AF_NETLINK socket, and denying those closes a real avenue.

The Ones That Will Break You

MemoryDenyWriteExecute=yes blocks pages that are both writable and executable. It is excellent against a large class of exploit, and it breaks anything with a JIT. For a C++ daemon it is usually free. For anything embedding a scripting runtime, test carefully.

SystemCallFilter=@system-service is the setting most likely to produce a mysterious failure. The allow list covers what normal services do, and a program using something unusual gets killed with SIGSYS and no useful message. When a service dies immediately after adding it, find the offending call rather than guessing:

journalctl -u tracker.service | grep -i seccomp
auditctl -a always,exit -F arch=b64 -S all -F key=seccomp-debug

ProtectSystem=strict breaks anything writing outside its declared paths, which in practice means log files in unexpected places and PID files in /var/run. Both are better fixed than exempted.

ProtectProc=invisible hides other users’ processes in /proc. Harmless for most daemons and immediately fatal for anything that inspects the process table, including some monitoring agents.

Do It Incrementally

Adding all twenty lines at once and finding the service dead tells you nothing about which line did it. Add the block above minus SystemCallFilter and MemoryDenyWriteExecute, confirm the service still works under real load rather than just starting, then add those two separately.

“Starts successfully” is a weak test. Sandboxing failures show up on code paths that only run occasionally, so the syscall your daemon makes once a day during log rotation is exactly the one the filter blocks. Give a hardened unit a full cycle of whatever periodic work it does before considering it verified.

None of this replaces running as an unprivileged user, keeping the software patched, or putting the database somewhere the internet cannot reach. It is the layer underneath those, and it is roughly twenty lines of configuration that turns a total compromise of the process into a considerably less useful foothold.

Why Your DNS Change Looks Different From Eight Places at Once

“Waiting for DNS to propagate” is the most common description of something that does not happen. There is no propagation in DNS. Nothing is pushed anywhere. Understanding what is actually going on turns a mysterious waiting period into an arithmetic problem you can predict and control.

Nothing Travels

When you change a record, exactly one thing happens: your authoritative nameservers start returning a new answer. That change is complete the moment the zone reloads, which is usually seconds. Any resolver that asks after that gets the new value immediately.

What varies is when each resolver next bothers to ask, and that is governed entirely by the TTL of the answer it cached before you made the change. A resolver holding a record with a 3600 second TTL will keep serving the old value for up to an hour, and no action on your end reaches inside its cache. You are not waiting for something to spread. You are waiting for copies to expire.

This is why checking from eight locations gives eight different answers during the window, and why the pattern looks random. Each of those resolvers cached at a different moment, so each expires at a different moment. The propagation checker on mrdns.com is really a cache-expiry checker, and reading it that way makes the staggered results obvious.

The TTL That Matters Is the Old One

Here is the part that trips people up. Lowering a record’s TTL right before you change it does nothing useful, because resolvers are still holding the copy they fetched under the previous, longer TTL.

; Monday: the value resolvers have cached
www.example.com.    86400    IN    A    203.0.113.10

; Friday: lowered TTL and changed the address at the same time
www.example.com.      300    IN    A    203.0.113.55

A resolver that cached on Monday holds the old address for a full day regardless of what Friday’s record says, because it will not re-ask until its copy expires. The 300 second TTL only starts applying to whatever it fetches next.

The sequence that works is to lower the TTL first, wait at least the old TTL so every cached copy expires and gets replaced by a short-lived one, and only then change the value. Now the maximum staleness is 300 seconds. Raise the TTL again once the change has settled.

For a planned migration that means starting a day or two ahead. Doing it the other way around and then waiting is the origin of most “DNS is still propagating” complaints.

Negative Answers Cache Too

If someone queries a name before it exists, the NXDOMAIN gets cached. The lifetime of that negative answer comes from the zone’s SOA record, specifically the minimum field, per RFC 2308:

example.com.  IN  SOA  ns1.example.com. hostmaster.example.com. (
                  2026081101   ; serial
                  7200         ; refresh
                  3600         ; retry
                  1209600      ; expire
                  3600 )       ; minimum, caps negative caching

A large minimum means that a name someone checked prematurely stays broken for them long after you create it. An hour is reasonable. The multi-day values that appear in copied-and-pasted zone files are not, and they produce the particularly confusing case where a brand new hostname works for most of the world and not for the one person who tried it early.

The Other Places Answers Hide

Delegation TTLs are longer than record TTLs and get overlooked. If you change nameservers, the parent zone’s NS records govern how long resolvers keep asking your old provider, and those are often set to a day or two by the registry. The records at your new provider can be perfect while resolvers continue to consult the old one.

CNAME chains expire independently. Each link has its own TTL, so the effective staleness is set by whichever link is longest, and updating the target does nothing for a resolver still holding the alias.

Then there is everything below the resolver: the stub resolver on the client, the browser’s own cache, and any corporate forwarder in between. Chrome caches independently of the operating system, which is why a page can stay stubbornly wrong on one machine after dig on the same machine returns the new value.

How to Check Properly

Query the authoritative server directly to confirm the change is live, then query a public resolver to see what the cached world still believes:

dig @ns1.example.com www.example.com A +norecurse
dig @8.8.8.8 www.example.com A

The TTL in the second answer counts down toward zero, and it tells you precisely how much longer that resolver will serve the old value. That number is the actual answer to “how long until this is done”, and it is available immediately rather than after waiting to find out. If you want the same view without a terminal, the lookup tool shows the returned TTL alongside the record.