我有一个SpringBoot 2.1.7 SpringBoot应用程序。使用Thymeleaf模板引擎,我把这段代码放在Thymeleaf模板中,但是图像没有显示出来。
<object data="assets/img/icons/ico_status_up.svg" type="image/svg+xml">
<img th:src="@{assets/img/icons/ico_status_up.png}" alt="UP">
</object>我在浏览器的控制台中看到了这个错误:
Refused to display 'http://localhost:8080/bonanza/pecador/assets/img/icons/ico_status_up.svg' in a frame because it set 'X-Frame-Options' to 'deny'.我在我的项目中使用spring安全:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>发布于 2019-08-31 08:45:13
问题是,您可能正在使用自配置的Spring安全模块。
正如在弹簧安全文档中解释的那样:
解决点击劫持问题的一种更现代的方法是使用X帧选项标头: X帧选项:拒绝 X框架选项响应头指示浏览器防止在响应中使用此标头的任何站点在框架内呈现。默认情况下,安全性禁用iframe.中的呈现。
因此,要配置这种行为,您应该配置Security:
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// ...
.headers()
.frameOptions()
.sameOrigin(); // or disable();
}
}此外,我鼓励您考虑这样的问题,其中包含了如何使用html标记来显示SVG - 为了SVG文件?的主题。
https://stackoverflow.com/questions/57736409
复制相似问题