Hardening: re-validate stored host settings on load #13
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: hardening (only reachable by a fully privileged writer). Found by security audit run 3 (commit
01195c8), observed in a local lab.What happens
Repository::load->Settings::fromArray->Host::fromArray(src/Config/Settings.php:69-79,src/Config/Host.php:40-47) only casts stored values; it does not re-run the sanitizer. The sanitizer is attached viaregister_settingonadmin_init, sowp option update(WP-CLI), direct DB writes or other plugin code bypass it. Effects observed with deliberately malformed stored data:ContentRewritermatch every bare//(JS comments,http://) and rewrite it to the current host;http:///pathredirects and adds''toallowed_redirect_hosts;could not be converted to string).Suggested fix
In
Settings::fromArray/Host::fromArray, run each host throughHostHeader::normalize, drop rows that come back empty or are non-scalar, validatelangwithLocales::isValid, and enforce a single primary (mirrorSettingsSanitizer::enforceSinglePrimary). Defence in depth: refuse to emit URLs when the current host is empty. Regression test:Settings::fromArray(['hosts'=>[['host'=>'','is_primary'=>true],['host'=>'www.example.test']]])yields one host,www.example.test, flagged primary.