shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[Task] Decouple JWT signing key from user password hash

Open Aias00 opened this issue 5 months ago • 3 comments

Description

DashboardUserServiceImpl currently uses the SHA-512 hash of the user's password as the HMAC-SHA256 signing key for JWT tokens (JwtUtils.generateToken(userName, getPassword(), ...)). This design has two weaknesses:

If the database is compromised, an attacker can use the stored password hash directly as a JWT signing key without needing to crack the original password. Changing a user's password silently invalidates all existing sessions for that user with no explicit revocation mechanism.

Affected Files:

shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/JwtUtils.java shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DashboardUserServiceImpl.java shenyu-admin/src/main/resources/application.yml

Proposed Change:

Introduce a shenyu.jwt.secret-key configuration property in application.yml that holds a randomly generated secret independent of user credentials. Update JwtUtils.generateToken() and JwtUtils.verifyToken() to use this configured secret instead of the password hash. Generate a default random value at startup if the property is not configured, with a warning log recommending explicit configuration.

Acceptance Criteria:

JWT tokens are signed with a configured or randomly generated secret key, not the user's password hash. Changing a user's password does not affect existing JWT validity. shenyu.jwt.secret-key is documented in the configuration reference.

Task List

No response

Aias00 avatar Jun 26 '26 10:06 Aias00

👋 Hello @yuluo-yx

A new issue has been opened by @Aias00:

  • Title: [Task] Decouple JWT signing key from user password hash
  • Link: https://github.com/apache/shenyu/issues/6398

Please review when you have time. Thank you! 🙏

github-actions[bot] avatar Jun 26 '26 10:06 github-actions[bot]

Hi, @Aias00 I've submitted a PR to address it. Could you please review when you have time? Thanks!

hengyuss avatar Jul 05 '26 16:07 hengyuss

Closing as completed. PR #6408 decoupled JWT signing and verification from user password hashes by using shenyu.jwt.secretKey through JwtProperties, with configuration and regression test updates.

Aias00 avatar Oct 01 '26 11:10 Aias00