mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
fixes potential XSS issue with TOTP exception lists (which need escaping, see also #1185). refactors Template escaping to use TemplateEscape enum (rather than the previous boolean). thanks @TrapoSAMA
44 lines
1.9 KiB
PHP
44 lines
1.9 KiB
PHP
<?php
|
|
|
|
// Test-only router: never place this fixture in the public document root.
|
|
if (PHP_SAPI !== 'cli-server' || !getenv('PFA_SECURITY_LIST_TEST_CONFIG')) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
define('PHPUNIT_TEST', true);
|
|
require dirname(__DIR__, 2) . '/vendor/autoload.php';
|
|
$CONF = array_replace($CONF, json_decode(file_get_contents(getenv('PFA_SECURITY_LIST_TEST_CONFIG')), true, 512, JSON_THROW_ON_ERROR));
|
|
require dirname(__DIR__, 2) . '/public/common.php';
|
|
// Exercise plain-text translations containing characters that need HTML escaping.
|
|
$PALANG['pPassword_password_current_text_error'] = 'Invalid <password> & current';
|
|
$PALANG['pPassword_password_text_error'] = 'Invalid <password> & new';
|
|
Config::write('__LANG', $PALANG);
|
|
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
if ($path === '/__session') {
|
|
$globalAdmin = ($_GET['role'] ?? '') === 'global-admin';
|
|
$admin = $globalAdmin || ($_GET['role'] ?? '') === 'admin';
|
|
init_session($admin ? 'admin@security-list-http.example.com' : 'test@security-list-http.example.com', $admin, true);
|
|
if ($globalAdmin) {
|
|
$_SESSION['sessid']['roles'][] = 'global-admin';
|
|
}
|
|
echo 'Session ready';
|
|
} else {
|
|
$pages = [
|
|
'/users/password.php' => 'password.php',
|
|
'/users/totp.php' => 'totp.php',
|
|
'/list-virtual.php' => 'list-virtual.php',
|
|
'/edit.php' => 'edit.php',
|
|
'/app-passwords.php' => 'app-passwords.php',
|
|
'/users/app-passwords.php' => 'app-passwords.php',
|
|
'/totp-exceptions.php' => 'totp-exceptions.php',
|
|
'/users/totp-exceptions.php' => 'totp-exceptions.php',
|
|
];
|
|
if (!isset($pages[$path])) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
// Both public aliases and user routes execute these complete controllers.
|
|
chdir(dirname(__DIR__, 2) . (in_array($path, ['/list-virtual.php', '/edit.php'], true) ? '/public' : '/public/users'));
|
|
require $pages[$path];
|
|
}
|