RP-initiated logout is refused for good (invalid_token: sid) once the user's SSO session has been replaced
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
- 43/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- authentication, backend-api-design
Hướng nghiên cứu
Start with OidcLogoutAuthenticationProvider and JwtGenerator in oauth2/oauth2-authorization-server, then trace the logout validation and refresh-token ID token generation described in the issue. Reproduce the flow with an earlier ID token after the user's session is replaced, and check existing logout tests for coverage. Done means logout accepts the same user's earlier sid while still rejecting an ID token whose sub belongs to another user.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When a user's session at the authorization server is replaced by a new one (a new login, or a session restored by remember-me), RP-initiated logout fails for every client that still holds an ID token from the earlier session. /connect/logout answers 400 with invalid_token / OpenID Connect 1.0 Logout Request Parameter: sid instead of redirecting to post_logout_redirect_uri. The client is never told to end its own session, so the user stays signed in there.
A refresh doesn't help, because the refreshed ID token carries the same old sid. That client can't log out any more until it goes through a new authorization code flow.
Two parts of the authorization server combine here:
JwtGenerator, refresh_token grant: copiessidfrom the previous ID token. This was added in spring-projects/spring-authorization-server#1224 (SAS 1.1.1), since a back-channel refresh has no browser session to take asidfrom:String sidClaim = currentIdToken.getClaim("sid"); if (sidClaim != null) { claimsBuilder.claim("sid", sidClaim); }OidcLogoutAuthenticationProvider: when the principal is authenticated and the current session is in theSessionRegistry, it requiressidto equal the hash of that session:String sidClaim = idToken.getClaim("sid"); if (!StringUtils.hasText(sidClaim) || !sidClaim.equals(sessionIdHash)) { throw createException(OAuth2ErrorCodes.INVALID_TOKEN, "sid");
So as soon as the session is replaced, every outstanding ID token carries a sid that can never match again, even though sub is the user who is signed in.
It goes unnoticed in many setups, because the check is skipped when nobody is signed in at logout (an expired session) and when the session isn't in the registry (another replica with the default in-memory SessionRegistry; that may be what spring-projects/spring-authorization-server#1547 saw). It shows reliably with remember-me, or with several clients sharing one SSO session where one of them makes the user sign in again.
To Reproduce
Single instance, default SessionRegistry, a client with openid and a registered post_logout_redirect_uri:
- Sign in as user U (session A), run the authorization code flow, and keep the ID token (
sid= hash(A)). - Replace the session for the same user U: sign in again, or restore through remember-me (session B), and run the authorization code flow again, so that B is in the
SessionRegistry. - In session B, call
GET /connect/logout?id_token_hint=<ID token from step 1>&post_logout_redirect_uri=<registered>.
Actual: 400, invalid_token, parameter sid. Logs show OAuth2 authentication failure: OpenID Connect 1.0 Logout Request Parameter: sid.
Same result with an ID token obtained by refresh in step 1, at any later time.
Expected behavior
The logout succeeds and ends the session the browser has (B), as long as the other checks pass: the ID token is known, aud/client_id match the client, post_logout_redirect_uri is registered, and sub is the signed-in user. An ID token of another user must still be refused, which the sub check already does.
The OIDC RP-Initiated Logout spec doesn't require the sid comparison. When the OP isn't sure the request comes from the signed-in user, it should ask the user whether to log out, not return an error.
Possible fixes
Any of these would do:
- treat a
sidthat doesn't match but belongs to the samesublike a request without a session id, i.e. skip the session comparison; - make the session check pluggable (e.g. a
setSessionValidator, or run theauthenticationValidatorafter the identity checks with the session information in the context); - or at least make
OidcLogoutAuthenticationProvidernon-final.
Today the only way out is to wrap the provider through OidcLogoutEndpointConfigurer.authenticationProviders(...). On a sid failure, which can only be recognised by the error description, the wrapper calls it again with a token that has no session id. setAuthenticationValidator can't help, because it runs before the identity block.
Versions
Reproduced with Spring Authorization Server 1.5.8 (Spring Boot 3.5). The same code is on main of spring-security, in oauth2/oauth2-authorization-server (OidcLogoutAuthenticationProvider, JwtGenerator, both @since 7.0).
Related: spring-projects/spring-authorization-server#1224 (sid missing after refresh, fixed by copying it), spring-projects/spring-authorization-server#1547 (same error with several replicas, closed as invalid), #15509 (client keeps the original ID token after refresh).
- Ngôn ngữ chính
- Java
- Star
- 9.7k
- Fork
- 6.4k
- Merge trung bình
- 3 giờ 11 phút
- Pull request đã merge (30 ngày)
- 19
Chuẩn bị môi trường
- 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 spring-projects/spring-security
-
Update spring-ldap to 4.0.7Đang mởtype: dependency-upgrade
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/100
spring-projects/spring-security#20057 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update micrometer to 1.16.9Đang mởtype: dependency-upgrade
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
spring-projects/spring-security#20056 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update spring-ldap to 4.1.3Đang mởtype: dependency-upgrade
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
spring-projects/spring-security#20055 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update micrometer to 1.17.3Đang mởtype: dependency-upgrade
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
spring-projects/spring-security#20054 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update spring-ldap to 4.2.0Đang mởtype: dependency-upgrade
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
spring-projects/spring-security#20053 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của spring-projects/spring-security
Issue tương tự
-
Mend: dependency security vulnerability untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
opensearch-project/k-NN#3693 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Disk full for windows GH actionĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Encrypted PDF portfolios show an empty portfolio panelCó thể đã có người làm @christophmertins đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Stirling-Tools/Stirling-PDF#8864 · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
CodingDocs/awesome-java#41 · 1 bình luận ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày