X-Frame-Options: ALLOW-FROM in firefox and chrome

后端 未结 3 556
感动是毒
感动是毒 2020-12-02 10:47

I\'m implementing a \"pass-through\" for X-Frame-Options to let a partner site wrap my employer\'s site in an iframe, as per this article: http://blogs.msdn.com

相关标签:
3条回答
  • 2020-12-02 11:31

    For Chrome, instead of

    response.AppendHeader("X-Frame-Options", "ALLOW-FROM " + host);
    

    you need to add Content-Security-Policy

    string selfAuth = System.Web.HttpContext.Current.Request.Url.Authority;
    string refAuth = System.Web.HttpContext.Current.Request.UrlReferrer.Authority;
    response.AppendHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: *.msecnd.net vortex.data.microsoft.com " + selfAuth + " " + refAuth);
    

    to the HTTP-response-headers.
    Note that this assumes you checked on the server whether or not refAuth is allowed.
    And also, note that you need to do browser-detection in order to avoid adding the allow-from header for Chrome (outputs error on console).

    For details, see my answer here.

    0 讨论(0)
  • 2020-12-02 11:42

    I posted this question and never saw the feedback (which came in several months after, it seems :).

    As Kinlan mentioned, ALLOW-FROM is not supported in all browsers as an X-Frame-Options value.

    The solution was to branch based on browser type. For IE, ship X-Frame-Options. For everyone else, ship X-Content-Security-Policy.

    Hope this helps, and sorry for taking so long to close the loop!

    0 讨论(0)
  • 2020-12-02 11:45

    ALLOW-FROM is not supported in Chrome or Safari. See MDN article: https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options

    You are already doing the work to make a custom header and send it with the correct data, can you not just exclude the header when you detect it is from a valid partner and add DENY to every other request? I don't see the benefit of AllowFrom when you are already dynamically building the logic up?

    0 讨论(0)
提交回复
热议问题