Open KaseyJenkins opened 1 year ago
Does
if (count($_COOKIE) > 0 && (isset($_COOKIE['nc_sameSiteCookielax']) || isset($_COOKIE['nc_sameSiteCookiestrict']))) {
fixes the probleme here?
https://github.com/nextcloud/server/blob/565dc36226d08d071c30d8ad4fd54126dfa4be79/lib/base.php#L560
Hi @solracsf! Yes, that seems to have done the trick :)
If that's a preferred solution should I create a PR or will somebody else be assigned this task?
Thanks!
@nickvergessen do you have an opinion here?
@solracsf @nickvergessen is there any update on this issue?
This is not my area of expertise
⚠️ This issue respects the following points: ⚠️
Bug description
In base.php:performSameSiteCookieProtection()
The way the code seems to work at the moment:
First request:
nc_sameSiteCookielax
andnc_sameSiteCookiestrict
are set (along withoc_sessionPassphrase
andoc<10-character id>
) base.php:584Second and subsequent requests:
The $_COOKIE superglobal has some cookies set, hence we check whether
$request->passesStrictCookieCheck()
base.php:571; Request.php:532We check whether
cookieCheckRequired()
- it is required, since a cookie with the session_name is present (oc<10-character id>
) Request.php:489We detect the presence of
nc_sameSiteCookiestrict
andnc_sameSiteCookiestrict
set during the first request.We successfully pass
$request->passesStrictCookieCheck()
base.php:571.The above works when the assumption that the first request should come in without any cookies set is correct. When some cookie is already present during the first request (e.g. an Apache module may choose to set it for various reasons) we seem to encounter a small issue:
First request:
The $_COOKIE superglobal is checked for cookies set. base.php:560
There are some cookies set, hence we immediately start checking whether
$request->passesStrictCookieCheck()
base.php:571; Request.php:532.We check whether
cookieCheckRequired()
- it is not required, since there's no cookie with the session_name as of yet (oc<10-character id>
) Request.php:489.We successfully pass
$request->passesStrictCookieCheck()
base.php:571, however,nc_sameSiteCookielax
andnc_sameSiteCookiestrict
haven't been set, onlyoc_sessionPassphrase
andoc<10-character id>
.Second request:
The $_COOKIE superglobal is checked for cookies set. base.php:560
There are some cookies set (
oc_sessionPassphrase
andoc<10-character id>
along with the external cookie(s) we didn't set that came in the first request), hence we check whether$request->passesStrictCookieCheck()
base.php:571; Request.php:532We check whether
cookieCheckRequired()
- it is indeed required, since a cookie with the session_name is present (oc<10-character id>
) Request.php:489.We do not detect the presence of
nc_sameSiteCookiestrict
andnc_sameSiteCookiestrict
(they were not set during the first request).The
$request->passesStrictCookieCheck()
fails base.php:571.There's a warning 'Request does not pass strict cookie check' and, if the debug mode is off, we bail out with 412 (
Http::STATUS_PRECONDITION_FAILED
) and a 'Strict Cookie has not been found in request' json error.We
set nc_sameSiteCookielax
andnc_sameSiteCookiestrict
cookies here.Third and consequent requests: Since all the necessary cookies are present (
nc_sameSiteCookielax
,nc_sameSiteCookiestrict
,oc_sessionPassphrase
, andoc<10-character id>
) everything finally works as expected (akin to the second request in the first scenario).Steps to reproduce
This could be seen running the following:
Simulating the first request without any cookies set:
Simulating the first request with an 'external' cookie already present:
You could also simulate first and second requests with the following php scripts respectively: The first one contains an unexpected cookie during the first request.
The second has all the cookies set but
nc_sameSiteCookielax
,nc_sameSiteCookiestrict
, which results in 412.Expected behavior
One would expect no 'unexpected' error (412) in case the very first request comes with some preset cookies.
Installation method
None
Nextcloud Server version
25
Operating system
None
PHP engine version
None
Web server
None
Database engine version
None
Is this bug present after an update or on a fresh install?
None
Are you using the Nextcloud Server Encryption module?
None
What user-backends are you using?
Configuration report
No response
List of activated Apps
No response
Nextcloud Signing status
No response
Nextcloud Logs
No response
Additional info
No response