[java-oidc-common] branch main updated: JCOMOIDC-196 - AuthenticationTimeClaimsValidator validates auth_time with millisecond precision

Codeberg noreply at shibboleth.net
Thu Nov 26 11:10:30 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
https://codeberg.org/Shibboleth/java-oidc-common/commit/f0c10adc6fb73f213a5855ccdba025cb05ce5eb1

The following commit(s) were added to refs/heads/main by this push:
     new f0c10adc JCOMOIDC-196 - AuthenticationTimeClaimsValidator validates auth_time with millisecond precision
f0c10adc is described below

commit f0c10adc6fb73f213a5855ccdba025cb05ce5eb1
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Nov 26 11:10:21 2026 +0000

    JCOMOIDC-196 - AuthenticationTimeClaimsValidator validates auth_time
    with millisecond precision
    
      - changed to comparing the max_age=0 path with second precision.
    
    https://shibboleth.atlassian.net/browse/JCOMOIDC-196
---
 .../impl/AuthenticationTimeClaimsValidator.java    | 18 ++++++++------
 .../AuthenticationTimeClaimsValidatorTest.java     | 29 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidator.java b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidator.java
index 0c75fa3c..3e98ff95 100644
--- a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidator.java
+++ b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidator.java
@@ -178,22 +178,24 @@ public class AuthenticationTimeClaimsValidator extends AbstractClaimsValidator {
                     throw new JWTValidationException("No authentication lifetime set");
                 }
                 
-                if (authnLifetime.equals(Duration.ofSeconds(0))) {
+                if (authnLifetime.equals(Duration.ZERO)) {
                     // Now assume forced authentication semantics, the authentication must have happened after the 
                     // authentication request was made to the OP
                     final Instant authnRequestTime = authnRequestTimeLookupStrategy.apply(context);
                     
                     if (authnRequestTime == null) {
-                        log.warn("Maximum authentication age of 0 seconds requested, but no "
-                                + "authentication request time could be found, can not check for a fresh "
-                                + "authentication");
-                        throw new JWTValidationException("Maximum authentication age of 0 seconds requested, but no "
-                                + "authentication request time could be found, can not check for a fresh "
-                                + "authentication");
+                        log.warn("""
+							Maximum authentication age of 0 seconds requested, but no \
+							authentication request time could be found, can not check for a fresh \
+							authentication""");
+                        throw new JWTValidationException("""
+							Maximum authentication age of 0 seconds requested, but no \
+							authentication request time could be found, can not check for a fresh \
+							authentication""");
                     }
                     
                     // Check authTime is after the time which the authentication request was made
-                    if (authTimeDate.toInstant().isBefore(authnRequestTime)) {
+                    if (authTimeDate.toInstant().getEpochSecond() < authnRequestTime.getEpochSecond()) {
                         log.warn("JWT token authentication time is not valid. Authentication is not fresh but max_age=0"
                                 + " was requested, re-authentication did not occur");
                         throw new JWTValidationException("JWT token authentication time is not valid. Authentication "
diff --git a/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidatorTest.java b/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidatorTest.java
index 19fd1e55..ca9014ee 100644
--- a/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidatorTest.java
+++ b/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jwt/claims/impl/AuthenticationTimeClaimsValidatorTest.java
@@ -164,6 +164,35 @@ public class AuthenticationTimeClaimsValidatorTest extends AbstractClaimsValidat
         validator.initialize();
         validator.validate(claimsSet, prc);
     }
+    
+    /*
+     * Check we are comparing seconds for when the request was made to the auth_time in the response.
+     * The auth_time in the response has seconds precision, so we can only compare on seconds. For example,
+     * the following situation could fail if we are not comparing on seconds:
+     * 
+     * <ul>
+     * <li>(R) Request made: 12:00:00.5</li>
+     * <li>(UA) User authenticated: 12:00:00.7</li>
+     * <li>(AT) auth_time recorded at 12:00:00.0</li>
+     * <li>With a fine precision check, the auth_time (AT) is before the request time (R) even though the user
+     * authenticated after the request was made. Assuming only a second precision, they will be equal and the 
+     * authentication accepted.</li>
+     * </ul>
+     */
+    @Test
+    public void doAcceptForceAuthenticationRequestWithinTheSecond() 
+            throws JWTValidationException, ComponentInitializationException {
+    	final Instant now = Instant.now();
+        final JWTClaimsSet claimsSet = new JWTClaimsSet.Builder().claim(
+                IDTokenClaims.AUTHENTICATION_TIME.getClaimName(), 
+                now.plusMillis(100).getEpochSecond()).build();
+        validator.setId("test-validator");   
+        // returning 0 seconds 'signals' forced authentication
+        validator.setAuthnLifetime(Duration.ofSeconds(0));
+        validator.setAuthnRequestTimeLookupStrategy(prc -> now);
+        validator.initialize();
+        validator.validate(claimsSet, prc);
+    }
 
     
     @Test

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list