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

Added csrf tokens to all forms #683

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/ZfcUser/Form/ChangeEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public function __construct($name, AuthenticationOptionsInterface $options)
),
));

$this->add([
'type' => '\Zend\Form\Element\Csrf',
'name' => 'security',
'options' => [
'csrf_options' => [
'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout()
]
]
]);

$this->add(array(
'name' => 'submit',
'attributes' => array(
Expand Down
10 changes: 10 additions & 0 deletions src/ZfcUser/Form/ChangePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function __construct($name, AuthenticationOptionsInterface $options)
),
));

$this->add([
'type' => '\Zend\Form\Element\Csrf',
'name' => 'security',
'options' => [
'csrf_options' => [
'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout()
]
]
]);

$this->add(array(
'name' => 'submit',
'attributes' => array(
Expand Down
10 changes: 10 additions & 0 deletions src/ZfcUser/Form/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public function __construct($name, AuthenticationOptionsInterface $options)
//$csrf->getValidator()->setTimeout($options->getLoginFormTimeout());
//$this->add($csrf);

$this->add([
'type' => '\Zend\Form\Element\Csrf',
'name' => 'security',
'options' => [
'csrf_options' => [
'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout()
]
]
]);

$submitElement = new Element\Button('submit');
$submitElement
->setLabel('Sign In')
Expand Down
10 changes: 10 additions & 0 deletions src/ZfcUser/Form/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public function __construct($name, RegistrationOptionsInterface $options)

parent::__construct($name);

$this->add([
'type' => '\Zend\Form\Element\Csrf',
'name' => 'security',
'options' => [
'csrf_options' => [
'timeout' => $this->getRegistrationOptions()->getUserFormTimeout()
]
]
]);

if ($this->getRegistrationOptions()->getUseRegistrationFormCaptcha()) {
$this->add(array(
'name' => 'captcha',
Expand Down
1 change: 1 addition & 0 deletions tests/ZfcUserTest/Form/ChangeEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testConstruct()
$this->assertArrayHasKey('newIdentity', $elements);
$this->assertArrayHasKey('newIdentityVerify', $elements);
$this->assertArrayHasKey('credential', $elements);
$this->assertArrayHasKey('security', $elements);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/ZfcUserTest/Form/ChangePasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testConstruct()
$this->assertArrayHasKey('credential', $elements);
$this->assertArrayHasKey('newCredential', $elements);
$this->assertArrayHasKey('newCredentialVerify', $elements);
$this->assertArrayHasKey('security', $elements);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/ZfcUserTest/Form/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function testConstruct($authIdentityFields = array())

$this->assertArrayHasKey('identity', $elements);
$this->assertArrayHasKey('credential', $elements);
$this->assertArrayHasKey('security', $elements);


$expectedLabel="";
if (count($authIdentityFields) > 0) {
Expand Down
2 changes: 2 additions & 0 deletions tests/ZfcUserTest/Form/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function testConstruct($useCaptcha = false)
$this->assertArrayHasKey('email', $elements);
$this->assertArrayHasKey('password', $elements);
$this->assertArrayHasKey('passwordVerify', $elements);
$this->assertArrayHasKey('security', $elements);

}

public function providerTestConstruct()
Expand Down