SpringBootloggers未授权访问漏洞处理
在编写系统的时候SpringBootloggers在未授权情况下可以访问是一个系统漏洞,我们可以通过加白名单或者直接关闭功能的方式处理。
1.添加白名单
添加SpringSecurity方法拦截,过滤用户拦截请求AuthorizeRequestsCustomizer
package com.todod.basemanage.module.base.framework.security.config;import com.todod.basemanage.framework.security.config.AuthorizeRequestsCustomizer;
import org.springframework.beans.factory.annotation.Value;
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.configurers.AuthorizeHttpRequestsConfigurer;/*** base 模块的 Security 配置*/
@Configuration(proxyBeanMethods = false, value = "baseSecurityConfiguration")
public class SecurityConfiguration {@Value("${spring.boot.admin.context-path:''}")private String adminSeverContextPath;@Bean("baseAuthorizeRequestsCustomizer")public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {return new AuthorizeRequestsCustomizer() {@Overridepublic void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {// Swagger 接口文档registry.requestMatchers("/v3/api-docs/**").hasRole("ADMIN").requestMatchers("/webjars/**").hasRole("ADMIN").requestMatchers("/swagger-ui.html").hasRole("ADMIN").requestMatchers("/swagger-ui/**").hasRole("ADMIN");// Spring Boot Actuator 的安全配置registry.requestMatchers("/actuator").hasRole("ADMIN").requestMatchers("/actuator/**").hasRole("ADMIN");// Druid 监控registry.requestMatchers("/druid/**").hasRole("ADMIN");// Spring Boot Admin Server 的安全配置registry.requestMatchers(adminSeverContextPath).hasRole("ADMIN").requestMatchers(adminSeverContextPath + "/**").hasRole("ADMIN");// 文件读取registry.requestMatchers(buildAdminApi("/base/file/*/get/**")).hasRole("ADMIN");}};}}
在yaml文件里配置用户角色权限:
spring:security:user:name: adminpassword: adminroles: ADMIN
测试一下就看看是否还可以访问,正常情况下是无法访问了
2.直接关闭端口(暴力解法)
在yaml文件中修改以下配置
# Actuator 监控端点的配置项
management:endpoints:web:base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuatorexposure:include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
星号:‘*’代表开放所有端点,我们只需要把*改成[]即可,代表空即无法访问,代码如下:
# Actuator 监控端点的配置项 management:endpoints:web:base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuatorexposure:include: [] # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。