Skip to content

Commit cab676e

Browse files
committed
feat(revoke-token): encrypt login id token in session db row
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent a0fd296 commit cab676e

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/Db/SessionMapper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
use OCP\DB\QueryBuilder\IQueryBuilder;
1717

1818
use OCP\IDBConnection;
19+
use OCP\Security\ICrypto;
1920

2021
/**
2122
* @extends QBMapper<Session>
2223
*/
2324
class 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);

lib/Listener/TokenInvalidatedListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OCP\EventDispatcher\Event;
2121
use OCP\EventDispatcher\IEventListener;
2222
use OCP\IURLGenerator;
23+
use OCP\Security\ICrypto;
2324
use 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 {

0 commit comments

Comments
 (0)