fix(security): Add security hardening and CSRF protection.

Added .htaccess rules to deny access to hidden files. Escaped JSON output in views to prevent XSS attacks. Converted delete links and forms to use POST with CSRF tokens. Enforced POST method on sensitive routes. Added tests to verify these security controls.
This commit is contained in:
2026-12-02 11:07:41 +01:00
parent 6f02b0bc8d
commit b44b1bfc72
11 changed files with 318 additions and 18 deletions
@@ -1,13 +1,22 @@
<?php
phpb_requires_authenticated();
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
return;
}
if (!function_exists('phpb_validate_csrf') || !phpb_validate_csrf()) {
http_response_code(403);
return;
}
$formsRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
$entriesRepository = new \Plugi\Extensions\Form\EntriesRepository();
if(
isset($_GET['id'])
isset($_POST['id'])
) {
$formsRepository->destroy($_GET['id']);
$entriesRepository->destroyWhere('formId', $_GET['id']);
$formsRepository->destroy($_POST['id']);
$entriesRepository->destroyWhere('formId', $_POST['id']);
}
phpb_redirect(phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'listForms']));