Removed laminas-eventmanager dependency, refactored validators#168
Removed laminas-eventmanager dependency, refactored validators#168gsteel merged 6 commits intolaminas:3.0.xfrom
Conversation
|
@laminas/tsc-reviewers |
If this component defines its own interface for validators, then this should also be used by validators in this component. This not only reduces dependencies, but also confusion. |
The problem here is naming. It's entirely aceptable to have 2 different types of validator:
Renaming the session validator interface from I'd support a rename of the interface/namespace as I find it unlikely that many users implement custom validators outside of those already shipped, and, the BC breaks are already very significant in this portion of the library. The fact that the CSRF validator is in the same namespace is really unfortunate. Extracting it to a separate library (and removing the |
@gsteel Should I maybe remove this feature altogether then? I'm not sure that form CSRF validation should be in the |
I agree, but I'd gather some more opinions first. Who's going to make sure that there is a CSRF implementation available to users of Laminas Session for example. Is it even necessary based on the current fate of MVC? Mezzio already has an equivalent that doesn't use laminas-validator. cc @laminas/technical-steering-committee |
I think the main use is in the CSRF element of laminas-form. |
Ideally, Maybe On the other hand, why not just use mezzio-csrf 🤷♂️ |
|
@Jurj-Bogdan Perhaps it would be a good idea to bring this up as a topic for the next TSC meet. 1 - Is the CSRF validator and Form element relevant any more? Can they both be deprecated and removed? For the purposes of this patch, why don't we:
|
The current usage of CSRF token generation and validation via laminas-form is easy: $form->add([
'type' => Laminas\Form\Element\Csrf::class,
'name' => 'example',
]);Nothing else needs to be done. So this is very user-friendly. |
Well, yes and no. Currently When For people using Should we be dogmatic about soft dependencies? I prefer to be, mainly because it places clear constraints on installable versions - with soft deps, we could end up with session:2 being installed with form:4 (This wouldn't happen because of validator:2 constraints, but, the point remains) |
|
@gsteel |
|
While a decision is taken for the
session_manager.validators This might be better of reorganised, such as |
|
In a separate patch, we should delete anything to do with laminas-form or laminas-validator 👍 |
can you open an issue ? to remember later |
gsteel
left a comment
There was a problem hiding this comment.
Sorry @Jurj-Bogdan! More nit-picks :)
…rom events Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
…s-strings Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
4df2c90 to
f4acb7f
Compare
gsteel
left a comment
There was a problem hiding this comment.
Just a few tweaks to
- Reduce baseline additions
- Make factories internal to reduce the BC surface
Otherwise 👍
Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
Signed-off-by: Jurj-Bogdan <jurj@dotkernel.com>
gsteel
left a comment
There was a problem hiding this comment.
Phew! Thanks @Jurj-Bogdan LGTM!
@froschdesign Anything to add?
Ocramius
left a comment
There was a problem hiding this comment.
From my PoV, this is a good/stateless design: I provided a lot of feedback on things to improve though, sorry :D
| 'classes' => [ | ||
| Session\Validator\RemoteAddr::class, | ||
| Session\Validator\HttpUserAgent::class, | ||
| ], | ||
| 'options' => [ | ||
| 'remote_addr' => [ | ||
| 'use_proxy' => false, | ||
| 'trusted_proxies' => [], | ||
| ], | ||
| ] |
There was a problem hiding this comment.
This type is in the docs, but I don't directly see it reflected in any @psalm-type or array shape in this patch?
| * last, however, does not, due to the differences in implementations, and | ||
| * the fact that save handlers will often be written in userland. As such | ||
| * The first two have corresponding factories inside this namespace. | ||
| * "SaveHandlerInterface", however, does not, due to the differences in implementations, |
There was a problem hiding this comment.
Instead of a quoted string, use {@see ...}?
| /** @var list<class-string<ValidatorInterface>> $validators */ | ||
| $validators = $validatorsConfig['classes']; |
There was a problem hiding this comment.
This type is the one I flagged in the docs: kinda missing anywhere?
| /** @psalm-var list<class-string<ValidatorInterface>> $uniqueValidators */ | ||
| $uniqueValidators = array_unique($validators); |
There was a problem hiding this comment.
Do we even care about uniqueness? What's the disadvantage if more than one is instantiated on accident?
|
|
||
| if ($sessionId === null) { | ||
| return false; | ||
| throw new SessionValidationFailedException('Session id validation failed'); |
There was a problem hiding this comment.
We should explain what failed (missing session ID)
| { | ||
| return self::class; | ||
| if (! (bool) preg_match($pattern, $sessionId)) { | ||
| throw new SessionValidationFailedException('Session id validation failed'); |
There was a problem hiding this comment.
We should explain what failed (missing pattern mismatch - the ID and pattern should probably be part of the exception)
| { | ||
| return self::class; | ||
| if ($initial->getUserAgent() !== $current->getUserAgent()) { | ||
| throw new SessionValidationFailedException('Http user agent validation failed'); |
There was a problem hiding this comment.
The mismatching values should be part of the exception
| } | ||
|
|
||
| if ($this->initialData !== $this->currentData) { | ||
| throw new SessionValidationFailedException('Remote address validation failed'); |
There was a problem hiding this comment.
We should add the before/after values to the exception
| /** @throws SessionValidationFailedException */ | ||
| public function validate(EnvironmentInterface $initial, EnvironmentInterface $current): void; |
There was a problem hiding this comment.
This is obviously a major breaking change, but a welcome one 👍
Description
Based on #167.
I agree with @gsteel 's suggestion of dropping the "event" flow for session validation, and since the dependency was not used in other places, I have removed
laminas/laminas-eventmanager. To go in a bit more detail:ValidatorChainclass that was using it has been removed.ValidatorChainhas also been completely removed.Laminas\Session\ValidatorInterfaceand all validators using it to suit the new validation flow.While mentioned in the initial issue, I haven't touched the
Csrfvalidator and its dependencylaminas/laminas-validatorhere, as that's probably better suited for a new PR - right now this validator already cannot be used in the same way as the other validators implementing the ownValidatorInterface( neither in v3 nor v2 ).