diff --git a/php/controller/updateArticle-controller.php b/php/controller/updateArticle-controller.php index cb58617..bc24544 100644 --- a/php/controller/updateArticle-controller.php +++ b/php/controller/updateArticle-controller.php @@ -8,6 +8,7 @@ require_once '../model/ArticleManager.php'; require_once '../model/Article.php'; require_once '../validator/article-validator.php'; require_once '../../includes/article-block-helper.php'; +require_once '../../includes/csrf.php'; // NEU: CSRF-Schutz if (!isset($_SESSION["user"])) { header("Location: index.php?pfad=login"); @@ -16,9 +17,17 @@ if (!isset($_SESSION["user"])) { if ($_SERVER["REQUEST_METHOD"] === "POST") { - if (isset($_GET["id"]) && !empty($_GET["id"])) { - $id = $_GET["id"]; - } else { + // CSRF-Token prüfen, bevor irgendeine Änderung vorgenommen wird + if (!csrf_verify()) { + $_SESSION["message"] = "invalid_csrf_token"; + header("location: ../../index.php?pfad=updateArticle"); + exit(); + } + + // Die Beitrags-ID muss eine gültige numerische ID sein + $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT); + + if ($id === false || $id === null) { $_SESSION["message"] = "missing_id"; header("location: ../../index.php?pfad=updateArticle"); exit(); @@ -27,6 +36,14 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") { try { $articleManager = ArticleManager::getInstance(); $article = $articleManager->getArticle($id); + + // Existenz des Beitrags prüfen, bevor auf $article zugegriffen wird. + if ($article === null) { + $_SESSION["message"] = "missing_id"; + header("location: ../../index.php?pfad=updateArticle"); + exit(); + } + if ($article->getAuthor() != $_SESSION["user_email"]) { $_SESSION["message"] = "unauthorized_access"; header("location: ../../index.php");