spring-projects/spring-security · error · OAuth2AuthenticationException

server_error

server_error

Error message

Failed to compute hash for Session ID.

What it means

Thrown by OidcLogoutAuthenticationProvider.authenticate when hashing the session ID for the required sid (session-id) claim comparison fails because no hashing algorithm is available on the platform (NoSuchAlgorithmException). The provider treats this as a server_error because it cannot complete RP-initiated logout validation.

Source

Thrown at oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/authentication/OidcLogoutAuthenticationProvider.java:168

			Assert.notNull(authorizedUserPrincipal, "authorizedUserPrincipal cannot be null");
			if (!StringUtils.hasText(idToken.getSubject())
					|| !currentUserPrincipal.getName().equals(authorizedUserPrincipal.getName())) {
				throw createException(OAuth2ErrorCodes.INVALID_TOKEN, IdTokenClaimNames.SUB);
			}

			// Check for active session
			if (StringUtils.hasText(oidcLogoutAuthentication.getSessionId())) {
				SessionInformation sessionInformation = findSessionInformation(currentUserPrincipal,
						oidcLogoutAuthentication.getSessionId());
				if (sessionInformation != null) {
					String sessionIdHash;
					try {
						sessionIdHash = createHash(sessionInformation.getSessionId());
					}
					catch (NoSuchAlgorithmException ex) {
						OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.SERVER_ERROR,
								"Failed to compute hash for Session ID.", null);
						throw new OAuth2AuthenticationException(error);
					}

					String sidClaim = idToken.getClaim("sid");
					if (!StringUtils.hasText(sidClaim) || !sidClaim.equals(sessionIdHash)) {
						throw createException(OAuth2ErrorCodes.INVALID_TOKEN, "sid");
					}
				}
			}
		}

		if (this.logger.isTraceEnabled()) {
			this.logger.trace("Authenticated logout request");
		}

		return new OidcLogoutAuthenticationToken(idToken, (Authentication) oidcLogoutAuthentication.getPrincipal(),
				oidcLogoutAuthentication.getSessionId(), oidcLogoutAuthentication.getClientId(),
				oidcLogoutAuthentication.getPostLogoutRedirectUri(), oidcLogoutAuthentication.getState());
	}

View on GitHub (pinned to 96852e8860)

Solutions

  1. Verify the JVM exposes the digest algorithm: run MessageDigest.getInstance("SHA-256") in the same environment and check available Security.getProviders()
  2. If a custom hash algorithm was configured for the sid claim, switch to a standard one (SHA-256) available in all JREs
  3. On FIPS JVMs, register/enable a JCE provider (e.g. BouncyCastle FIPS) that supplies the required MessageDigest
  4. Catch the resulting OAuth2AuthenticationException server_error at the filter/filter-chain level and return a 500 with logs for ops diagnosis

Example fix

// before (custom algorithm not present in JVM)
oidcLogoutAuthenticationProvider.setSessionIdHashAlgorithm("SHA3-256");
// after
oidcLogoutAuthenticationProvider.setSessionIdHashAlgorithm("SHA-256");
Defensive patterns

Strategy: try-catch

Validate before calling

try {
    javax.crypto.Mac.getInstance("HmacSHA256");
    java.security.MessageDigest.getInstance("SHA-256");
} catch (java.security.NoSuchAlgorithmException e) {
    throw new IllegalStateException("JVM lacks required digest algorithms", e);
} // run at startup to fail fast

Try / catch

try {
    oidcLogoutFilter.doFilter(request, response, chain);
} catch (OAuth2AuthenticationException e) {
    if (OAuth2ErrorCodes.SERVER_ERROR.equals(e.getError().getErrorCode())) {
        // environment problem: missing MessageDigest, alert ops
        response.sendError(500, "Logout processing failed");
        return;
    }
    response.sendError(401);
}

Prevention

When it happens

Trigger: During an OIDC RP-initiated logout request with an id_token_hint, the provider hashes the current session's ID (createHash, default SHA-256 via MessageDigest) and receives NoSuchAlgorithmException — practically only when the JRE lacks the configured digest algorithm (e.g. hardened/fips JCE policy or non-standard hash algorithm configured).

Common situations: FIPS-restricted JVMs or stripped-down JREs where 'SHA-256' MessageDigest is unavailable; custom OidcLogoutAuthenticationProvider configuration overriding the session-id hash algorithm to a name not registered in the JCE provider list.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-security@96852e8860 (2026-09-10). Data as JSON: /api/errors/e1f97257475c44a6. Report an issue: GitHub.