1、SpringBoot Actuator
1.1 简介
SpringBoot Actuator 是 Spring Boot 项目中的一个模块,提供了一组用于监控和管理应用程序的端点。这些端点可以用来检索应用程序的运行状态、查看统计数据、配置信息等。此外,还可以使用 Actuator 执行一些安全操作,如关闭应用程序。
以下是常用端点:
| Http | 路径 | 描述 |
|---|---|---|
| get | /autoconfig | 自动配置报告 |
| get | /configprops | 配置属性注入 Bean 情况 |
| get | /beans | 应用程序上下文里全部的 Bean 及关系 |
| get | /dump | 线程活动的快照 |
| get | /env | 获取全部环境属性 |
| get | /health | 健康指标 |
| get | /info | 获取应用程序的定制信息 |
| get | /mappings | URI 路径及控制器映射关系 |
| get | /metrics | 度量信息,如内存用量和 HTTP 请求计数 |
| post | /shutdown | 关闭应用程序 |
| get | /trace | HTTP 请求跟踪信息 |
| get | /heapdump | JVM 堆转储 |
1.2 漏洞复现
访问 /actuator/env 接口可能泄露环境变量信息。
访问 /actuator/info 接口可能泄露项目信息。
如果配置了 management.endpoints.* 但未做权限控制,同样存在风险。
2、解决方案
2.1 创建安全配置类
添加一个安全配置类,限制只有授权用户才能访问 Actuator 端点。以下配置要求访问 /actuator 下所有路径需具备 ADMIN 角色,并启用了 HTTP Basic 认证。
package com.example.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public {
Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(, ).permitAll()
.antMatchers().hasRole()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}


