Skip to content

Commit ff6175f

Browse files
authored
Merge pull request #1272 from nextcloud/enh/noid/allow-disabling-jwk-strength-check
Allow disabling JWK strength validation
2 parents 8462499 + 1f24d27 commit ff6175f

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ is not set in the discovery. In such case, you can set the default token endpoin
7070
]
7171
```
7272

73+
## `user_oidc.validate_jwk_strength`
74+
75+
By default, user_oidc validates the strength of the JWK keys received from the discovery endpoint.
76+
It will check that RSA keys are long enough and that EC/OKP keys have the correct curve.
77+
This can be disabled with:
78+
79+
```php
80+
'user_oidc' => [
81+
'validate_jwk_strength' => false
82+
]
83+
```
7384

7485
---
7586

lib/Service/DiscoveryService.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\UserOIDC\Vendor\Firebase\JWT\JWT;
1616
use OCP\ICache;
1717
use OCP\ICacheFactory;
18+
use OCP\IConfig;
1819
use Psr\Log\LoggerInterface;
1920

2021
class DiscoveryService {
@@ -42,6 +43,7 @@ public function __construct(
4243
private LoggerInterface $logger,
4344
private HttpClientHelper $clientService,
4445
private ProviderService $providerService,
46+
private IConfig $config,
4547
ICacheFactory $cacheFactory,
4648
) {
4749
$this->cache = $cacheFactory->createDistributed('user_oidc');
@@ -208,8 +210,12 @@ private function fixJwksAlg(array $jwks, string $jwt): array {
208210
continue;
209211
}
210212

211-
// Validate key strength
212-
$this->validateKeyStrength($key, $alg);
213+
$oidcSystemConfig = $this->config->getSystemValue('user_oidc', []);
214+
if (!isset($oidcSystemConfig['validate_jwk_strength'])
215+
|| !in_array($oidcSystemConfig['validate_jwk_strength'], [false, 'false', 0, '0'], true)) {
216+
// Validate key strength
217+
$this->validateKeyStrength($key, $alg);
218+
}
213219

214220
// If JWT has a kid, match strictly
215221
if ($kid !== null) {

tests/unit/Service/DiscoveryServiceTest.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,35 @@
1212
use OCA\UserOIDC\Service\DiscoveryService;
1313
use OCA\UserOIDC\Service\ProviderService;
1414
use OCP\ICacheFactory;
15+
use OCP\IConfig;
1516
use PHPUnit\Framework\Assert;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
1819
use Psr\Log\LoggerInterface;
1920

2021
class DiscoveryServiceTest extends TestCase {
2122

22-
/**
23-
* @var MockObject|LoggerInterface
24-
*/
23+
/** @var MockObject|LoggerInterface */
2524
private $logger;
26-
/**
27-
* @var HttpClientHelper|MockObject
28-
*/
25+
/** @var HttpClientHelper|MockObject */
2926
private $clientHelper;
30-
/**
31-
* @var ProviderService|MockObject
32-
*/
27+
/** @var ProviderService|MockObject */
3328
private $providerService;
34-
/**
35-
* @var ICacheFactory|MockObject
36-
*/
29+
/** @var IConfig|MockObject */
30+
private $config;
31+
/** @var ICacheFactory|MockObject */
3732
private $cacheFactory;
38-
/**
39-
* @var DiscoveryService
40-
*/
33+
/** @var DiscoveryService */
4134
private $discoveryService;
4235

4336
public function setUp(): void {
4437
parent::setUp();
4538
$this->logger = $this->createMock(LoggerInterface::class);
4639
$this->clientHelper = $this->createMock(HttpClientHelper::class);
4740
$this->providerService = $this->createMock(ProviderService::class);
41+
$this->config = $this->createMock(IConfig::class);
4842
$this->cacheFactory = $this->createMock(ICacheFactory::class);
49-
$this->discoveryService = new DiscoveryService($this->logger, $this->clientHelper, $this->providerService, $this->cacheFactory);
43+
$this->discoveryService = new DiscoveryService($this->logger, $this->clientHelper, $this->providerService, $this->config, $this->cacheFactory);
5044
}
5145

5246
public function testBuildAuthorizationUrl() {

0 commit comments

Comments
 (0)