➜ Old React website
Chung Cheuk Hang MichaelJava Web Developer
Java Spring Boot/Cloud HTTP clientsSpring Security 漏洞 CVE-2023-20860

Spring Security 漏洞 CVE-2023-34034

Continued from previous post:
Spring Security 漏洞 CVE-2023-20860

Table of contents

1 CVE-2023-34034 背景

繼上一篇既 關於 Spring Security 漏洞 CVE-2023-20860 之後,Snyk 又再公佈左一個同佢相關既 Spring 安全漏洞,叫做 SNYK-JAVA-ORGSPRINGFRAMEWORKSECURITY-5777893,對應 CVE 資料庫既 CVE-2023-34034
同上次漏洞唔同既係所涉及既 library。

1.1 涉及既 library 版本

呢個漏洞係同 org.springframework.security:spring-security-config 有關。有問題既版本包括 [5.6.0,5.6.12) [5.7.0,5.7.10) [5.8.0,5.8.5) [6.0.0,6.0.5) [6.1.0,6.1.2),亦即係:
  • 5.6.05.6.11
  • 5.7.05.7.9
  • 5.8.05.8.4
  • 6.0.06.0.4
  • 6.1.06.1.1
已修復既版本包括:
  • 5.6.12 或以上
  • 5.7.10 或以上
  • 5.8.5 或以上
  • 6.0.5 或以上
  • 6.1.2 或以上
註:6.x 係用於 Spring Boot 3.x

1.2 漏洞涉及既安全問題

根據 CVE 既描述,當喺 Spring Webflux 項目使用 pattern matching 配置 Spring Security 既時候用左 un-prefixed double wildcard pattern(**),Spring 背後所產生既實際 Spring Webflux 配置會同我地既 Spring Security 有出入,最終有可能導致個 Spring app 允許未經授權既訪問。

2 建立測試項目

2.1 Maven dependencies

  • Maven parent POM:spring-boot-starter-parent
  • Dependencies
    • spring-boot-starter-webflux
    • spring-boot-starter-security

2.2 HTTP APIs

Request methodRequest path測試結果期望
GET/public呢個 endpoint 唔應該需要登入驗證。
GET/secure呢個 endpoint 應該需要登入驗證。

2.3 寫 Java code

2.3.1 Controller

BusinessController.java
1@RestController 2public class BusinessController { 3 4 @GetMapping("public") 5 public String _public() { 6 return "This is a public endpoint. You should see this without logging in."; 7 } 8 9 @GetMapping("secure") 10 public String secure() { 11 return "This is a secure endpoint. You should NOT see this without logging in."; 12 } 13}

2.3.2 Spring Security config class

SecurityConfiguration.java
1@Configuration 2public class SecurityConfiguration { 3 4 @Bean 5 public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) throws Exception { 6 return http 7 .authorizeExchange().pathMatchers("/public").permitAll() 8 .and() 9 .authorizeExchange().pathMatchers("/**").authenticated() 10 .and() 11 .httpBasic() 12 .and() 13 .build(); 14 } 15}
另一個寫法:
1@Configuration 2public class SecurityConfiguration { 3 4 @Bean 5 public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) throws Exception { 6 return http 7 .authorizeExchange() 8 .pathMatchers("/public").permitAll() 9 .pathMatchers("/**").authenticated() 10 .and() 11 .httpBasic() 12 .and() 13 .build(); 14 } 15}
再另一個寫法:
1@Configuration 2public class SecurityConfiguration { 3 4 @Bean 5 public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) throws Exception { 6 return http 7 .authorizeExchange(request -> request 8 .pathMatchers("/public").permitAll() 9 .pathMatchers("/**").authenticated()) 10 .httpBasic() 11 .and() 12 .build(); 13 } 14}

3 測試結果

3.1 使用有漏洞既版本

以下係有漏洞既版本:
  • spring-boot-starter-security 2.7.1
    • Spring Security 5.7.2

3.1.1 測試結果:Permit 特定 endpoints、authenticate wildcard

  1. pathMatchers(<some paths>).permitAll()
  2. pathMatchers(<wildcard>).authenticated()
