X-Frame选项Spring Boot

问题描述

所以我试图在Spring Boot应用程序上使用配置iframe。但是,我正在努力使x-frame-options变为ALLOW-From。这是我的html和spring安全文件文件

HTML IFrame:

<div class="gridItem8">
<iframe src="https://www.youtube.com/watch?v=HV2LVEPrKGs&feature=emb_title" title="Halo Video"></iframe>
安全配置:
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
        .antMatchers().authenticated()
        .antMatchers( "/","/about","/signup","/signUpForm","/signUpFormError","/login","/logout","/ForgotPasswordPage","/Forgot_Password","/SignUp","/registrationComplete").permitAll()
        .antMatchers("/LoggedInUser/**").hasAnyAuthority("ADMIN","USER","MODERATOR")
        .anyRequest().authenticated().and().csrf().disable().formLogin()
        .loginPage("/login").failureUrl("/login?error=true")
        .defaultSuccessUrl("/LoggedInUser/success")
        .usernameParameter("email")
        .passwordParameter("password")
        .and().logout()
        .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
        .logoutSuccessUrl("/")
        .and()
        .headers()
        .frameOptions()
        .disable()
        .addHeaderWriter(new StaticHeadersWriter("x-frame-options","ALLOW-FROM https://www.youtube.com/watch?v=HV2LVEPrKGs&feature=emb_title"));

任何帮助将不胜感激。谢谢!

解决方法

X-Frame-Options是HTTP响应标头,由您从中请求资源的服务器设置。它用于指示是否应允许浏览器在<frame>中呈现页面,以通过确保内容未嵌入其他站点来避免点击劫持攻击。
请查看有关它的MDN文档:X-Frame-Options

因此,如果youtube.com上的资源将X-Frame-Options设置为DENY,则该资源将不允许在<frame>中呈现。如果为SAMEORIGIN,则只能在与页面本身相同的域中的<frame>中呈现资源。 ALLOW-FROM uri是一个过时的指令,在现代浏览器中不再有效。

如果您想在自己的网站中嵌入youtube视频,只需使用share功能并将HTML代码复制到您的网站中,here's an example应该可以使用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...