Spring Boot 關閉 Actuator ,滿足安全工具掃描

應用被安全工具,掃描出漏洞信息

【MSS】SpringBoot Actuator敏感接口未授權訪問漏洞(Actuator)事件發現通告:
發現時間:2023-11-25 19:47:17
攻擊時間:2023-11-25 18:56:44
事件/告警類型:非授權訪問/權限繞過
告警設備:APT
攻擊IP:xxx
被攻擊IP/資產信息:xxx
告警描述:SpringBoot Actuator敏感接口未授權訪問漏洞(Actuator) http://xxx/actuator/
優先級:三級(一般)
處置建議:關閉或限制Actuator端口的訪問權限,或升級Spring Boot版本修復漏洞。

解決方案

方法1. 修改配置

management:
  server:
    port: -1  # 修改端口,跳過安全漏洞掃描
  endpoints:
    enabled-by-default: false #關閉監控
    web:
      exposure:
        include: '*' 

image
image

方法2. 添加訪問權限

通過配置 Spring Security 來限制對 Actuator 端點的訪問,只爲了這一個需求,添加 Spring Security 感覺有些重

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/actuator/**").hasRole("ADMIN") // 設置只有具有 ADMIN 角色的用戶可以訪問 Actuator 端點
                .anyRequest().permitAll()
            .and()
            .httpBasic(); // 啓用基本認證
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章