Implementation解釋結果
Permit public、authenticate **兩者都冇 / 開頭/public 需要登入,過分安全。
Permit /public、authenticate /**兩者都有 / 開頭✅ 符合測試結果期望。
Permit public、authenticate /**其中一個有 / 開頭/public 需要登入,過分安全。
Permit /public、authenticate **其中一個有 / 開頭✅ 符合測試結果期望。
Permit public、authenticate *兩者都冇 / 開頭,單 * 字元/public 需要登入,過分安全。
Permit /public、authenticate /*兩者都有 / 開頭,單 * 字元✅ 符合測試結果期望。
Permit public、authenticate /*其中一個有 / 開頭,單 * 字元/public 需要登入,過分安全。
Permit /public、authenticate *其中一個有 / 開頭,單 * 字元✅ 符合測試結果期望。

3.1.2 測試結果:Authenticate 特定 endpoints、permit wildcard

  1. pathMatchers(<some paths>).authenticated()
  2. pathMatchers(<wildcard>).permitAll()
Implementation解釋結果
Authenticate secure、permit **兩者都冇 / 開頭/public 需要登入,過分安全。
Authenticate /secure、permit /**兩者都有 / 開頭✅ 符合測試結果期望。
Authenticate secure、permit /**其中一個有 / 開頭/secure 唔需要登入,存在漏洞。
Authenticate /secure、permit **其中一個有 / 開頭/public 需要登入,過分安全。
Authenticate secure、permit *兩者都冇 / 開頭,單 * 字元/public 需要登入,過分安全。
Authenticate /secure、permit /*兩者都有 / 開頭,單 * 字元✅ 符合測試結果期望。
Authenticate secure、permit /*其中一個有 / 開頭,單 * 字元/secure 唔需要登入,存在漏洞。
Authenticate /secure、permit *其中一個有 / 開頭,單 * 字元/public 需要登入,過分安全。

3.2 使用已修復既版本

要修復今次既漏洞,唔可以淨係覆蓋單一 library 既版本,否則會 start up 唔到個 web app。
BOM 既 Maven 配置名新版本BOM 所管理既 libraries
spring-framework.version5.3.29spring-corespring-contextspring-beansspring-expressionspring-aopspring-jclspring-webspring-webfluxspring-webmvc
spring-security.version5.7.10spring-security-corespring-security-webspring-security-configspring-security-crypto
reactor-bom.version(只有 Spring Webflux 項目需要)2020.0.34rector-corereactor-netty-corereactor-netty-http

3.2.1 測試結果:Permit 特定 endpoints、authenticate wildcard

  1. pathMatchers(<some paths>).permitAll()
  2. pathMatchers(<wildcard>).authenticated()
ImplementationTest case結果
Permit public、authenticate **兩者都冇 / 開頭✅ 符合測試結果期望。
Permit /public、authenticate /**兩者都有 / 開頭✅ 符合測試結果期望。
Permit public、authenticate /**其中一個有 / 開頭✅ 符合測試結果期望。
Permit /public、authenticate **其中一個有 / 開頭✅ 符合測試結果期望。
Permit public、authenticate *兩者都冇 / 開頭,單 * 字元✅ 符合測試結果期望。
Permit /public、authenticate /*兩者都有 / 開頭,單 * 字元✅ 符合測試結果期望。
Permit public、authenticate /*其中一個有 / 開頭,單 * 字元✅ 符合測試結果期望。
Permit /public、authenticate *其中一個有 / 開頭,單 * 字元✅ 符合測試結果期望。

3.2.2 測試結果:Authenticate 特定 endpoints、permit wildcard

  1. pathMatchers(<some paths>).authenticated()
  2. pathMatchers(<wildcard>).permitAll()
ImplementationTest case結果
Authenticate secure、permit **兩者都冇 / 開頭✅ 符合測試結果期望。
Authenticate /secure、permit /**兩者都有 / 開頭✅ 符合測試結果期望。
Authenticate secure、permit /**其中一個有 / 開頭✅ 符合測試結果期望。
Authenticate /secure、permit **其中一個有 / 開頭✅ 符合測試結果期望。
Authenticate secure、permit *兩者都冇 / 開頭,單 * 字元✅ 符合測試結果期望。
Authenticate /secure、permit /*兩者都有 / 開頭,單 * 字元✅ 符合測試結果期望。
Authenticate secure、permit /*其中一個有 / 開頭,單 * 字元✅ 符合測試結果期望。
Authenticate /secure、permit *其中一個有 / 開頭,單 * 字元✅ 符合測試結果期望。

4 參考資料