Programming

iframe에서 'X-Frame-Options'를 설정하는 방법은 무엇입니까?

procodes 2020. 6. 29. 21:47
반응형

iframe에서 'X-Frame-Options'를 설정하는 방법은 무엇입니까?


이런 식으로 만들면 iframe:

var dialog = $('<div id="' + dialogId + '" align="center"><iframe id="' + frameId + '" src="' + url + '" width="100%" frameborder="0" height="'+frameHeightForIe8+'" data-ssotoken="' + token + '"></iframe></div>').dialog({

오류를 어떻게 해결할 수 있습니까?

'https://www.google.com.ua/?gws_rd=ssl''X-Frame-Options'가 'SAMEORIGIN'으로 설정되어 프레임 에 표시 되지 않습니다.

JavaScript로?


당신은 설정할 수 없습니다 X-Frame-Optionsiframe. 리소스를 요청하는 도메인에서 설정 한 응답 헤더입니다 ( google.com.ua예제에서). SAMEORIGIN이 경우 헤더를 설정했습니다. 즉, iframe도메인 외부 에서 리소스를로드 할 수 없습니다 . 자세한 내용은 MDN 의 X-Frame-Options 응답 헤더참조하십시오 .

여기에 Chrome 개발자 도구에 표시된 헤더를 빠르게 검사 X-Frame-Options하면 호스트에서 반환 된 값이 표시됩니다.

여기에 이미지 설명을 입력하십시오


문제를 오해하고있는 것 같습니다. 요청 된 도메인이 프레임 내에 표시 될 수 있는지 여부를 나타내는 상태 요청 X-Frame-Options에 대한 응답포함 된 헤더 입니다. Javascript 또는 HTML과는 아무런 관련이 없으며 요청을 보낸 사람이 변경할 수 없습니다.

이 웹 사이트는이 헤더가에 표시되지 않도록 설정했습니다 iframe. 이 행동을 막기 위해 할 수있는 일은 없습니다.

X-Frame-Options에 대한 추가 자료


iframe의 컨텐츠를 전송하는 서버를 제어하는 ​​경우 X-Frame-Options웹 서버에서 설정을 지정할 수 있습니다 .

아파치 설정

모든 페이지에 대해 X-Frame-Options 헤더를 보내려면 사이트 구성에 다음을 추가하십시오.

Header always append X-Frame-Options SAMEORIGIN

nginx 구성

Xgin-Frame-Options 헤더를 보내도록 nginx를 구성하려면 http, 서버 또는 위치 구성에 추가하십시오.

add_header X-Frame-Options SAMEORIGIN;

구성이 없습니다

이 헤더 옵션은 선택 사항이므로 옵션이 전혀 설정되지 않은 경우 다음 인스턴스 (예 : 방문자 브라우저 또는 프록시)에 구성 할 수있는 옵션이 제공됩니다.

출처 : https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options


솔루션이 서버 측에서 실제로 언급되지 않았기 때문에 :

이와 같은 것을 설정해야합니다 (아파치의 예). 이것이 모든 것에서 허용하는 최상의 옵션은 아니지만 서버가 올바르게 작동하는 것을 본 후에는 쉽게 설정을 변경할 수 있습니다.

           Header set Access-Control-Allow-Origin "*"
           Header set X-Frame-Options "allow-from *"

정말 ... 나는 사용했다

 <system.webServer>
     <httpProtocol allowKeepAlive="true" >
       <customHeaders>
         <add name="X-Frame-Options" value="*" />
       </customHeaders>
     </httpProtocol>
 </system.webServer>

해결책은 브라우저 플러그인을 설치하는 것입니다.

A web site which issues HTTP Header X-Frame-Options with a value of DENY (or SAMEORIGIN with a different server origin) cannot be integrated into an IFRAME... unless you change this behavior by installing a Browser plugin which ignores the X-Frame-Options Header (e.g. Chrome's Ignore X-Frame Headers).

Note that this not recommended at all for security reasons.


The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

For More Information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

I have an alternate solution for this problem, which I am going to demonstrate by using PHP:

iframe.php:

<iframe src="target_url.php" width="925" height="2400" frameborder="0" ></iframe>

target_url.php:

<?php 
  echo file_get_contents("http://www.example.com");
?>

I had the same problem on my virtualmin server (apache) for wordpress in a subdirecotry and none of above answers could solve the problem on my case and still was getting the x-frame-options denied error message on console, until I tried to add below line to .htaccess file placed on my public_html\subdirectory\(wordpress root) directory:

header always set x-frame-options "SAMEORIGIN"

and this was the only working solution in my case. (note that there is a part containing always set rather than append or always append)


and if nothing helps and you still want to present that website in an iframe consider using X Frame Bypass Component which will utilize a proxy.


For this purpose you need to match the location in your apache or any other service you are using

If you are using apache then in httpd.conf file.

  <LocationMatch "/your_relative_path">
      ProxyPass absolute_path_of_your_application/your_relative_path
      ProxyPassReverse absolute_path_of_your_application/your_relative_path
   </LocationMatch>

you can set the x-frame-option in web config of the site you want to load in iframe like this

<httpProtocol>
    <customHeaders>
      <add name="X-Frame-Options" value="*" />
    </customHeaders>
  </httpProtocol>

You can not really add the x-iframe in your HTML body as it has to be provided by the site owner and it lies within the server rules.

What you can probably do is create a PHP file which loads the content of target URL and iframe that php URL, this should work smoothly.


you can do it in tomcat instance level config file (web.xml) need to add the 'filter' and filter-mapping' in web.xml config file. this will add the [X-frame-options = DENY] in all the page as it is a global setting.

<filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
          <param-name>antiClickJackingEnabled</param-name>
          <param-value>true</param-value>
        </init-param>
        <init-param>
          <param-name>antiClickJackingOption</param-name>
          <param-value>DENY</param-value>
        </init-param>
    </filter>

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

참고URL : https://stackoverflow.com/questions/27358966/how-to-set-x-frame-options-on-iframe

반응형