How to restrict who can iframe embed my web app?

筅森魡賤 提交于 2019-12-21 21:20:12

问题


What is the best (most secure) way to restrict which websites can iframe embed by web application?

For example, everyone should be denied who is not on the list:

  • www.myFriend.com
  • www.anotherFriend.com
  • www.myThirdFriend.com

As a follow up question, given any restrictions for the above, what is the most secure way to find out server side which one of the white-listed sites is doing the embedding?


回答1:


Use the X-Frame-Options HTTP header.

X-Frame-Options ALLOW-FROM http://example.com/

See also the MSDN documentation which has this advice:

Note that the Allow-From token does not support wildcards or listing of multiple origins. For cases where the server wishes to allow more than one page to frame its content, the following design pattern is recommended:

  1. The outer IFRAME supplies its own origin information, using a querystring parameter on the Inner IFRAME's src attribute. This can obviously be specified by an attacker, but that's OK.
  2. The server for the Inner IFRAME verifies the supplied Origin information meets whatever criteria business practices call for. For example, the server that serves the IFRAME containing a social network's "Like" button, might check to see that the supplied Origin matches the Origin expected for that Like button, and that the owner of the specified Origin has a valid affiliate relationship, etc.
  3. If satisfied with the information supplied, the server for the Inner IFRAME sends an X-FRAME-OPTIONS: allow-from suppliedorigin header
  4. The Browser then enforces the X-FRAME-OPTIONS directive.



回答2:


FROM MDN

The X-Frame-Options response header

Using X-Frame-Options There are three possible values for X-Frame-Options:

  • DENY : The page cannot be displayed in a frame, regardless of the site attempting to do so.
  • SAMEORIGIN : The page can only be displayed in a frame on the same origin as the page itself.
  • ALLOW-FROM uri : The page can only be displayed in a frame on the specified origin.


来源:https://stackoverflow.com/questions/21629414/how-to-restrict-who-can-iframe-embed-my-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!