-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Bug]: Same Site Cookies Not Set if First Request has Cookies (412 Precondition Failed) #41210
Open
4 of 8 tasks
Labels
Comments
KaseyJenkins
added
0. Needs triage
Pending check for reproducibility or if it fits our roadmap
bug
labels
Oct 31, 2023
Does
fixes the probleme here? Line 560 in 565dc36
|
Hi @solracsf! If that's a preferred solution should I create a PR or will somebody else be assigned this task? Thanks! |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
pointhi
added a commit
to pointhi/nextcloud-server
that referenced
this issue
Mar 29, 2024
…h breaks passesCSRFCheck()
pointhi
added a commit
to pointhi/nextcloud-server
that referenced
this issue
Mar 29, 2024
Signed-off-by: Thomas Pointhuber <thomas.pointhuber@gmx.at>
4 tasks
pointhi
added a commit
to pointhi/nextcloud-server
that referenced
this issue
Apr 1, 2024
Signed-off-by: Thomas Pointhuber <thomas.pointhuber@gmx.at>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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
The text was updated successfully, but these errors were encountered: