-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: Security class sends cookies immediately #5429
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
fix: Security class sends cookies immediately #5429
Conversation
0b04489 to
b8f4bf3
Compare
|
This adds a new dependency (Cookie on Security), which is fine but it must be defined in depfile.yaml. |
|
Does this need to handle the |
paulbalandan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the previous dependency addition warning, I think the SecurityException should not be inside the CookieStore class. IMO, CookieStore should be clean from outside dependencies and just dispatch the cookies in its collection. No outside interference.
The addition of setCookieStore() method in Response looks good to me. Reading on the related issue, my suggestion would be:
- On sending the CSRF cookie,
Securitygets the saved instance of theCookieStorefrom theResponsethen save to it the CSRF cookie. Securitystill retains the secure checks on the cookie.Securityputs the newCookieStoreinstance to theResponseusing$response->setCookieStore($cookieStore);Response, after saving the new cookie store instance, invokessendCookies()via thesend()method. This calls$cookieStore->dispatch()CookieStorewill send all the cookies in its store, including the CSRF cookie.
What do you mean? |
|
I think it is weird that Your opinion is just moving the secure checks on the cookie back to |
I thought that. But it seems I could go. |
|
It looks like @paulbalandan has a better grasp on this so I will not review. Thanks for the work though, I assume this fixes the test case issues. |
paulbalandan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at how other frameworks send cookies. Particularly, for CakePHP, they send cookies using the ResponseEmitter class so I think this is good. In the future, or future versions, I think we can also modularize class responsibilities.
9aceb2c to
3526672
Compare
|
I rebased for just signing commits. |
|
I will add the documentation. |
| /** @var Response $response */ | ||
| $response = Services::response(); | ||
| $response->setCookie($this->cookie); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any point of storing response service in a variable?
| /** @var Response $response */ | |
| $response = Services::response(); | |
| $response->setCookie($this->cookie); | |
| Services::response()->setCookie($this->cookie); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To explicitly indicate dependency.
This is also to avoid disabling the deptrac check.
You may like the short code, but it hides the dependency Response.
deptrac can't detect it.
Services::response()->setCookie($this->cookie);Add Response::setCookieStore()
To explicitly indicate dependency
3526672 to
49cd879
Compare
|
I added the documentation. |
|
💪 |
Description
Fixes #5406
SecuritytoResponseTraitSecurityclass does not send cookie, just set it toResponseCookieStoreclass does not send cookies,Responsesends cookiesResponse::setCookie()can getCookieobject nowChecklist: