diff --git a/php/controller/like-controller.php b/php/controller/like-controller.php index d0d9a95..56bdc33 100644 --- a/php/controller/like-controller.php +++ b/php/controller/like-controller.php @@ -5,6 +5,12 @@ if (session_status() === PHP_SESSION_NONE) { require_once __DIR__ . '/../model/Article.php'; require_once __DIR__ . '/../model/ArticleManager.php'; +require_once __DIR__ . '/../../includes/csrf.php'; + +if ($_SERVER["REQUEST_METHOD"] !== "POST") { + header("Location: ../../index.php"); + exit(); +} // 2. Prüfen, ob eine gültige Artikel-ID übergeben wurde if (isset($_GET["id"]) && !empty($_GET["id"])) { @@ -17,6 +23,13 @@ if (isset($_GET["id"]) && !empty($_GET["id"])) { exit(); } + // CSRF-Token prüfen, bevor der Like-Status verändert wird + if (!csrf_verify()) { + $_SESSION["message"] = "invalid_csrf_token"; + header("Location: ../../index.php?pfad=showArticle&id=" . $articleId); + exit(); + } + try { $articleManager = ArticleManager::getInstance(); $articleManager->toggleLike($articleId, $userEmail);