@@ -142,6 +142,55 @@ public function testLoginWithExistingFrontendSession(): void
142142 $ this ->assertHttpResponseCodeEquals ($ response , 201 );
143143 }
144144
145+ public function testDeletedSessionCookieCannotReauthenticate (): void
146+ {
147+ $ session = $ this ->login ();
148+
149+ // Logged-in server-side session check
150+ $ currentSessionRequest = $ this ->createHttpRequest (
151+ 'GET ' ,
152+ '/api/ibexa/v2/user/sessions/current ' ,
153+ '' ,
154+ 'Session+json ' ,
155+ '' ,
156+ [
157+ 'Cookie ' => sprintf ('%s=%s ' , $ session ->name , $ session ->identifier ),
158+ 'X-CSRF-Token ' => $ session ->csrfToken ,
159+ ]
160+ );
161+ $ currentSessionResponse = $ this ->sendHttpRequest ($ currentSessionRequest );
162+ self ::assertHttpResponseCodeEquals ($ currentSessionResponse , 200 );
163+ $ authenticatedData = json_decode ($ currentSessionResponse ->getBody ()->getContents (), true , 512 , JSON_THROW_ON_ERROR );
164+ $ authenticatedUserHref = $ authenticatedData ['Session ' ]['User ' ]['_href ' ];
165+
166+ // Logout
167+ $ deleteResponse = $ this ->sendHttpRequest ($ this ->createDeleteRequest ($ session ));
168+ self ::assertHttpResponseCodeEquals ($ deleteResponse , 204 );
169+
170+ // Re-use the old cookie — the server-side session must no longer be authenticated as the original user
171+ $ reusedResponse = $ this ->sendHttpRequest (
172+ $ this ->createHttpRequest (
173+ 'GET ' ,
174+ '/api/ibexa/v2/user/sessions/current ' ,
175+ '' ,
176+ 'Session+json ' ,
177+ '' ,
178+ ['Cookie ' => sprintf ('%s=%s ' , $ session ->name , $ session ->identifier )]
179+ )
180+ );
181+
182+ $ reusedData = json_decode ($ reusedResponse ->getBody ()->getContents (), true , 512 , JSON_THROW_ON_ERROR );
183+ self ::assertNotEquals (
184+ $ authenticatedUserHref ,
185+ $ reusedData ['Session ' ]['User ' ]['_href ' ],
186+ 'Old session cookie must not re-authenticate as the original user after logout '
187+ );
188+ self ::assertEquals (
189+ '/api/ibexa/v2/user/users/10 ' ,
190+ $ reusedData ['Session ' ]['User ' ]['_href ' ]
191+ );
192+ }
193+
145194 public function testDeleteSessionExpired (): void
146195 {
147196 $ session = $ this ->login ();
@@ -195,7 +244,7 @@ public function testCheckSession(): void
195244 $ this ->assertHttpResponseCodeEquals ($ response , 200 );
196245
197246 $ contents = $ response ->getBody ()->getContents ();
198- $ data = json_decode ($ contents , true , JSON_THROW_ON_ERROR );
247+ $ data = json_decode ($ contents , true , 512 , JSON_THROW_ON_ERROR );
199248 self ::assertArrayHasKey ('Session ' , $ data );
200249 }
201250
0 commit comments