Skip to content

Commit beb8b63

Browse files
committed
feature #1592 [make:security:form-login] Tweak login forms to enable double-submit CSRF protection (nicolas-grekas)
This PR was merged into the 1.x-dev branch. Discussion ---------- [make:security:form-login] Tweak login forms to enable double-submit CSRF protection Will be leveraged by symfony/symfony#58095 Does no harm being enabled regardless of the Symfony version in use. --- Waiting on: - [x] symfony/symfony#58095 Commits ------- b13f0fb Generate data-controller="csrf-protection" on CSRF fields
2 parents dcd2260 + b13f0fb commit beb8b63

File tree

4 files changed

+4
-16
lines changed

4 files changed

+4
-16
lines changed

templates/authenticator/login_form.tpl.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
<input type="<?= $username_is_email ? 'email' : 'text'; ?>" value="{{ last_username }}" name="<?= $username_field; ?>" id="input<?= ucfirst($username_field); ?>" class="form-control" autocomplete="<?= $username_is_email ? 'email' : 'username'; ?>" required autofocus>
2222
<label for="inputPassword">Password</label>
2323
<input type="password" name="password" id="inputPassword" class="form-control" autocomplete="current-password" required>
24-
25-
<input type="hidden" name="_csrf_token"
26-
value="{{ csrf_token('authenticate') }}"
27-
>
24+
<input type="hidden" name="_csrf_token" data-controller="csrf-protection" value="{{ csrf_token('authenticate') }}">
2825
<?php if($support_remember_me && !$always_remember_me): ?>
2926

3027
<div class="checkbox mb-3">

templates/security/formLogin/login_form.tpl.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
<input type="<?= $username_is_email ? 'email' : 'text'; ?>" value="{{ last_username }}" name="_username" id="username" class="form-control" autocomplete="<?= $username_is_email ? 'email' : 'username'; ?>" required autofocus>
2222
<label for="password">Password</label>
2323
<input type="password" name="_password" id="password" class="form-control" autocomplete="current-password" required>
24-
25-
<input type="hidden" name="_csrf_token"
26-
value="{{ csrf_token('authenticate') }}"
27-
>
24+
<input type="hidden" name="_csrf_token" data-controller="csrf-protection" value="{{ csrf_token('authenticate') }}">
2825

2926
{#
3027
Uncomment this section and add a remember_me option below your firewall to activate remember me functionality.

tests/fixtures/security/make-form-login/expected/login.html.twig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
<input type="email" value="{{ last_username }}" name="_username" id="username" class="form-control" autocomplete="email" required autofocus>
2020
<label for="password">Password</label>
2121
<input type="password" name="_password" id="password" class="form-control" autocomplete="current-password" required>
22-
23-
<input type="hidden" name="_csrf_token"
24-
value="{{ csrf_token('authenticate') }}"
25-
>
22+
<input type="hidden" name="_csrf_token" data-controller="csrf-protection" value="{{ csrf_token('authenticate') }}">
2623

2724
{#
2825
Uncomment this section and add a remember_me option below your firewall to activate remember me functionality.

tests/fixtures/security/make-form-login/expected/login_no_logout.html.twig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
<input type="email" value="{{ last_username }}" name="_username" id="username" class="form-control" autocomplete="email" required autofocus>
1414
<label for="password">Password</label>
1515
<input type="password" name="_password" id="password" class="form-control" autocomplete="current-password" required>
16-
17-
<input type="hidden" name="_csrf_token"
18-
value="{{ csrf_token('authenticate') }}"
19-
>
16+
<input type="hidden" name="_csrf_token" data-controller="csrf-protection" value="{{ csrf_token('authenticate') }}">
2017

2118
{#
2219
Uncomment this section and add a remember_me option below your firewall to activate remember me functionality.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy