Skip to content

Commit 7d39715

Browse files
committed
Fix eight small defects queued while writing tests
Each was found while writing the unit tests and pinned there as it behaved; the pins now assert the fixes. - getVciValidCredentialClaimPathsFor() re-indexes after dropping claims which name no path, so it returns a list rather than a map with gaps (a JSON object once encoded). - The federation entity configuration and the back-channel logout token read the clock once, so exp is iat plus the configured duration rather than plus the work done between two readings. - RequestRulesManagerFactory no longer takes a protocol cache it never read. - PreAuthCodeGrant no longer carries a copy of AuthCodeGrant's issueRefreshToken(); nothing in it calls the method. - RefreshTokenIssuer logs the attempt limit it was given when it gives up, rather than 0. - LoggerService and ArrayLogger refuse an unknown log level without a doubled closing quote in the message. - The back-channel logout handler announces each request as "Backchannel Logout", not "Backhannel Logout". - code_challenge and code_verifier are matched with the D modifier, so a value of valid shape followed by one newline is refused: PCRE's $ alone also matches before a final newline, and RFC 7636 allows unreserved characters only. Nothing was bypassed by it, as the challenge is still compared with the verifier's transformation. Assisted-by: Claude Code (claude-opus-5-5, fixes & tests) Assisted-by: OpenAI Codex (gpt-6.1-sol, xhigh review) Assisted-by: Google Antigravity (gemini-4-argon-high, review)
1 parent 0d6d6d1 commit 7d39715

22 files changed

Lines changed: 95 additions & 114 deletions

‎src/Controllers/Federation/EntityStatementController.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public function configuration(): Response
7474
return $this->prepareEntityStatementResponse((string)$cachedEntityConfigurationToken);
7575
}
7676

77-
$currentTimestamp = $this->helpers->dateTime()->getUtc()->getTimestamp();
77+
// Read once, so that the statement lives exactly the configured duration from its iat.
78+
$now = $this->helpers->dateTime()->getUtc();
79+
$currentTimestamp = $now->getTimestamp();
7880

7981
$jwks = $this->jwks->jwksDecoratorFactory()->fromJwkDecorators(
8082
...$this->moduleConfig->getFederationSignatureKeyPairBag()->getAllPublicKeys(),
@@ -86,7 +88,7 @@ public function configuration(): Response
8688
ClaimsEnum::Jti->value => $this->federation->helpers()->random()->string(),
8789
// This is entity configuration (statement about itself).
8890
ClaimsEnum::Sub->value => $this->moduleConfig->getIssuer(),
89-
ClaimsEnum::Exp->value => $this->helpers->dateTime()->getUtc()->add(
91+
ClaimsEnum::Exp->value => $now->add(
9092
$this->moduleConfig->getFederationEntityStatementDuration(),
9193
)->getTimestamp(),
9294
ClaimsEnum::Jwks->value => $jwks,

‎src/Factories/RequestRulesManagerFactory.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
use SimpleSAML\Module\oidc\Utils\FederationCache;
5656
use SimpleSAML\Module\oidc\Utils\FederationParticipationValidator;
5757
use SimpleSAML\Module\oidc\Utils\JwksResolver;
58-
use SimpleSAML\Module\oidc\Utils\ProtocolCache;
5958
use SimpleSAML\Module\oidc\Utils\RequestParamsResolver;
6059
use SimpleSAML\Module\oidc\VerifiableCredentials\ClaimsDescriptionValidator;
6160
use SimpleSAML\OpenID\Core;
@@ -91,7 +90,6 @@ public function __construct(
9190
private readonly ClaimsDescriptionValidator $claimsDescriptionValidator,
9291
private readonly CredentialOfferRepository $credentialOfferRepository,
9392
private readonly ?FederationCache $federationCache = null,
94-
private readonly ?ProtocolCache $protocolCache = null,
9593
) {
9694
}
9795

‎src/ModuleConfig.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,7 +4318,7 @@ public function getVciCredentialConfigurationIdsWithoutScope(): array
43184318

43194319
/**
43204320
* Extract and parse the claims path definition from the credential configuration supported.
4321-
* Returns an array of valid paths for the claims.
4321+
* Returns the valid paths for the claims, as a list.
43224322
*/
43234323
public function getVciValidCredentialClaimPathsFor(string $credentialConfigurationId): array
43244324
{
@@ -4347,7 +4347,7 @@ public function getVciValidCredentialClaimPathsFor(string $credentialConfigurati
43474347
}
43484348
}
43494349

4350-
return array_filter($validPaths);
4350+
return array_values(array_filter($validPaths));
43514351
}
43524352

43534353

‎src/Server/Grants/PreAuthCodeGrant.php‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace SimpleSAML\Module\oidc\Server\Grants;
66

77
use DateInterval;
8-
use League\OAuth2\Server\Entities\AccessTokenEntityInterface as OAuth2AccessTokenEntityInterface;
98
use League\OAuth2\Server\Entities\ClientEntityInterface as OAuth2ClientEntityInterface;
109
use League\OAuth2\Server\Entities\ScopeEntityInterface;
1110
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface as OAuth2AuthCodeRepositoryInterface;
@@ -17,10 +16,8 @@
1716
use Psr\Http\Message\ServerRequestInterface;
1817
use SimpleSAML\Module\oidc\Codebooks\FlowTypeEnum;
1918
use SimpleSAML\Module\oidc\Entities\AuthCodeEntity;
20-
use SimpleSAML\Module\oidc\Entities\Interfaces\AccessTokenEntityInterface;
2119
use SimpleSAML\Module\oidc\Entities\Interfaces\AuthCodeEntityInterface;
2220
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
23-
use SimpleSAML\Module\oidc\Entities\Interfaces\RefreshTokenEntityInterface;
2421
use SimpleSAML\Module\oidc\Entities\UserEntity;
2522
use SimpleSAML\Module\oidc\Factories\Entities\AccessTokenEntityFactory;
2623
use SimpleSAML\Module\oidc\Factories\Entities\AuthCodeEntityFactory;
@@ -560,28 +557,4 @@ public function validateAuthorizationRequestWithRequestRules(
560557
): OAuth2AuthorizationRequestInterface {
561558
throw OidcServerException::serverError('Not implemented');
562559
}
563-
564-
565-
/**
566-
* @param \League\OAuth2\Server\Entities\AccessTokenEntityInterface $accessToken
567-
* @param string|null $authCodeId
568-
* @return \SimpleSAML\Module\oidc\Entities\Interfaces\RefreshTokenEntityInterface|null
569-
* @throws \League\OAuth2\Server\Exception\OAuthServerException
570-
* @throws \League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException
571-
*/
572-
protected function issueRefreshToken(
573-
OAuth2AccessTokenEntityInterface $accessToken,
574-
?string $authCodeId = null,
575-
): ?RefreshTokenEntityInterface {
576-
if (! is_a($accessToken, AccessTokenEntityInterface::class)) {
577-
throw OidcServerException::serverError('Unexpected access token entity type.');
578-
}
579-
580-
return $this->refreshTokenIssuer->issue(
581-
$accessToken,
582-
$this->refreshTokenTTL,
583-
$authCodeId,
584-
self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS,
585-
);
586-
}
587560
}

