Skip to content

[Bug]: Remember-me login on a superseded session id replaces the regenerated session (password-protected share returns 401, IP gets brute-force blocked) #66874

Open

Description

@easygoings3841

⚠️ This issue respects the following points: ⚠️

  • This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug (if unsure, ask the Community Help Forum).
  • This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
  • I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (Supported major versions and current patch levels).
  • I agree to follow Nextcloud's Code of Conduct.
  • I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.

Bug description

When a user who is logged in with "Remember me" (the default on the login page) opens a password-protected public link share in the same browser and enters the correct password, the share's WebDAV requests (/public.php/dav/files/<token>/) start failing with 401 right after the password is accepted. Each 401 is counted twice by PublicAuth for the public_dav_auth brute-force action, so after a few retries the IP is blocked for 30 minutes (Reached maximum delay). Other people behind the same IP are blocked as well.

It does not happen in a private window or when not logged in.

This looks like a gap in #65928 (stale requests on a superseded session id). That fix withholds the session cookie during the 60-second grace period, but a stale request that carries remember-me cookies logs the user in again and gets a new session cookie anyway.

Observed sequence (debug log, production, NC 35)

19:34:11  POST /s/<token>/authenticate/showshare  -> 303
          (AuthPublicShareController::authenticate() calls regenerateId(true, true))
19:34:12  GET /index.php/apps/files/preview-service-worker.js   (arrives with the OLD session id)
            core: Request uses a session id that was replaced at <timestamp>
            core: Remember-me token replaced
19:34:13    core: Session token replaced
19:34:13  PROPFIND /public.php/dav/files/<token>/   -> NotAuthenticated (401), Bruteforce attempt ... "public_dav_auth"
19:34:13  GET /public.php/dav/files/<token>/        -> 401 (repeated), IP throttled

The new session cookie issued by the stale service-worker request replaces the browser's cookie, so the session that holds the share authentication (public_link_authenticated_frontend) is lost.

