Skip to content

Commit

Permalink
Merge pull request #6289 from wallabag/2.5/fix-csrf-user-deletion
Browse files Browse the repository at this point in the history
Fix CSRF on user deletion
  • Loading branch information
j0k3r committed Feb 7, 2023
2 parents 4e023bd + f1b3d5c commit 268372d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Wallabag/CoreBundle/Controller/ConfigController.php
Expand Up @@ -586,14 +586,18 @@ 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
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
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();

Expand Down
Expand Up @@ -548,7 +548,7 @@
</div>
</div>
</div>

<div id="set7" class="col s12">
<div class="row">
<h5>{{ 'config.reset.title'|trans }}</h5>
Expand All @@ -573,9 +573,11 @@
<div class="row">
<h5>{{ 'config.form_user.delete.title'|trans }}</h5>
<p>{{ 'config.form_user.delete.description'|trans }}</p>
<a href="{{ path('delete_account') }}" onclick="return confirm('{{ 'config.form_user.delete.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red delete-account">
{{ 'config.form_user.delete.button'|trans }}
</a>
<form action="{{ path('delete_account') }}" method="post" onsubmit="return confirm('{{ 'config.form_user.delete.confirm'|trans|escape('js') }}')" name="delete-account">
<input type="hidden" name="token" value="{{ csrf_token('delete-account') }}" />

<button class="waves-effect waves-light btn red" type="submit">{{ 'config.form_user.delete.button'|trans }}</button>
</form>
</div>
{% endif %}
</div>
Expand Down
6 changes: 3 additions & 3 deletions tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 268372d

Please sign in to comment.