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?
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.Use the
X-Frame-Options
HTTP header.See also the MSDN documentation which has this advice: