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:
@@ -151,6 +151,7 @@ class WebsiteManager implements WebsiteManagerContract
|
||||
exit();
|
||||
} elseif ($action === "destroy") {
|
||||
$this->handleDestroy($page);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,6 +298,15 @@ class WebsiteManager implements WebsiteManagerContract
|
||||
*/
|
||||
public function handleDestroy(PageContract $page)
|
||||
{
|
||||
if (($_SERVER["REQUEST_METHOD"] ?? "") !== "POST") {
|
||||
http_response_code(405);
|
||||
return false;
|
||||
}
|
||||
if (!function_exists("phpb_validate_csrf") || !phpb_validate_csrf()) {
|
||||
http_response_code(403);
|
||||
return false;
|
||||
}
|
||||
|
||||
$pageRepository = new PageRepository();
|
||||
if (!$pageRepository->destroy($page->getId())) {
|
||||
phpb_redirect(phpb_url("website_manager"), [
|
||||
|
||||
@@ -161,17 +161,20 @@
|
||||
) ?>" class="btn btn-ghost btn-square btn-sm">
|
||||
<i class="text-xl ph-duotone ph-gear" aria-hidden="true"></i>
|
||||
</a>
|
||||
<a href="<?= phpb_url("website_manager", [
|
||||
<form method="post" action="<?= phpb_url("website_manager", [
|
||||
"route" => "page_settings",
|
||||
"action" => "destroy",
|
||||
"page" => $page->getId(),
|
||||
]) ?>" title="<?= phpb_trans(
|
||||
]) ?>">
|
||||
<?php phpb_csrf_field(); ?>
|
||||
<button type="submit" title="<?= phpb_trans(
|
||||
"website-manager.remove",
|
||||
) ?>" aria-label="<?= phpb_e(
|
||||
phpb_trans("website-manager.remove"),
|
||||
) ?>" class="btn btn-error btn-square btn-sm">
|
||||
<i class="text-xl ph-duotone ph-trash" aria-hidden="true"></i>
|
||||
</a>
|
||||
<i class="text-xl ph-duotone ph-trash" aria-hidden="true"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user