Where it happens in the code

  1. Internal::leaveSupersededSession() moves the stale request to a fresh, empty session and sets $cookieAllowed = false inside the grace period (as intended by fix(session): Prevent stale requests from replacing a regenerated session #65928).
  2. The fresh session has no user, but nc_username / nc_token / nc_session_id are present, so the request logs in again via OC\User\Session::loginWithCookie().
  3. loginWithCookie() calls $this->session->regenerateId(), and Internal::regenerateId() sets $this->cookieAllowed = true. A new session cookie (and a rotated nc_token) is sent, which overrides the newer session that the browser already holds.

So during the grace period, a request on a superseded id can still replace the browser's session if it carries remember-me cookies.

Actual behavior: the stale request logs in via remember-me, regenerates the session id and sends a new cookie. The share authentication is lost, the share's WebDAV requests return 401, and the client IP is blocked by brute-force protection.

Steps to reproduce

  1. Log in with "Remember me" checked (default).
  2. In the same browser, open a password-protected link share of a video and enter the password.
  3. Have any request reach the server with the previous (pre-password) session id within a few seconds after the password POST. In our production setup with Firefox this was the Files app's preview-service-worker.js fetch, which happened every time. (Service worker registration fails there because of CSP, so the script seems to be fetched on every page load; we have not confirmed this.)
  4. The share's PROPFIND/GET requests return 401 and the IP gets throttled.

Deterministic reproduction on a 35.0.3 dev instance (nextcloud-docker-dev, Firefox and Chromium via Playwright): right after the password POST, send a request to /index.php/apps/files/preview-service-worker.js with the old session cookie and the remember-me cookies. The response sets a new session cookie, and after that the share page asks for the password again and PROPFIND returns 401. Without remember-me cookies, the same stale request gets no cookie and the share keeps working, which matches the intent of #65928.

Expected behavior

A request that arrives on a superseded session id during the grace period should not replace the browser's newer session. For example, the remember-me login could be skipped for superseded ids, or the cookie could stay withheld for the rest of that request.

Nextcloud Server version

35

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.3

Web server

Nginx

Database engine version

MariaDB

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?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

List of activated Apps

Nextcloud Signing status

Nextcloud Logs

Additional info

Server configuration

  • Caching: APCu (local), Redis (distributed, locking)
  • PHP sessions: files handler
  • Browsers: Firefox 160.0.1 (production); Firefox 157 / Chromium (Playwright, dev)
  • lib/private/Session/Internal.php is unchanged on current stable35 and master compared to 35.0.3.

Workaround

We stopped the trigger in nginx by not passing cookies for the service-worker script and dropping its Set-Cookie. The script is a #[PublicPage] static file, so it does not need the session:

location = /index.php/apps/files/preview-service-worker.js {
    # same fastcgi settings as the generic \.php location, plus:
    fastcgi_param HTTP_COOKIE "";
    fastcgi_hide_header Set-Cookie;
}

This only covers this one request. Any other request that arrives on the superseded id with remember-me cookies would still trigger the problem.

Related

Activity

  1. added
    0. Needs triage
    on Nov 20, 2026
  2. haddung commented on Nov 21, 2026

    @haddung

    Confirming on 35.0.3 (Docker nextcloud:latest, Apache, PHP 8.5, behind Nginx Proxy Manager), Firefox 160 on Windows, logged in with "Remember me". Same sequence in the access log:

    23:04:10  POST /s/<token>/authenticate/showshare            303
    23:04:11  GET  /index.php/apps/files/preview-service-worker.js  200  6988 bytes  (all other fetches of this file: 6473 bytes)
    23:04:18  PROPFIND /public.php/dav/files/<token>/             401
    

    The larger response right after the password POST is consistent with the extra Set-Cookie headers from the remember-me re-login described here. The same link works in a private window.

  3. Voltra commented on Nov 24, 2026

    @Voltra

    Confirming on 35.0.3 in a private browser window. Same error as before

  4. pkoevesdi commented on Nov 30, 2026

    @pkoevesdi

    Same on 35.0.3 with Apache 2.4 + PHP-FPM 8.4, Firefox 161 on Linux. Access log with the first characters of the session cookie:

    16:20:27.486 POST     /s/<token>/authenticate/showshare                303  sess=e750…  Set-Cookie: session=140f…, nc_session_id=140f…
    16:20:28.400 GET      /index.php/apps/files/preview-service-worker.js  200  sess=e750…  Set-Cookie: session=cd10…, nc_token=<new>, nc_session_id=cd10…
    16:20:29.775 GET      /s/<token>                                       200  sess=140f…
    16:20:31.464 PROPFIND /public.php/dav/files/<token>/                   401  sess=cd10…
    

    Two additions:

    1. Both requests renew the same session token, so every occurrence leaves two rows in oc_authtoken, created within a second of each other. The one for the session the browser dropped (140f…) stays valid.
    2. Apache equivalent of the nginx workaround (needs mod_headers):
    <Location "/index.php/apps/files/preview-service-worker.js">
        RequestHeader unset Cookie
        Header unset Set-Cookie
        Header always unset Set-Cookie
    </Location>

    Assisted by ClaudeCode:claude-fable-5-2

  5. Voltra commented on Nov 30, 2026

    @Voltra

    Huh, so it could be a "forced" session regeneration causing the issue. As in:

    Has no session -> requests page -> gets session from auth -> requests js worker -> no checks, regenerates a fresh session -> mismatch

  6. easygoings3841 commented on Dec 1, 2026

    @easygoings3841
    Author

    I tested it on a local 35.0.3 instance with Chrome: logged out, the 401 did not reproduce in any of 10 attempts; logged in with "Remember me", it returned 401 every time (3/3).

    So I think the cookie is not being overwritten by the service worker script fetch itself, but by the automatic re-login via the remember-me cookies on that request (loginWithCookie() → regenerateId()).

  7. Voltra commented on Dec 1, 2026

    @Voltra

    Most likely not that as I get the 401 in private Firefox windows while logged out

  8. susnux commented on Dec 3, 2026

    @susnux
    Contributor

    Thanks, the analysis matches the code on master: Internal::leaveSupersededSession() withholds the cookie during the grace period, but User\Session::loginWithCookie() calls regenerateId(), which re-enables it unconditionally – so a stale request carrying remember-me cookies still sends a new session cookie and rotates nc_token. The open PR #66416 doesn't change this path. A 401 in a logged-out private window can't come from this path (no remember-me cookies involved); if that still happens, please open a separate issue with the request sequence.

  9. added
    1. to develop
    and removed
    0. Needs triage
    on Dec 3, 2026
  10. moved this from To triage to Confirmed in 🧑‍🤝‍🧑 Server Community triageon Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    1. to develop35-feedbackbug

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions