Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csrf validation added to all forms #384

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Contact/src/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public function init(): void
],
'type' => Textarea::class,
]);

$this->add([
'name' => 'contact_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Contact/templates/contact/contact-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
</div>
</div>

{{ formElement(form.get('contact_csrf')) }}

<div class="g-recaptcha" data-sitekey="{{ recaptchaSiteKey }}"
data-callback="submitContactUsForm"
data-size="invisible">
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public function init()
],
]);

$this->add([
'name' => 'login_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/ProfileDeleteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public function init()
]
]);

$this->add([
'name' => 'profile_delete_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/ProfileDetailsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public function init()
'type' => UserDetailFieldset::class
]);

$this->add([
'name' => 'profile_details_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/ProfilePasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public function init()
'type' => Password::class
]);

$this->add([
'name' => 'profile_password_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/RegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public function init()
'type' => Password::class
]);

$this->add([
'name' => 'register_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/RequestResetPasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public function init()
'type' => Email::class
]);

$this->add([
'name' => 'request_reset_password_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/ResetPasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public function init()
'type' => Password::class
]);

$this->add([
'name' => 'reset_password_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
9 changes: 9 additions & 0 deletions src/User/src/Form/UploadAvatarForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public function init()
'type' => AvatarFieldset::class
]);

$this->add([
'name' => 'upload_avatar_csrf',
'type' => 'csrf',
'options' => [
'timeout' => 3600,
'message' => 'The form CSRF has expired and was refreshed. Please resend the form',
],
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/profile/avatar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
{% set dummy = image.setAttribute('data-url', path('account', {'action': 'avatar'})) %}
{{ formElement(image) }}

{{ formElement(form.get('upload_avatar_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/profile/change-password.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
{% set dummy = passwordConfirm.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(passwordConfirm) }}

{{ formElement(form.get('profile_password_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/profile/delete-account.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<p>I accept the <a href="#" target="_blank">Terms and Conditions</a> and I want to delete my account with all additional data.</p>
</div>

{{ formElement(form.get('profile_delete_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/profile/details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
{% set dummy = lastName.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(lastName) }}

{{ formElement(form.get('profile_details_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
3 changes: 3 additions & 0 deletions src/User/templates/user/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
</label>
</div>

{{ formElement(form.get('login_csrf')) }}


{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/user/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
{% set dummy = passwordConfirm.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(passwordConfirm) }}

{{ formElement(form.get('register_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/user/request-reset-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
{% set dummy = identity.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(identity) }}

{{ formElement(form.get('request_reset_password_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down
2 changes: 2 additions & 0 deletions src/User/templates/user/reset-password-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
{% set dummy = passwordConfirm.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(passwordConfirm) }}

{{ formElement(form.get('reset_password_csrf')) }}

{% set submit = form.get('submit') %}
{% set submitValue = submit.getValue|trans|raw %}
{% set dummy = submit.setAttribute('value', submitValue) %}
Expand Down