true, CURLOPT_FOLLOWLOCATION => false, CURLOPT_COOKIEJAR => $jar, CURLOPT_COOKIEFILE => $jar, CURLOPT_TIMEOUT => 15, ]); if ($post !== null) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); } $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return [(int) $code, (string) $body]; } function lockout_probe_csrf(string $html): string { // csrf-magic embeds the token in a hidden field and a JS variable. if (preg_match('/name="__csrf_magic"\s+value="([^"]+)"/', $html, $m)) { return $m[1]; } if (preg_match("/csrfMagicToken\s*=\s*\"([^\"]+)\"/", $html, $m)) { return $m[1]; } return ''; } // Authenticate. [, $loginHtml] = lockout_probe_request("$base/index.php", $jar); $token = lockout_probe_csrf($loginHtml); if ($token === '') { lockout_probe_fail('could not extract a CSRF token from the login page'); } lockout_probe_request("$base/index.php", $jar, [ '__csrf_magic' => $token, 'action' => 'login', 'login_username' => $user, 'login_password' => $pass, ]); // Without this, a failed login (bad credentials, CSRF rejected) would still // "pass" below: the lockout requests would just bounce off auth instead of // the guard under test, leaving cacti_lockout_status untouched either way. [, $sessionHtml] = lockout_probe_request("$base/index.php", $jar); if (str_contains($sessionHtml, 'name="login_username"')) { lockout_probe_fail('login did not authenticate the session (login form still shown)'); } $before = read_config_option('cacti_lockout_status', true); // A GET must be refused: the guard redirects before any state change. lockout_probe_request("$base/support.php?action=lockout", $jar); $after_get = read_config_option('cacti_lockout_status', true); if ($after_get !== $before) { lockout_probe_fail('GET to action=lockout changed the lockout state'); } // A POST without the CSRF token must be refused by csrf_check(). lockout_probe_request("$base/support.php?action=lockout", $jar, ['expected' => 'unlocked']); $after_post = read_config_option('cacti_lockout_status', true); if ($after_post !== $before) { lockout_probe_fail('POST without a CSRF token changed the lockout state'); } print "PASS support lockout csrf docker probe\n";