diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 5841f4da7b..acca1cfc0a 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -586,7 +586,7 @@ public function resetAction($type) /** * Delete account for current user. * - * @Route("/account/delete", name="delete_account") + * @Route("/account/delete", name="delete_account", methods={"POST"}) * * @throws AccessDeniedHttpException * @@ -594,6 +594,10 @@ public function resetAction($type) */ public function deleteAccountAction(Request $request) { + if (!$this->isCsrfTokenValid('delete-account', $request->request->get('token'))) { + throw $this->createAccessDeniedException('Bad CSRF token.'); + } + $enabledUsers = $this->get('wallabag_user.user_repository') ->getSumEnabledUsers(); diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 28ff364cbf..c55df53003 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -548,7 +548,7 @@ - +
{{ 'config.reset.title'|trans }}
@@ -573,9 +573,11 @@
{{ 'config.form_user.delete.title'|trans }}

{{ 'config.form_user.delete.description'|trans }}

- +
+ + + +
{% endif %}
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index d6a0f0d780..1021b2bcee 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -794,7 +794,7 @@ public function testDeleteUserButtonVisibility() $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertStringNotContainsString('config.form_user.delete.button', $body[0]); - $client->request('GET', '/account/delete'); + $client->request('POST', '/account/delete'); $this->assertSame(403, $client->getResponse()->getStatusCode()); $user = $em @@ -860,9 +860,9 @@ public function testDeleteAccount() $crawler = $client->request('GET', '/config'); - $deleteLink = $crawler->filter('.delete-account')->last()->link(); + $deleteForm = $crawler->filter('form[name=delete-account]')->form(); - $client->click($deleteLink); + $client->submit($deleteForm); $this->assertSame(302, $client->getResponse()->getStatusCode()); $em = $client->getContainer()->get('doctrine.orm.entity_manager');