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}


目录
相关文章
|
7天前
|
缓存 监控 Java
优化Spring Boot应用的数据库访问性能
优化Spring Boot应用的数据库访问性能
|
8天前
|
缓存 监控 Java
优化Spring Boot应用的数据库访问性能
优化Spring Boot应用的数据库访问性能
|
12天前
|
Java
自主定义访问路径-----SpringBoot自主定义静态资源访问路径的方法
自主定义访问路径-----SpringBoot自主定义静态资源访问路径的方法
|
19天前
|
前端开发 JavaScript 网络协议
Springboot中为什么你能通过一小段代码来访问网页?
Springboot中为什么你能通过一小段代码来访问网页?
27 7
|
17天前
|
Java
SpringBoot修改访问路径
SpringBoot修改访问路径
|
21天前
|
JavaScript 应用服务中间件 nginx
nginx配置解决vue刷新404、swagger 页面访问(springboot+vue项目)
nginx配置解决vue刷新404、swagger 页面访问(springboot+vue项目)
22 0
|
2月前
|
NoSQL Java Redis
springboot之RedisTemplate的访问单机,哨兵,集群模式
以上是配置RedisTemplate以连接到单机、哨兵和集群模式的示例。在实际应用中,还可以根据需求配置连接池、序列化方式、超时等其他参数。
92 0
springboot 获取访问接口的请求的IP地址
springboot 获取访问接口的请求的IP地址
2568 0
|
4天前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的房屋租赁App的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的房屋租赁App的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的房屋租赁App的详细设计和实现(源码+lw+部署文档+讲解等)
|
4天前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的武汉市公交路线查询系统的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的武汉市公交路线查询系统的详细设计和实现(源码+lw+部署文档+讲解等)