-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix EZP-26179: REST session refresh must throw a 404 if session has expired #1769
Conversation
d619cf8
to
1888fcd
Compare
Some questions:
:) |
it seems to work :)
As far as I can tell, that's not strictly needed to fix the original issue but IMHO, it would make sense to have the same behavior when deleting the session through REST. |
@@ -136,7 +136,8 @@ protected function isMethodSafe($method) | |||
*/ | |||
protected function isLoginRequest($route) |
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.
now it does more than just checking if we try to login the user
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.
Deprecated in favour of isSessionRoute($route)
in addition to the previous comments, it would also be nice to complete https://github.com/ezsystems/ezpublish-kernel/blob/master/doc/specifications/rest/REST-API-V2.rst#refresh-session-get-sessions-user-information (and potentially the DELETE part as well) to precise that the session cookie is also deleted in error cases. |
19cb458
to
f00ed9d
Compare
Changed to use the same behaviour (ignored in
Yes. I've decided to take a shortcut and return a response here. |
But now I'm thinking that the csrf check in refresh and delete session are a bit wrong: the actual value of the csrf token won't be checked, since we only use the TokenStorage to check if there is a token. I guess that we should first check if there is a token, and if there isn't, throw a 404. Then if we have a token, check that the token that was provided as input is correct. |
Added csrf-token value check in both refresh and delete session. Also reorganized the code a little bit. |
*/ | ||
protected function isLoginRequest($route) | ||
{ | ||
return $route === 'ezpublish_rest_createSession'; | ||
return $route === 'ezpublish_rest_createSession' || | ||
$route === 'ezpublish_rest_refreshSession'; |
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.
given it is deprecated and not used this change should be removed I guess.
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.
Good point :-)
Updated Will consider fixing the case where a session exists without a csrf token fixed (reported in JIRA), preventing from logging into PlatformUI if a frontend session was previously created. |
1fdd788
to
72494a4
Compare
Did you think about how we can do that? Otherwise PR looks good :) |
b20337e
to
d0f758b
Compare
@andrerom : see d0f758b :) Do we need to fix it in 1.3 ? |
d0f758b
to
9206e22
Compare
We should be good for review, everything's in. |
@@ -490,7 +490,7 @@ public function testUnassignRoleFromUser($roleAssignmentHref) | |||
* | |||
* @return string role assignment href | |||
*/ | |||
public function testAssignRoleToUserGroup($roleHref) | |||
public function _testAssignRoleToUserGroup($roleHref) |
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.
temp change?
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 need to rephrase that a bit. This particular test breaks roles in the database, and prevents further tests from working.
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.
Marked the test as skipped with the reason.
Besides comment, +1
Not a must, stay with current target. |
9206e22
to
6e6e432
Compare
@pcardiga : this is ready for QA. There are several fixes / changes in there. They must be tested on 1.4.x. A new version will be issued for master: EZP-25038If a session was started from the frontend (just use EZP-26179This is the main issue fixed by this PR. It changes the behaviour of both refresh and delete session. From a REST perspective, if either is used while a session has expired, they will now throw a 404, and delete the session cookie, instead of a 401 because of a missing csrf token. From the UI, without this patch, if the session expires while on PlatformUI, it will be impossible to login again to the UI without deleting the session cookie. This can be tested together with ezsystems/platform-ui-bundle#668 on PlatformUI. Set sessions to expire quickly ( |
@bdunogier: |
6e6e432
to
4065815
Compare
I was not able to reproduce the issue EZP-25038 only using the The issue EZP-26179 was tested using the ezsystems/platform-ui-bundle#668 as well and everything was ok. The only issue I had was not being able to make the garbage collector work after 10s, so I manually deleted the sessions. Doing this the response status return was a 404 instead of 401 and the PlatformUI redirected to the login. These issues were tested on 1.4.x |
Odd, this is how I trigger this case in the REST functional tests. |
…n has expired According to the specifications, /api/ezp/v2/user/sessions/<id>/refresh must throw a 404 if the session doesn't exist / has expired. Because of the CSRF token check in the CsrfListener, a 401 is thrown because the csrf token verification fails, as the session has expired, and we don't have a stored token anymore. This changes the CsrfListener to skip this route, and explicitly checks in the refresh controller action if the token has expired.
4065815
to
01865fa
Compare
The error is a 1.4 related one. Composer didn't install the tested branch, but 5.4.2-rc1. This means that platform wasn't set to basic auth, and tests try to run with basic auth, hence the failure on everything that requires permissions other than anonymous. Tested locally, with a 1.4 install frm scratch and the PR's branch, and it works as expected. |
Change needed after ezsystems/ezpublish-kernel#1769 Conflicts: .travis.yml
According to the specifications,
/api/ezp/v2/user/sessions/<id>/refresh
must throw a 404 if the session doesn't exist / has expired.Because of the CSRF token check in the CsrfListener, a 401 is thrown because the csrf token verification fails, as the session has expired, and we don't have a stored token anymore.
This changes the CsrfListener to skip this route, and explicitly checks in the refresh controller action if the token has expired using the Csrf TokenStorage.