‎src/Server/LogoutHandlers/BackChannelLogoutHandler.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ protected function logoutRequestsGenerator(array $relyingPartyAssociations): Gen
243243
$index = 0;
244244
foreach ($relyingPartyAssociations as $association) {
245245
if ($association->getBackChannelLogoutUri() !== null) {
246-
$logMessage = "Backhannel Logout (index $index) - preparing request to: " .
246+
$logMessage = "Backchannel Logout (index $index) - preparing request to: " .
247247
($association->getBackChannelLogoutUri() ?? '');
248248
$this->loggerService->notice($logMessage);
249249
$index++;

‎src/Server/RequestRules/Rules/CodeChallengeRule.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function checkRule(
8585

8686
// Validate code_challenge according to RFC-7636
8787
// @see: https://tools.ietf.org/html/rfc7636#section-4.2
88-
if (preg_match('/^[A-Za-z0-9-._~]{43,128}$/', $codeChallenge) !== 1) {
88+
// D: $ matches at the very end only, not before a final newline as well.
89+
if (preg_match('/^[A-Za-z0-9-._~]{43,128}$/D', $codeChallenge) !== 1) {
8990
$loggerService->notice(
9091
'Authorization request rejected: `code_challenge` does not follow RFC-7636 (wrong length or ' .
9192
'character set).',

‎src/Server/RequestRules/Rules/CodeVerifierRule.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function checkRule(
5757

5858
// Validate code_verifier according to RFC-7636
5959
// @see: https://tools.ietf.org/html/rfc7636#section-4.1
60-
if (preg_match('/^[A-Za-z0-9-._~]{43,128}$/', $codeVerifier) !== 1) {
60+
// D: $ matches at the very end only, not before a final newline as well.
61+
if (preg_match('/^[A-Za-z0-9-._~]{43,128}$/D', $codeVerifier) !== 1) {
6162
$loggerService->notice(
6263
'Token request rejected: `code_verifier` does not follow RFC-7636 (wrong length or character set).',
6364
['client_id' => $client->getIdentifier()],

‎src/Server/TokenIssuers/RefreshTokenIssuer.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function issue(
4343
throw OidcServerException::serverError('Unexpected access token entity type.');
4444
}
4545

46-
while ($maxGenerationAttempts-- > 0) {
46+
$attemptsLeft = $maxGenerationAttempts;
47+
48+
while ($attemptsLeft-- > 0) {
4749
try {
4850
$refreshToken = $this->refreshTokenEntityFactory->fromData(
4951
$this->helpers->random()->getIdentifier(),
@@ -54,7 +56,7 @@ public function issue(
5456
$this->refreshTokenRepository->persistNewRefreshToken($refreshToken);
5557
return $refreshToken;
5658
} catch (UniqueTokenIdentifierConstraintViolationException $e) {
57-
if ($maxGenerationAttempts === 0) {
59+
if ($attemptsLeft === 0) {
5860
$this->logger->error('Maximum generation attempts reached.', [
5961
'maxGenerationAttempts' => $maxGenerationAttempts,
6062
'accessTokenId' => $accessToken->getIdentifier(),

‎src/Services/LoggerService.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function log(mixed $level, string|Stringable $message, array $context = [
9191
LogLevel::INFO => $this->info($message, $context),
9292
LogLevel::NOTICE => $this->notice($message, $context),
9393
LogLevel::WARNING => $this->warning($message, $context),
94-
default => throw new InvalidArgumentException("Unrecognized log level '$level''"),
94+
default => throw new InvalidArgumentException("Unrecognized log level '$level'"),
9595
};
9696
}
9797

‎src/Services/LogoutTokenBuilder.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ public function forRelyingPartyAssociation(RelyingPartyAssociationInterface $rel
4848
);
4949
}
5050

51-
$currentTimestamp = $this->core->helpers()->dateTime()->getUtc()->getTimestamp();
51+
// Read once, so that the token lives exactly the configured duration from its iat.
52+
$now = $this->core->helpers()->dateTime()->getUtc();
53+
$currentTimestamp = $now->getTimestamp();
5254

5355
$payload = array_filter([
5456
ClaimsEnum::Iss->value => $this->moduleConfig->getIssuer(),
5557
ClaimsEnum::Iat->value => $currentTimestamp,
56-
ClaimsEnum::Exp->value => $this->core->helpers()->dateTime()->getUtc()->add(
58+
ClaimsEnum::Exp->value => $now->add(
5759
$this->moduleConfig->getAuthCodeDuration(),
5860
)->getTimestamp(),
5961
ClaimsEnum::Jti->value => $this->core->helpers()->random()->string(),

0 commit comments

Comments
 (0)