1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2026-10-24 12:19:19 +03:00
Files
postfixadmin/public/common.php
Rodrigo Cortés Cano 719935d17a Improve error message for expired CSRF token errors
This backports the invalid-token/session-expired UX improvement to the 4.0 branch.

When a session expires and an old CSRF token is submitted, PostfixAdmin 
currently shows a raw invalid token error. 

This change renders a translated session-expired page instead, returning HTTP 419.

thanks @TrapoSAMA
2026-07-03 18:38:14 +01:00

40 lines
1.3 KiB
PHP

<?php
require_once(dirname(__FILE__) . '/../common.php');
function pfa_handle_invalid_token(): void
{
http_response_code(419); // HTTP 419 Page Expired.
$returnUrl = 'main.php';
$title = Config::lang('session_expired_title') ?: 'Session expired';
$message = Config::lang('session_expired_message') ?: 'The page token is no longer valid. Please return and try again.';
$button = Config::lang('session_expired_button') ?: 'Continue';
echo <<<HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{$title}</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; background: #f6f7f9; color: #222; }
main { max-width: 520px; margin: 12vh auto; padding: 2rem; background: #fff; border: 1px solid #ddd; border-radius: .5rem; text-align: center; }
h1 { margin-top: 0; font-size: 1.5rem; }
p { line-height: 1.45; }
a { display: inline-block; margin-top: 1rem; padding: .65rem 1rem; background: #337ab7; color: #fff; text-decoration: none; border-radius: 4px; }
</style>
</head>
<body>
<main>
<h1>{$title}</h1>
<p>{$message}</p>
<a href="{$returnUrl}">{$button}</a>
</main>
</body>
</html>
HTML;
exit(0);
}