Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a728a8a556 | |||
| ae34afda15 |
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user