2016-07-20 76 views
0

我想在y.example.com使子域的iframe訪問

這裏是我已經這樣做了

Tomcat中設置託管的網頁上顯示來自x.example.com IFRAME:

<filter> 
    <filter-name>ClickJackFilterEnabled</filter-name> 
    <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class> 
    <init-param> 
     <param-name>antiClickJackingEnabled</param-name> 
     <param-value>false</param-value> 
    </init-param> 
</filter> 

<filter-mapping> 
    <filter-name>ClickJackFilterEnabled</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

春季安全:

httpResponse.setHeader("Content-Security-Policy", "default-src 'self' *.example.com; style-src 'self' *.googleapis.com *.amazonaws.com 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self' *.example.com; font-src *;img-src 'self' *.amazonaws.com"); 
    httpResponse.setHeader("Access-Control-Allow-Origin", "http://*.example.com"); 

當我打開網頁嵌入iframs,我仍然剛開克這種錯誤:

Refused to display 'http://x.example.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. 

Uncaught SecurityError: Sandbox access violation: Blocked a frame at "http://y.example.com" from accessing a frame at "http://x.example.com". The frame being accessed is sandboxed and lacks the "allow-same-origin" flag. 

當我檢查使用捲曲頭,頭X框選項不存在

這捲曲的輸出

* Rebuilt URL to: y.example.com/ 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0* Trying 127.0.0.1... 
* Connected to y.example.com (127.0.0.1) port 80 (#0) 
> GET/HTTP/1.1 
> Host: y.example.com 
> User-Agent: curl/7.47.0 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Server: Apache-Coyote/1.1 
< X-Content-Type-Options: nosniff 
< X-XSS-Protection: 1; mode=block 
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
< Pragma: no-cache 
< Expires: 0 
< X-Application-Context: application:dev:8080 
< Content-Security-Policy: default-src 'self' *.example.com; style-src 'self' *.googleapis.com *.amazonaws.com 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self' *.example.com; font-src *;img-src 'self' *.amazonaws.com 
< Access-Control-Allow-Origin: http://*.example.com 
< Content-Type: text/html;charset=UTF-8 
< Content-Language: en-IN 
< Transfer-Encoding: chunked 
< Date: Wed, 20 Jul 2016 13:21:57 GMT 
< 
{ [8200 bytes data] 

我在想什麼?

UPDATE:

我試圖設置

document.domain = "example.com" 

在網頁上兩個,我仍然得到錯誤

Refused to display 'http://x.example.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' 

當我鍵入

document.domain 

在javascript的安慰le,我越來越

"example.com" 

在這兩個網頁上。所以這兩個頁面的原點是相同的。

回答

0

x.example.com是發送SAMEORIGIN標題的人。 y.example.com無法覆蓋此項,因爲那樣就無法阻止iframe包含。網站必須向其他網站授予許可權(通過缺少來源政策或具有許可的網站列表)以包含其內容。

檢查來自x .example.com的標題,您應該看到實際阻止iframe的策略。

+0

這兩個子域都託管在同一臺服務器上,並且設置相同,這兩個子域返回的標頭完全相同。 –

0

最後我能解決這個問題。問題可能在於瀏覽器如何處理X-Frame-Options標題。

背後設置

document.domain = "example.com" 

的概念是讓原點兩者相同的網頁。瀏覽器允許設置原點父域,所以在axexample.com一個頁面可以document.domain的設定的x.example.comexample.com

現在,即使例如document.domain設置爲。COM,當我刪除了X-Freme-選項頭乾脆我得到的錯誤

Refused to display 'http://x.example.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' 

,使用

http.headers().frameOptions().disable(); 

在securityConfiguration.java,它的工作!

我不知道瀏覽器不遵守document.domain設置的原因。在mozilla文檔或其他任何地方都找不到這方面的內容。希望這可以幫助某人。