Skip to content

Commit 180c89c

Browse files
committed
chore: update jjwt to 12.3 to address org.json library's CVE-2023-5072 vulnerability. spring-boot 3.1.4
1 parent a624be4 commit 180c89c

File tree

4 files changed

+22
-41
lines changed

4 files changed

+22
-41
lines changed

contributed/requests/address.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Content-Type: application/json
3030
{
3131
"username": "john.doe",
3232
"password": "test1234",
33-
"verificationCode": "479346"
33+
"verificationCode": "650364"
3434
}
3535

3636
> {%

pom.xml

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.1.0</version>
8+
<version>3.1.4</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111

1212
<groupId>osahner</groupId>
1313
<artifactId>kotlin-spring-boot-rest-jpa-jwt-starter</artifactId>
14-
<version>0.10.0-SNAPSHOT</version>
14+
<version>0.10.1-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<name>kotlin spring-boot 2 rest/jpa/jwt starter</name>
@@ -22,15 +22,15 @@
2222
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2323

2424
<java.version>17</java.version>
25-
<kotlin.version>1.8.21</kotlin.version>
25+
<kotlin.version>1.9.10</kotlin.version>
2626

2727
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
2828

29-
<jjwt.version>0.11.5</jjwt.version>
30-
<poi.version>5.2.3</poi.version>
29+
<jjwt.version>0.12.3</jjwt.version>
30+
<poi.version>5.2.4</poi.version>
3131
<jasypt.version>1.9.3</jasypt.version>
32-
<opencsv.version>5.7.1</opencsv.version>
33-
<commons-io.version>2.11.0</commons-io.version>
32+
<opencsv.version>5.8</opencsv.version>
33+
<commons-io.version>2.14.0</commons-io.version>
3434
<aerogear-otp-java.version>1.0.0</aerogear-otp-java.version>
3535
</properties>
3636

@@ -277,26 +277,4 @@
277277
</plugins>
278278
</build>
279279

280-
<repositories>
281-
<repository>
282-
<id>spring-milestones</id>
283-
<name>Spring Milestones</name>
284-
<url>https://repo.spring.io/milestone</url>
285-
<snapshots>
286-
<enabled>false</enabled>
287-
</snapshots>
288-
</repository>
289-
</repositories>
290-
291-
<pluginRepositories>
292-
<pluginRepository>
293-
<id>spring-milestones</id>
294-
<name>Spring Milestones</name>
295-
<url>https://repo.spring.io/milestone</url>
296-
<snapshots>
297-
<enabled>false</enabled>
298-
</snapshots>
299-
</pluginRepository>
300-
</pluginRepositories>
301-
302280
</project>

src/main/kotlin/osahner/security/JWTAuthorizationFilter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class JWTAuthorizationFilter(
2828
chain.doFilter(req, res)
2929
return
3030
}
31-
tokenProvider.getAuthentication(header)?.also { authentication ->
31+
tokenProvider.getAuthentication(header)?.let { authentication ->
3232
SecurityContextHolder.getContext().authentication = authentication
3333
}
3434
chain.doFilter(req, res)

src/main/kotlin/osahner/security/TokenProvider.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package osahner.security
22

33
import io.jsonwebtoken.Jwts
4-
import io.jsonwebtoken.SignatureAlgorithm
54
import io.jsonwebtoken.security.Keys
65
import jakarta.annotation.PostConstruct
76
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
@@ -11,15 +10,16 @@ import org.springframework.stereotype.Component
1110
import osahner.add
1211
import osahner.config.SecurityProperties
1312
import osahner.service.AppUserDetailsService
14-
import java.security.Key
1513
import java.util.*
14+
import javax.crypto.SecretKey
15+
1616

1717
@Component
1818
class TokenProvider(
1919
private val securityProperties: SecurityProperties,
2020
private val userDetailsService: AppUserDetailsService,
2121
) {
22-
private var key: Key? = null
22+
private var key: SecretKey? = null
2323
private var tokenValidity: Date? = null
2424

2525
@PostConstruct
@@ -35,20 +35,23 @@ class TokenProvider(
3535
}
3636

3737
return Jwts.builder()
38-
.setSubject(authentication.name)
38+
.subject(authentication.name)
3939
.claim("auth", authClaims)
40-
.setExpiration(tokenValidity)
41-
.signWith(key, SignatureAlgorithm.HS512)
40+
.expiration(tokenValidity)
41+
.signWith(key)
4242
.compact()
4343
}
4444

4545
fun getAuthentication(token: String): Authentication? {
46+
// val jwk = Jwks.parser().build().parse(securityProperties.secret)
47+
4648
return try {
47-
val claims = Jwts.parserBuilder()
48-
.setSigningKey(key)
49+
val claims = Jwts.parser()
50+
.verifyWith(key)
51+
.clockSkewSeconds(3 * 60)
4952
.build()
50-
.parseClaimsJws(token.replace(securityProperties.tokenPrefix, ""))
51-
val userDetail = userDetailsService.loadUserByUsername(claims.body.subject)
53+
.parseSignedClaims(token.replace(securityProperties.tokenPrefix, ""))
54+
val userDetail = userDetailsService.loadUserByUsername(claims.payload.subject)
5255
val principal = User(userDetail.username, "", userDetail.authorities)
5356
UsernamePasswordAuthenticationToken(principal, token, userDetail.authorities)
5457
} catch (e: Exception) {

0 commit comments

Comments
 (0)