服务器在 Spring 应用程序中生成 env.json 文件

Server generating env.json file in Spring Application

在 运行 Spring 引导应用程序之后,我可以使用以下 link:

访问服务器上的文件

http://localhost:8080/myweb/env.json

此文件不仅包含与服务器相关的数据,还包含与应用程序相关的数据。与应用程序相关的数据具有 application.properties 文件中定义的所有属性。这是一个安全漏洞。

{
  "profiles": [],
  "server.ports": {
    "local.server.port": 8080
  },
  "servletContextInitParams": {},
  "systemProperties": {},
  "systemEnvironment": {},
  "applicationConfig: [classpath:/application.properties]": {}
}

这个文件是如何生成的,我们如何限制它的公开访问?

这来自Spring Boot Actuator

management.endpoint.env.enabled=false 

将禁用此端点

如果不行试试

management.endpoints.web.exposure.exclude=env

或者您可以使用此配置禁用所有这些

management.endpoints.enabled-by-default=false

您可以在此处阅读更多相关信息: https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html