Compare commits

...

2 Commits

Author SHA1 Message Date
niklas.ortmann a728a8a556 Update showArticle-controller.php 2026-07-19 16:08:55 +02:00
niklas.ortmann ae34afda15 Update article-validator.php 2026-07-19 16:08:06 +02:00
2 changed files with 22 additions and 3 deletions
+7 -3
View File
@@ -7,10 +7,14 @@ require_once 'php/model/Article.php';
require_once 'php/model/ArticleManager.php';
require_once 'php/model/UserManager.php';
require_once 'php/model/CommentManager.php';
require_once 'php/validator/article-validator.php';
if (isset($_GET["id"]) && !empty($_GET["id"])){
// Die übergebene ID muss eine gültige, positive Zahl sein, bevor sie
// weiterverwendet wird. Vorher wurde jeder nicht-leere Wert akzeptiert.
$id = isset($_GET["id"]) ? articleIdValidator($_GET["id"]) : false;
if ($id !== false) {
try {
$id = $_GET["id"];
$articleManager = ArticleManager::getInstance();
$article = $articleManager->getArticle($id);
if($article != null){
@@ -38,7 +42,7 @@ if (isset($_GET["id"]) && !empty($_GET["id"])){
}
$commentManager = CommentManager::getInstance();
$comments = $commentManager->getCommentsByArticle($_GET["id"]);
$comments = $commentManager->getCommentsByArticle($id); // NEU: validierte ID statt rohem $_GET["id"]
foreach ($comments as $comment) {
if ($comment->isReply()) {
+15
View File
@@ -1,5 +1,20 @@
<?php
/**
* NEU: Prüft, ob ein übergebener Wert eine gültige, positive
* Beitrags-ID ist. Wird überall dort verwendet, wo eine Artikel-ID
* aus $_GET oder $_POST entgegengenommen wird
*
* @param mixed $id
* @return int|false Die validierte ID als int, oder false bei Ungültigkeit
*/
function articleIdValidator($id)
{
$options = ["options" => ["min_range" => 1]];
return filter_var($id, FILTER_VALIDATE_INT, $options);
}
/**
* Prüft, ob der Titel die folgenden Bedingungen erfüllt:
* Buchstaben von a-z; A-Z