SpringBoot Actuator未授权访问漏洞的解决方法

简介: SpringBoot Actuator未授权访问漏洞的解决方法Actuator 是 SpringBoot 提供的用来对应用系统进行自省和监控的功能模块,借助于 Actuator 开发者可以很方便地对应用系统某些监控指标进行查看、统计等。

一、Actuator 是什么

Actuator 是 SpringBoot 提供的用来对应用系统进行自省和监控的功能模块,借助于 Actuator 开发者可以很方便地对应用系统某些监控指标进行查看、统计等。

引入了actuator 相关依赖后一般以

http://ip:端口/项目前缀(如果有的话)/actuator/

二、未授权访问漏洞是怎么产生的

Actuator在带来方便的同时,如果没有管理好,会导致一些敏感的信息泄露;可能会导致我们的服务器,被暴露到外网,服务器可能会沦陷。

例如:

很多关键的信息都会暴露出来,线上服务等同于裸奔

三、解决方案都有哪些

1. 关闭端口(大多数是不会采取这种方案)

在配置文件中添加配置

management:
endpoints:
enabled-by-default: false
# 版本低的配置
# management:
#   endpoints: 
#     enabled: false

大多数是不会采取这种方案,但也不排除生产上感觉actuator没什么实质作用的同学,可以选择关闭暴露端点

但毕竟使用actuator是主观意向,主要是为了配合 SpringAdmin 或 Prometheus 来监控的,很多人都会需求其他的解决方案

2. 网关限制(最简单粗暴)

如果使用nginx作为网关控制,直接屏蔽掉相关接口即可

2.1 nginx 配置文件

屏蔽actuator路径

location ~ .*actuator.* {
   deny all;
}

2.2 k8s-ingress 配置文件

屏蔽actuator路径

metadata:
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
      location ~ .*actuator.* {
        deny all;
      }

3. Actuator 开启认证授权(存在代码污染风险)

主要是借助 spring security 来实现的,如果当前项目有使用security,需要自己解决一下合并问题

3.1 引入Maven包坐标

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

3.2 增加Java 权限控制代码

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.security.web.firewall.StrictHttpFirewall;
/**
 * Actuator 监控端点权限
 *
 * @author Parker
 */
@Configuration
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic().and()
                .authorizeRequests()
                    .antMatchers("/actuator/**")
                        .authenticated()
                    .anyRequest()
                        .permitAll();
        http
// 关闭csrf token认证不需要csrf防护
            .csrf().disable()
// 关闭Session会话管理器 JWT 不需要
            .sessionManagement().disable()
// 关闭记住我功能 JWT 不需要
            .rememberMe().disable();
    }
/**
     * 配置地址栏不能识别 // 的情况
     * @return
     */
@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
        StrictHttpFirewall firewall = new StrictHttpFirewall();
//此处可添加别的规则,目前只设置 允许双 //
        firewall.setAllowUrlEncodedDoubleSlash(true);
return firewall;
    }
}

3.3 Spirngboot 工程增加配置

# 开启SpringBoot Admin的监控
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
spring:
# 自身权限校验账号密码
security:
user:
name:
password:
# 上报账号密码    
boot:
admin:
client:
url: Admin URL
username:
password:
instance:
metadata:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}


目录
相关文章
|
1月前
|
缓存 监控 Java
优化Spring Boot应用的数据库访问性能
优化Spring Boot应用的数据库访问性能
|
1天前
|
Java Spring
Spring boot +Thymeleaf 本地图片加载失败(图片路径)的问题及解决方法
这篇文章详细讲解了在Spring Boot应用程序中本地图片无法加载的问题原因,并提供了两个示例来说明如何通过使用正确的相对路径或Thymeleaf语法来解决图片路径问题。
|
9天前
|
Java Spring
Spring Boot实战:静态资源无法访问
Spring Boot实战:静态资源无法访问
7 0
|
1月前
|
缓存 监控 Java
优化Spring Boot应用的数据库访问性能
优化Spring Boot应用的数据库访问性能
|
2月前
|
前端开发 JavaScript 网络协议
Springboot中为什么你能通过一小段代码来访问网页?
Springboot中为什么你能通过一小段代码来访问网页?
37 7
|
1月前
|
Java
自主定义访问路径-----SpringBoot自主定义静态资源访问路径的方法
自主定义访问路径-----SpringBoot自主定义静态资源访问路径的方法
|
2月前
|
Java
SpringBoot修改访问路径
SpringBoot修改访问路径
|
2月前
|
JavaScript 应用服务中间件 nginx
nginx配置解决vue刷新404、swagger 页面访问(springboot+vue项目)
nginx配置解决vue刷新404、swagger 页面访问(springboot+vue项目)
58 0
|
3月前
|
消息中间件 运维 监控
|
Java 安全
SpringBoot特性之Actuator
SpringBoot自动配置的特性,很大程度上解放了我们繁琐的配置的工作,但是也向我们屏蔽了很多内部运行 的细节,好在SpringBoot为我们提供了Actuator,Actuator在应用程序里提供了众多的Web端点,通过它 们,我们可以了解应用程序运行时的内部状况。
1048 0