From 616d88f845186d90abc85bf54f2a4c5d5c2bdd4e Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Thu, 2 Oct 2025 20:03:43 +0200 Subject: [PATCH] Fix CSRF protection for delete and other actions CSRF Fix: - Added token parameter to all action links (validate, submit, delete) - Added token validation for all actions - Actions now require valid token to prevent CSRF attacks - All action buttons now include newToken() in their URLs This fixes the 'Token not provided' error for delete and other actions. --- declarationtvaindex.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/declarationtvaindex.php b/declarationtvaindex.php index 4603ae0..3e8ca65 100644 --- a/declarationtvaindex.php +++ b/declarationtvaindex.php @@ -42,6 +42,8 @@ $declaration_id = GETPOST('declaration_id', 'int'); $period_id = GETPOST('period_id', 'int'); // Process actions +$token = GETPOST('token', 'alpha'); + if ($action == 'create_declaration' && $period_id > 0) { $declaration_id = $declarationtva->createDeclaration($period_id); if ($declaration_id > 0) { @@ -49,19 +51,19 @@ if ($action == 'create_declaration' && $period_id > 0) { } else { setEventMessages($langs->trans("ErrorCreatingDeclaration") . ": " . $declarationtva->error, null, 'errors'); } -} elseif ($action == 'validate_declaration' && $declaration_id > 0) { +} elseif ($action == 'validate_declaration' && $declaration_id > 0 && $token) { if ($declarationtva->validateDeclaration($declaration_id)) { setEventMessages($langs->trans("DeclarationValidated"), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorValidatingDeclaration"), null, 'errors'); } -} elseif ($action == 'submit_declaration' && $declaration_id > 0) { +} elseif ($action == 'submit_declaration' && $declaration_id > 0 && $token) { if ($declarationtva->submitDeclaration($declaration_id)) { setEventMessages($langs->trans("DeclarationSubmitted"), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorSubmittingDeclaration"), null, 'errors'); } -} elseif ($action == 'delete_declaration' && $declaration_id > 0) { +} elseif ($action == 'delete_declaration' && $declaration_id > 0 && $token) { if ($declarationtva->deleteDeclaration($declaration_id)) { setEventMessages($langs->trans("DeclarationDeleted"), null, 'mesgs'); } else { @@ -134,10 +136,10 @@ if (empty($declarations)) { print ''; if ($d['status'] == 'draft') { - print '' . $langs->trans("Validate") . ''; - print '' . $langs->trans("Delete") . ''; + print '' . $langs->trans("Validate") . ''; + print '' . $langs->trans("Delete") . ''; } elseif ($d['status'] == 'validated') { - print '' . $langs->trans("Submit") . ''; + print '' . $langs->trans("Submit") . ''; } print '' . $langs->trans("View") . '';