Spring Boot Actuator未授权访问漏洞
漏洞解释
这个漏洞就是可以直接通过网页地址访问到actuator的暴露的端口
例如:http://127.0.0.1:8181/actuator/env
解决方法
其实就是拦截这些Actuator的请求,不让可以直接访问到
普通服务
https://blog.csdn.net/python15397/article/details/123931915
1.引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.配置个配置文件
配置文件解释:
就是配了个拦截所有/actuator的前缀的请求,然后放行所有的请求(其他的看自己的需求修改)
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 class MyWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//CSRF默认支持的方法: GET|HEAD|TRACE|OPTIONS,不支持POST ,不是我们想要的,故取消CSRF防御
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/actuator/**").denyAll()
.anyRequest().permitAll();
}
}
完事了就成这样了
geteway
这个好像里面用了WebFlux,然后写security的配置好像不生效,用webflux的配置文件,官网好像也能找到(咱找不到)。
https://blog.csdn.net/qq_21518697/article/details/126049552
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebFluxSecurity
public class SecurityConfig {
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity){
httpSecurity
.authorizeExchange()
.pathMatchers("/actuator/**").denyAll()
.pathMatchers("/**").permitAll()
.pathMatchers(HttpMethod.OPTIONS).permitAll()
.anyExchange().authenticated()
.and()
.csrf()
.disable()
.cors();
return httpSecurity.build();
}
}
完事这样,咱想配置 用户,不知道为啥不生效,登录不上去,就这样吧,请求也拦截了