簡體   English   中英

X-Frame-Options:DENY 僅適用於后端端口端點

[英]X-Frame-Options: DENY works only on backend port endpoints

因此,由於我正在處理 spring 安全性,因此我已將 headers.frameOptions 設置為 DENY,當我通過將后端端點放入 iframe(此處localhost:8080 )來嘗試此操作時,一切都運行良好,問題是,當我將前端localhost:3000放在 iframe 中,沒有任何反應,應用程序顯示在 iframe 中。我認為我正在做的標頭配置僅適用於 API,而不適用於應用程序的開始

在應用程序開始時,您可以看到沒有配置: X-Frame-Options: DENY在我發送 API 之后

這是 function

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.headers()
            .httpStrictTransportSecurity()
            .maxAgeInSeconds(31536000)
            .includeSubDomains(true);

    http.headers()
            .contentTypeOptions();
    http.cors().and()
            .headers()
            .xssProtection()
            .and()
            .contentSecurityPolicy("script-src 'self'")
            .and()
            .httpStrictTransportSecurity().includeSubDomains(true).maxAgeInSeconds(31536000)
            .and()
            .contentSecurityPolicy("frame-ancestors 'none'")
            .and()
            .frameOptions()
            .deny()
            .and()
            .csrf()
            .disable()
            .formLogin().defaultSuccessUrl("/swagger-ui.html", true).and()
            .authorizeRequests().antMatchers(AUTH_LIST).authenticated()
            .antMatchers("/actuator/**").access("hasAnyRole('ADMIN') and hasIpAddress('127.0.0.1')")
            .anyRequest().permitAll()
            .and().httpBasic();
}

如果您使用 nginx 作為服務器,我最終通過配置前端 web.xml 文件解決了這個問題,您可以添加:

Header 始終設置 X-Frame-Options“SAMEORIGIN”

如果您使用的是任何其他服務器,您可以檢查mdn

總而言之,如果你正在開發一個完整的堆棧應用程序,你必須配置服務器配置文件,否則 spring 安全性不會阻止你點擊劫持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM