mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: prevent duplicate TFE submissions with logging and user feedback
- Add DuplicateThesisException (typed, carries existing thesis metadata) - Add Database::findDuplicateThesis(): matches on year + author + normalised title (exact, prefix, Levenshtein ≤10% of longer string) - ThesisCreateController::submit() runs duplicate check before any DB write and throws DuplicateThesisException on match - AppLogger::logDuplicate() writes status=duplicate entries to the JSON-lines log for audit purposes - App::flash/consumeFlash extended to support 'warning' flash type - admin/actions/formulaire.php: catches DuplicateThesisException, logs it, flashes an HTML warning toast with a clickable link to the existing thesis, and repopulates the form fields - partage/index.php: same catch block; surfaces a plain-text flash-warning banner on the student form with identifier, title, and year of the match; form is repopulated via session - toast.php: renders toast--warning variant - admin.css: .toast--warning + link colour rules - form.css: .flash-warning style for the partage form
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Security Test Suite
|
||||
* Tests SQL injection protection and input sanitization
|
||||
@@ -31,22 +32,22 @@ try {
|
||||
try {
|
||||
$results = $db->searchTheses(['query' => $query]);
|
||||
// Should return a (possibly empty) result set without throwing
|
||||
echo " ✓ Handled safely: " . substr($query, 0, 40) . "\n";
|
||||
echo ' ✓ Handled safely: ' . substr($query, 0, 40) . "\n";
|
||||
} catch (Exception $e) {
|
||||
// A thrown exception is also acceptable (query rejected upstream)
|
||||
echo " ✓ Exception (safe): " . substr($query, 0, 40) . "\n";
|
||||
echo ' ✓ Exception (safe): ' . substr($query, 0, 40) . "\n";
|
||||
}
|
||||
}
|
||||
echo "✓ PASS: SQL injection attempts handled safely\n\n";
|
||||
|
||||
// Test 2: Invalid thesis ID
|
||||
echo "Test 2: Invalid Thesis ID\n";
|
||||
$invalidIds = ["abc", "'; DROP TABLE theses;", "-1", "999999"];
|
||||
|
||||
$invalidIds = ['abc', "'; DROP TABLE theses;", '-1', '999999'];
|
||||
|
||||
foreach ($invalidIds as $id) {
|
||||
$result = $db->getThesisById($id);
|
||||
if ($result === null || $result === false) {
|
||||
echo " ✓ Rejected: " . $id . "\n";
|
||||
echo ' ✓ Rejected: ' . $id . "\n";
|
||||
} else {
|
||||
throw new Exception("Invalid ID '$id' was not rejected");
|
||||
}
|
||||
@@ -69,6 +70,6 @@ try {
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ FAIL: " . $e->getMessage() . "\n";
|
||||
echo '❌ FAIL: ' . $e->getMessage() . "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user