Spring security 启用Spring安全性使Swagger输出文本/纯文本而不是HTML
招摇过市!我可以和你互动,一切都很好 我将以下内容添加到pom.xml中Spring security 启用Spring安全性使Swagger输出文本/纯文本而不是HTML,spring-security,spring-boot,swagger,swagger-ui,swagger-maven-plugin,Spring Security,Spring Boot,Swagger,Swagger Ui,Swagger Maven Plugin,招摇过市!我可以和你互动,一切都很好 我将以下内容添加到pom.xml中 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> 在这一点上,如果我访问以前工作的同一个URL,我现在会得到一个text/plain响应
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
在这一点上,如果我访问以前工作的同一个URL,我现在会得到一个text/plain响应类型,而不是一个漂亮的HTML浏览器,我会看到源代码
如果我恢复更改并从project中删除这两个文件并删除JAR文件,它将再次工作
如何让Spring Security和Swagger玩得更好?我做错了什么。我怀疑这是由于Spring Security对内容类型标题的影响 从文件中- 历史上,包括Internet Explorer在内的浏览器都会尝试使用内容嗅探来猜测请求的内容类型。这允许浏览器通过猜测未指定内容类型的资源上的内容类型来改善用户体验。例如,如果浏览器遇到未指定内容类型的JavaScript文件,它将能够猜测内容类型,然后执行它 内容嗅探的问题在于,这允许恶意用户使用多语言标记,即作为多种内容类型有效的文件来执行XSS攻击。例如,某些网站可能允许用户向网站提交有效的postscript文档并进行查看。恶意用户可能创建一个也是有效JavaScript文件的postscript文档,并使用它执行XSS攻击 同样,从文档中,为了覆盖默认值-
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// ...
.headers()
.contentTypeOptions();
}
}
哇,我想是这样的。非常感谢 当我试过这个,它开始工作
.headers()
.disable()
我将默认的contentTypeOptions缩小到
.headers()
//.contentTypeOptions() // If this is uncommented it fails.
.xssProtection()
.cacheControl()
.httpStrictTransportSecurity()
.frameOptions()
.and()
太好了,谢谢你的反馈和补充信息。我希望它也能帮助其他人。
.headers()
.disable()
.headers()
//.contentTypeOptions() // If this is uncommented it fails.
.xssProtection()
.cacheControl()
.httpStrictTransportSecurity()
.frameOptions()
.and()