File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616use OCP \DB \QueryBuilder \IQueryBuilder ;
1717
1818use OCP \IDBConnection ;
19+ use OCP \Security \ICrypto ;
1920
2021/**
2122 * @extends QBMapper<Session>
2223 */
2324class SessionMapper extends QBMapper {
24- public function __construct (IDBConnection $ db ) {
25+ public function __construct (
26+ IDBConnection $ db ,
27+ private ICrypto $ crypto ,
28+ ) {
2529 parent ::__construct ($ db , 'user_oidc_sessions ' , Session::class);
2630 }
2731
@@ -154,7 +158,7 @@ public function createSession(
154158 $ session ->setAuthtokenId ($ authtokenId );
155159 $ session ->setNcSessionId ($ ncSessionid );
156160 $ session ->setCreatedAt ($ createdAt );
157- $ session ->setIdToken ($ idToken );
161+ $ session ->setIdToken ($ this -> crypto -> encrypt ( $ idToken) );
158162 $ session ->setUserId ($ userId );
159163 $ session ->setProviderId ($ providerId );
160164 $ session ->setIdpSessionClosed ($ idpSessionClosed ? 1 : 0 );
Original file line number Diff line number Diff line change 2020use OCP \EventDispatcher \Event ;
2121use OCP \EventDispatcher \IEventListener ;
2222use OCP \IURLGenerator ;
23+ use OCP \Security \ICrypto ;
2324use Psr \Log \LoggerInterface ;
2425
2526/**
@@ -34,6 +35,7 @@ public function __construct(
3435 private DiscoveryService $ discoveryService ,
3536 private IURLGenerator $ urlGenerator ,
3637 private HttpClientHelper $ httpClientHelper ,
38+ private ICrypto $ crypto ,
3739 ) {
3840 }
3941
@@ -98,9 +100,15 @@ public function handle(Event $event): void {
98100 return ;
99101 }
100102
103+ try {
104+ $ decryptedIdToken = $ this ->crypto ->decrypt ($ oidcSession ->getIdToken ());
105+ } catch (\Exception $ e ) {
106+ $ this ->logger ->warning ('[TokenInvalidatedListener] Could not decrpyt the login id token of a session related with an invalidated token ' , ['exception ' => $ e ]);
107+ return ;
108+ }
101109 $ endSessionEndpoint .= '?post_logout_redirect_uri= ' . $ this ->urlGenerator ->getAbsoluteURL ('/ ' );
102110 $ endSessionEndpoint .= '&client_id= ' . $ provider ->getClientId ();
103- $ endSessionEndpoint .= '&id_token_hint= ' . $ oidcSession -> getIdToken () ;
111+ $ endSessionEndpoint .= '&id_token_hint= ' . $ decryptedIdToken ;
104112
105113 $ this ->logger ->warning ('[TokenInvalidatedListener] requesting ' . $ endSessionEndpoint );
106114 try {
You can’t perform that action at this time.
0 commit comments