Skip to content

Commit 8d3a8e6

Browse files
committed
Ensure possible alg none for RequestObject
1 parent ec42192 commit 8d3a8e6

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/Core/RequestObject.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,39 @@
1212
class RequestObject extends ParsedJws
1313
{
1414
/**
15+
* Get Algorithm. Overridden to allow the 'none' algorithm.
16+
*
17+
* @return ?non-empty-string
1518
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
16-
* @throws \SimpleSAML\OpenID\Exceptions\RequestObjectException
1719
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
1820
*/
19-
public function isProtected(): bool
21+
public function getAlgorithm(): ?string
2022
{
21-
$algHeader = $this->helpers->type()->ensureString(
22-
$this->getHeaderClaim(ClaimsEnum::Alg->value) ?? throw new RequestObjectException(
23-
'Alg header is missing.',
24-
),
23+
$claimKey = ClaimsEnum::Alg->value;
24+
25+
$alg = $this->getHeaderClaim($claimKey);
26+
27+
if (is_null($alg)) {
28+
throw new RequestObjectException('Missing Algorithm header claim.');
29+
}
30+
31+
$alg = $this->helpers->type()->ensureNonEmptyString($alg, $claimKey);
32+
33+
SignatureAlgorithmEnum::tryFrom($alg) ?? throw new RequestObjectException(
34+
'Invalid Algorithm header claim.',
2535
);
2636

27-
return $algHeader !== SignatureAlgorithmEnum::none->value;
37+
return $alg;
38+
}
39+
40+
41+
/**
42+
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
43+
* @throws \SimpleSAML\OpenID\Exceptions\RequestObjectException
44+
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
45+
*/
46+
public function isProtected(): bool
47+
{
48+
return $this->getAlgorithm() !== SignatureAlgorithmEnum::none->value;
2849
}
2950
}

tests/src/Core/RequestObjectTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected function setUp(): void
7070
$this->helpersMock->method('type')->willReturn($typeHelperMock);
7171

7272
$typeHelperMock->method('ensureString')->willReturnArgument(0);
73+
$typeHelperMock->method('ensureNonEmptyString')->willReturnArgument(0);
7374

7475
$this->claimFactoryMock = $this->createMock(ClaimFactory::class);
7576
}

0 commit comments

Comments
 (0)