fix(audit L5): unter der Sperre Divis Laufzeit-Caches verwerfen (Options-Cache-Gruppe, GlobalData-/GlobalPreset-Static, et_theme_options) vor raw() und design_rev

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-20 00:26:40 +02:00
co-authored by Claude Sonnet 5.5
parent 6e84138979
commit 99c7aab238
28 changed files with 182 additions and 13 deletions
@@ -102,26 +102,33 @@ final class DesignLockTest extends TestCase
public function testTheLockHolderReadsEtDiviFreshNotFromTheRequestStartCache(): void
{
$db = $this->table();
$stored = ['et_divi' => ['color' => 'alt']];
$stored = ['et_divi' => ['color' => 'alt'], 'et_divi_global_variables' => ['v' => 'alt']];
$cache = [];
// Like WordPress: every option is cached under its own key (not autoloaded ones) or in "alloptions".
Functions\when('get_option')->alias(static function (string $name) use (&$stored, &$cache) {
if (! isset($cache['options:' . $name]) && ! isset($cache['options:alloptions'][$name])) {
$cache['options:alloptions'][$name] = $stored[$name] ?? false;
}
$key = 'options:' . $name;
$cache[$key] ??= $stored[$name] ?? false;
return $cache['options:' . $name] ?? $cache['options:alloptions'][$name];
return $cache[$key];
});
Functions\when('wp_cache_delete')->alias(static function (string $key, string $group = '') use (&$cache): bool {
unset($cache[$group . ':' . $key]);
Functions\when('wp_cache_flush_group')->alias(static function (string $group) use (&$cache): bool {
foreach (array_keys($cache) as $key) {
if (str_starts_with($key, $group . ':')) {
unset($cache[$key]);
}
}
return true;
});
self::assertSame(['color' => 'alt'], get_option('et_divi'), 'request B cached the old array');
self::assertSame(['v' => 'alt'], get_option('et_divi_global_variables'));
$stored['et_divi'] = ['color' => 'neu']; // request A wrote and released meanwhile
$stored['et_divi_global_variables'] = ['v' => 'neu'];
self::assertTrue((new DesignLock())->acquire('colors'));
self::assertSame(['color' => 'neu'], get_option('et_divi'));
self::assertSame(['v' => 'neu'], get_option('et_divi_global_variables'), 'also options that are not autoloaded');
self::assertNotSame([], $db->rows);
}
}