Skip to content

fix(dav): drop the session of a cookieless bearer request - #1635

Draft
ximalin wants to merge 2 commits into
nextcloud:mainfrom
ximalin:pr2-trim
Draft

ximalin wants to merge 2 commits into
nextcloud:mainfrom
ximalin:pr2-trim

Conversation

@ximalin

@ximalin ximalin commented Nov 19, 2026

Copy link
Copy Markdown

Stacked on #1634, which is included here as the first commit. Only the second commit belongs to this PR.

After #1634 a cookieless DAV bearer request no longer creates an oc_authtoken row, but OC::initSession() still starts a PHP session and session_write_close() leaves its record behind: one session per request.

When the request did not send the session cookie, shutdown now removes the record of this request only. A cookie that came with the request is left alone, so a browser login is not affected.

Observed on Nextcloud 35.0.2 with 200 cookieless PROPFIND requests (concurrency 20):

save handler session records before after
files +200 0
redis (tcp, auth, db 2, prefix) +200 0
redis (unix socket) 0 0
memcached 0 0

Also checked: a user-land SessionHandlerInterface, session.use_strict_mode on and off, a mixed browser login and cookieless load (200 and 412), aborted connections.

Not tested: redis cluster and sentinel, packet-level TCP RST, abort and RST on php-fpm, memcached with strict mode and a browser session.

A cookieless OIDC bearer request to /remote.php/dav was treated as an
apache session, so loginWithApache() wrote an oc_authtoken row and a
login_token preference on every request.

DAV bearer requests now skip that path and are authenticated by a Sabre
backend registered on SabrePluginAuthInitEvent. Restoring a file from
the trash still sees the uid, published for the current request only.
It is not written to the PHP session, and getCurrentUserId() does not
call setUser(). See nextcloud#1376, nextcloud#1452 and nextcloud#1486.

OCS and /remote.php/webdav are unchanged.

Refs nextcloud#1584
Signed-off-by: xima lin <lin@rackunit.ru>
OC::initSession() starts a PHP session and session_write_close() leaves
the record behind, so a cookieless DAV bearer request still created one
session per call after the authtoken row was stopped.

When the request did not send the session cookie, shutdown removes the
record of this request only. The files handler is unlinked. Redis and
memcached records are deleted through their storage backends, including
unix sockets. A user-land SessionHandlerInterface is cleared with
session_destroy() after session.use_cookies is turned off while headers
are still unsent, only for that handler. Built-in handlers are not
reconfigured. A cookie that arrived with the request is left alone,
including a browser login. Set-Cookie is not stripped.

Follow-up to nextcloud#1634.
Refs nextcloud#1584
Signed-off-by: xima lin <lin@rackunit.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant