java - 在 Springdoc 中未禁用 Petstore url(swagger 默认应用程序)
问题描述
我仍然有“禁用”问题......
我的招摇界面网址配置为 /swagger-ui.html (它重定向到 /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config =>这是正常的!)但默认招摇网址( PetStore )仍然可以通过 /swagger-ui/index.html 访问(所以通过从 "?" 中删除所有内容)。
我必须解决这个问题,因为它被视为一个安全问题......
有 4 种配置方法,但我使用了 swagger-ui yaml 文件: https ://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
我的 application.yaml :
springdoc:
swagger-ui:
path: '/swagger-ui.html'
configUrl: '/v3/api-docs/swagger-config'
disable-swagger-default-url: true
但这不会禁用宠物商店。我不知道为什么 :-(
我正在使用 springdoc openapi 1.5.7(在 build.gradle 中):
implementation('org.springdoc:springdoc-openapi-ui:1.5.7') {
exclude group: 'javax.validation', module: 'validation-api'
}
我在配置中将路径从“/swagger-ui.html”更改为路径:“/swagger_ui.html”(并再次运行应用程序)此更改有效,所以我不明白为什么它不禁用默认招摇网址.
我阅读了有关 stackoverflow 的许多主题,我确切地了解了所写的内容,我在需要“配置”的文件中得到了答案( application.properties 或 application.yaml )
解决方案
我终于解决了这个问题,感谢 SSK !
此问题的解决方案是添加“application.yaml”(在“main”下的文件夹“resources”中):
springdoc:
swagger-ui:
path: /swagger-ui.html
display-request-duration: true
groups-order: DESC
operationsSorter: method
disable-swagger-default-url: true
我的招摇 http://localhost:8080/swagger-ui.html 非常适合我的应用程序,你被重定向到 http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/ swagger-config 这是正确的(并且总是完美地工作)!
但是当尝试使用这些网址时: http://localhost:8080/swagger-ui/index.html?configUrl= http://localhost:8080/swagger-ui/index.html 它给出“没有提供 API 定义”。 ,所以它是完全安全的,并且“demo PetStore”被禁用了!
祝你今天过得愉快 !
推荐阅读
- python - 为什么那些带有布局的小部件不起作用
- javascript - 在 HTML 页面中使用 JS
- tensorflow - 将 12 通道重塑为 3 通道 Tensorflow
- unity3d - 在将 Facebook 网络广告统一实施时,我得到 Null 参考 AudienceNetwork.AudienceNetworkAds.IsInitialized ()
- r - 如何在 glm 中指定特定的优化方法
- node.js - 如何删除未使用的要求和/或导入行?
- pine-script - Pine 脚本句柄关闭值
- ruby-on-rails - 尝试将导轨版本从 4.2.11 升级到 5.0
- c++ - 如何在 QT 中将大量 C 文件导入到我的项目中?
- python - 在 python 中定义一个回调协议,作为任何符合以下模式的函数的结构超类型