apache / apache/shenyu

[Task] Decouple JWT signing key from user password hash

Open
#6,398 2 comments 0 reactions 0 assignees View on GitHub
status: volunteer wanted
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### 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_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/JwtUtils.java and DashboardUserServiceImpl.java to trace token generation, verification, and password-hash use. Review application.yml and the configuration reference for the new property, then run the relevant admin authentication tests. Done means tokens use the configured or startup-generated secret, password changes do not invalidate existing tokens, and the property is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authentication, backend, security
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
57/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.