【问题标题】:X-Frame Options Spring BootX-Frame 选项 Spring Boot
【发布时间】:2020-12-24 05:46:41
【问题描述】:

所以我尝试在我的 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"));

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

【问题讨论】:

    标签: java spring spring-boot iframe x-frame-options


    【解决方案1】:

    X-Frame-Options 是一个 HTTP 响应标头,由您请求资源的服务器设置。它用于指示是否应允许浏览器在&lt;frame&gt; 中呈现页面,从而通过确保内容不嵌入到其他站点中来避免点击劫持攻击。
    请参阅 MDN 文档:X-Frame-Options

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

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

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2023-04-07
      • 1970-01-01
      • 2017-07-29
      • 2021-08-05
      相关资源
      最近更新 更多