-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Allow override of CSRF name #170
Conversation
Signed-off-by: Villermen <[email protected]>
Signed-off-by: Villermen <[email protected]>
Weird that in the first commit, with the test but without the fix, 2 build passed the tests 🤔 WDYT may have happened? |
@villermen I agree that the current implementation has the "issue" (might as well be a feature for some) that the token is unique for all forms where the element is named identically. Usually I name the element <?php
declare(strict_types=1);
namespace Application\Utility\Form;
use Laminas\Form\Element\Csrf;
use Laminas\Session\Container;
class Form extends \Laminas\Form\Form
{
public function addCsrfElement($timeout = 600): void
{
$parts = explode('\\', static::class);
$name = 'csrf' . $parts[0] . (count($parts) > 1 ? $parts[array_key_last($parts)] : '');
$session = 'CsrfToken_' . $parts[0] . (count($parts) > 1 ? '_' . $parts[array_key_last($parts)] : '');
$this->add([
'type' => Csrf::class,
'name' => 'csrf',
'options' => [
'csrf_options' => [
'name' => $name,
'session' => new Container($session),
'timeout' => $timeout,
],
],
]);
}
} However, looking at your changes I see that my option |
@froschdesign It just feels very wrong to me that specifying the CSRF validator's options via If the name is discarded as a feature I'd prefer it if the option were removed/not parsed altogether so it can not give the impression of improved security where there is none. |
Yeah, if I remember correctly, I found the |
@Slamdunk |
Go for it 💪 |
@villermen |
Allows the
csrf_options.name
option passed to aCsrf
element to override the element's own name for the validator, instead of discarding the option entirely.Fixes #169.
¹ Technically yes for people who had the name CSRF option specified before (previously a no-op).