Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@Slf4j
public class JwtTokenProvider {

private static final String INSECURE_DEFAULT_SECRET =
"your-256-bit-secret-key-here-change-in-production";

@Value("${security.jwt.secret}")
private String jwtSecret;

Expand All @@ -35,6 +38,14 @@ public class JwtTokenProvider {

@PostConstruct
public void init() {
if (jwtSecret == null || jwtSecret.isBlank()) {
throw new IllegalStateException(
"JWT secret must be configured via the JWT_SECRET environment variable.");
}
if (INSECURE_DEFAULT_SECRET.equals(jwtSecret)) {
throw new IllegalStateException(
"JWT secret is using the insecure default value. Set JWT_SECRET to a secure random key.");
}
this.key = Keys.hmacShaKeyFor(jwtSecret.getBytes(StandardCharsets.UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions RestroHub/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ api.license.url=https://www.apache.org/licenses/LICENSE-2.0
# ===============================
# Security / JWT
# ===============================
# Set JWT_SECRET in production; startup fails if the insecure default is used.
security.jwt.secret=${JWT_SECRET:your-256-bit-secret-key-here-change-in-production}
security.jwt.expiration=${JWT_EXPIRATION:86400000}
security.jwt.refresh-expiration=${JWT_REFRESH_EXPIRATION:604800000}
Expand Down