I have a very basic ASP.NET MVC 5 application, hosted on an intranet server, where one of the pages has an iframe
to display a document:
<div class="document-view-container">
...
<iframe class="document-frame" src="@Url.Action("GetDocumentImage", "Imaging", ...)" ></iframe>
...
</div>
The returned document is sometimes a PDF served as application/pdf
, sometimes a piece of text served as text/plain
, and sometimes an XML served as text/xml
.
The GetDocumentImage
method retrieves the document contents from a database and returns it using File
:
return File(doc.document.ToArray(), doc.mime_type);
When the document happens to be an XML, it often includes a reference to a stylesheet with which it should be viewed:
<?xml-stylesheet type="text/xsl" href="//server.local/folder/content/grn.xslt"?>
<document>
...
</document>
Sometimes that stylesheet comes from the same subdomain as what the @Url.Action()
returns (i.e. same origin with the iframe
), but sometimes it does not.
When it does not, the stylesheet is successfully loaded and used in Firefox, but Chrome refuses to load the stylesheet and displays an error in console,
Unsafe attempt to load URL
http://server.local/folder/content/grn.xslt
from frame with URLhttp://documents.server/imaging/GetDocumentImage/52855
. Domains, protocols and ports must match.
This is a known problem, but my understanding was that it only applies to local files, not to files served from a server, and one of the solutions is specifically to host the files on a server. Besides, it works in Firefox.
What is the source of this problem?
- Is it Chrome, that treats the XML in an
iframe
as a local file and therefore incorrectly prevents it from requesting a stylesheet from the server? - Is it Firefox, that has a security issue where it would allow an XML file from an
iframe
request a stylesheet when it should be prohibited? - Is it me, who is not serving the XML from the server properly enough making Chrome mistake it for a local file?
What is the proper way to fix it?