Skip to content

Fix client secret length to always use HS512 entropy #49793 - #50083

Merged
mposolda merged 1 commit into
keycloak:mainfrom
MdTanwer:fix/49793-client-secret-entropy
Jun 23, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
MdTanwer:fix/49793-client-secret-entropy

Conversation

@MdTanwer

@MdTanwer MdTanwer commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #49793

When regenerating a client secret, Keycloak previously derived secret length only from the Token Endpoint Authentication Signing Algorithm (via PR #39637). Other HMAC-based settings were ignored:

  • ID Token Signature Algorithm
  • UserInfo Response Signature Algorithm
  • Request Object Signature Algorithm
  • Access Token Signature Algorithm
  • Authorization Response / JARM Signature Algorithm

A client using client_secret_basic with ID Token Signature Algorithm = HS512 could receive a ~32-character secret insufficient for HS512.

This change follows Marek's suggestion: always generate secrets at HS512-level entropy (86 alphanumeric characters) on create and regenerate, regardless of authentication type or configured signing algorithms.

Changes

  • KeycloakModelUtils.generateSecret() now uses getRequiredClientSecretLength() (86 chars / ~512 bits)
    - getSecretLengthByAuthenticationType() is kept for backwards compatibility but delegates to the same fixed length
  • Added unit tests in KeycloakModelUtilsTest
  • Updated ClientAuthSecretSignedJWTTest to expect 86-character secrets and added coverage for regenerating with ID Token HS512 configured

@mposolda mposolda self-assigned this Jun 17, 2026
@MdTanwer
MdTanwer force-pushed the fix/49793-client-secret-entropy branch from 46fe396 to 1d24c17 Compare June 18, 2026 04:43
@MdTanwer
MdTanwer marked this pull request as ready for review June 18, 2026 04:55
@MdTanwer
MdTanwer requested a review from a team as a code owner June 18, 2026 04:55
Copilot AI review requested due to automatic review settings June 18, 2026 04:55
@MdTanwer
MdTanwer requested review from a team as code owners June 18, 2026 04:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Keycloak’s client secret generation to always use HS512-level entropy (86 alphanumeric characters), ensuring sufficient strength for any HMAC-based signing configuration (including ID Token, UserInfo, Request Object, Access Token, and JARM), not just token endpoint auth signing.

Changes:

  • Make KeycloakModelUtils.generateSecret() always generate secrets with HS512-equivalent entropy via a new getRequiredClientSecretLength() helper.
  • Keep getSecretLengthByAuthenticationType(...) for compatibility while delegating to the fixed HS512-level length.
  • Update and extend test coverage to expect 86-character secrets, including regeneration for client_secret_basic with ID Token HS512 configured.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
server-spi-private/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java Forces client secret generation to use fixed HS512-level entropy and centralizes length computation in getRequiredClientSecretLength().
server-spi-private/src/test/java/org/keycloak/models/utils/KeycloakModelUtilsTest.java Adds unit tests for the new fixed required secret length and the compatibility behavior of getSecretLengthByAuthenticationType(...).
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oauth/ClientAuthSecretSignedJWTTest.java Updates expectations to HS512-level secret length and adds an integration test covering regeneration for client_secret_basic with ID Token HS512.

@MdTanwer
MdTanwer force-pushed the fix/49793-client-secret-entropy branch from 1d24c17 to 6d2c56a Compare June 20, 2026 03:38
mposolda
mposolda previously approved these changes Jun 23, 2026

@mposolda mposolda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MdTanwer Thanks! I hope PR can be merged if tests are OK

Always generate 86-character secrets on create/regenerate to cover all
HMAC signature use cases regardless of configured algorithms.

Signed-off-by: MdTanwer <tanw9004167@gmail.com>
Copilot AI review requested due to automatic review settings June 23, 2026 08:24
@MdTanwer
MdTanwer force-pushed the fix/49793-client-secret-entropy branch from 6d2c56a to f2f638b Compare June 23, 2026 08:24
@MdTanwer

Copy link
Copy Markdown
Contributor Author

Hey @mposolda there was an formating issue i have fixed that now I thisnk all checkout should pass

@MdTanwer
MdTanwer requested a review from mposolda June 23, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@mposolda mposolda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MdTanwer Thanks!

@mposolda
mposolda merged commit e75c868 into keycloak:main Jun 23, 2026
88 checks passed
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OIDC: Client secret generation should ensure sufficient entropy for all configured HMAC signature algorithms

4 participants