[Bug]: Remember-me login on a superseded session id replaces the regenerated session (password-protected share returns 401, IP gets brute-force blocked)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- php
- Lĩnh vực
- authentication, backend
Hướng nghiên cứu
Start with lib/private/Session/Internal.php, especially leaveSupersededSession() and regenerateId(), then trace the remember-me login path through OC\User\Session::loginWithCookie(). Reproduce the stale-session request described in the issue with remember-me cookies and check whether it sends a replacement session cookie. Done means that request cannot replace the newer session, and the password-protected share's WebDAV requests remain authenticated.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
⚠️ 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
Internal::leaveSupersededSession()moves the stale request to a fresh, empty session and sets$cookieAllowed = falseinside the grace period (as intended by #65928).- The fresh session has no user, but
nc_username/nc_token/nc_session_idare present, so the request logs in again viaOC\User\Session::loginWithCookie(). loginWithCookie()calls$this->session->regenerateId(), andInternal::regenerateId()sets$this->cookieAllowed = true. A new session cookie (and a rotatednc_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
- Log in with "Remember me" checked (default).
- In the same browser, open a password-protected link share of a video and enter the password.
- 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.jsfetch, 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.) - 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:
fileshandler - Browsers: Firefox 160.0.1 (production); Firefox 157 / Chromium (Playwright, dev)
lib/private/Session/Internal.phpis 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
- #65928 (stale requests replacing a regenerated session), backported to stable35 in #66295
- #64659 (similar symptom, different cause; closed via #66178)
- Ngôn ngữ chính
- PHP
- Star
- 37.6k
- Fork
- 5.4k
- Merge trung bình
- 1 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 623
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nextcloud/server
-
[Bug]: Axios Update NeededĐang mở0. Needs triage 35-feedback bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
34-feedback
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: GET /js/../<anything> returns 500 (NotPermittedException from JsController::getJs) instead of 404Có thể đã có người làm @lazerg đã nhận 7 ngày trước. Đang mở35-feedback
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Dashboard widgets registered via OCA.Dashboard.register() sometimes never mount (spinner forever) – Vue 3 non-deep `callbacks` watcher raceCó thể đã có người làm @lazerg đã nhận 7 ngày trước. Đang mở35-feedback
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của nextcloud/server
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sonata-project/SonataAdminBundle#8426 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
erkamyaman/rust-anything#942 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CPU core labels missing for Low-Power E-cores on hybrid Intel CPUs (Arrow Lake-H) — get_intel_core_types() ignores /sys/devices/cpu_lowpowerCó thể đã có người làm @dgongut đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày