[Webinar] Streamline your web hosting managementRegister Today


Restricting framing of frame to a specific foreign website

Posted on 2006-10-23
Medium Priority
Last Modified: 2008-02-01
I have a frame hosted on one domain that subscriber websites (with other domains) will be able to incorporate in their websites by framing or using an iframe. I am looking for a way I can prevent rogue websites from framing this frame, hence stealing it's content.
(Please look at the example at http://allstarcomputing.com/svtframetest.asp to see how this currently looks if I am not being clear).
I am an ASP/VBscript guy but I am thinking I need a JavaScript solution to this problem. So I really only have a little of an idea how to do this.  
My idea is that I need to get the URL of the parent frame to compare with the intended parent URL for validation, but my attempts have failed. Specifically when I try to get the Parent window URL with a  I get a message (IE6) "Access is denied". (I don't get this message when I use this frame on it's own domain's frameset, only when I try to frame it with a different domain.
I won't be able to control much on the subsciber's side other than to provide them with a link and perhaps some HTML code they could incorporate - I want it simple for them, but I do have server side capabilities on the frame's server.
Sorry to be so long but I want to make my problem clear.
The question is: How can I validate that the framing site actually corresponds to the site URL encoded in the frame's URL?
Question by:monshes
  • 5
  • 3
LVL 16

Assisted Solution

OliWarner earned 2000 total points
ID: 17792464
I think a frame on another site will display its referrer to your page as that external site, so you should be able to check that against your list of "allowed" domains.

LVL 16

Assisted Solution

OliWarner earned 2000 total points
ID: 17792469
I suggest testing that out from a couple of remote domains and making sure the same thing happens in different browsers because referrer code is down to the browser makers to implement. Some may not have it on their code for iframe links.

Author Comment

ID: 17792888
Regretfully Request.ServerVariables("HTTP_REFERER") will not work for the first time the frameset is loaded. I tried that first. Request.ServerVariables("HTTP_REFERER") is an empty string for the first page loaded in the browser(a distinct possibility if someone bookmarks the frameset, which needs to be possible).
Request.ServerVariables("HTTP_REFERER") only works for this scenario if the frameset is refreshed or loaded by a link on the parent domain. That is why I think I need a JavaScript solution or something transcending this problem.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

LVL 16

Accepted Solution

OliWarner earned 2000 total points
ID: 17792943
Is it a proper frameset or just an iframe?

Another option, as you just pointed out, is having the external sites include a JS file on your server. If that JS file were actually an ASP file that outputted JS code, you should be able to do the referrer check and set a session variable on your server if that host is allowed (i'll explain in a bit). Also make sure the JS isn't cached. This can best be achieved by adding a random querystring (that doesn't get read) to the end of URL for the JS file (which is actually an ASP file)

As for the JS itself, work it like adsense (if you've seen the code for that) so that people can customise the way the JS outputs an iframe. So yes. Have that JS output an iframe based on the configuration specified by the external webmasters and link to your asp page inside it.

Here's the clever part: because the request for the JS should have started a session on your server and set a variable, you now know if that user is coming from an allowed site and what to show them.

It's long winded, but it should work.
LVL 16

Assisted Solution

OliWarner earned 2000 total points
ID: 17792960
And here's an example of adsense code:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel = "";
<script type="text/javascript"

As you can see, the variables are specified before the link to the external file. The external js, when loaded, can then read those vars and, in your case, decide how to output the iframe.

Author Comment

ID: 17793146
I want this frame to work either as a frame in a proper frameset or as an iframe.

I think I get the gist of the adsense idea. I'm going to try it out tommorrow. But........  Now that I'm thinking about it if I incorporate a javascript variable used to validate the framing domain and that code is accesible by View Source, then it seems that that the security intent of this enterprise is compromised. The script could be written into  a frameset by a non-subscriber spoofing themself as a subscriber.
I need a method that a reasonably astute nonsubscribing webmaster cannot easily exploit and then "borrow" the frame into their website. I am hoping there was a way with JavaScript (or anything else) to get the URL of the parent frame (which would be hard to spoof) and crosscheck it with the expected URL of the framing domain (which will be chosen out of a database based on the ID parameter passed in the frame URL). And I'm hoping it's possible :)
LVL 16

Assisted Solution

OliWarner earned 2000 total points
ID: 17793170
But if someone goes to one of these external sites, with the information on the page and some simple programming they could easily spoof the referrers.

This is the trade-off between making things easy for other people to use and secure.

If your data needs to be protected that much, you could make the users run server-side code that sends your server private information about itself plus information about the current user. When the same user hits your servers, you should be able to tally that data with their credentials/ip/etc.
LVL 44

Expert Comment

ID: 17793604
Frames and Iframes are totally different animals.  You need to FORGET frames for any modern programming, use Iframes instead, and with iframes, it is simple to get the parent in javascript --

parent.item.attribute = new attribute  -- does it in javascript just fine.

Author Comment

ID: 17797808
In response to scrathcyboy... My situation requires a solution that will work either in frames or iframes because I do not want to limit my subscribers (other webmasters of varying abilities) so as to exclude them. I personally prefer iframes. I cannot use my favorite which is SSI because of the cross domain issues here.

To everyone... I seem to be running into a security issue getting ANYTHING in javascript from the host frameset to the framed window. I get "Access Denied" error messages in IE^ using medium security.

To OliWarner and all... I think your server side idea seems promising. Are you suggesting that the hosting frameset server (pardon my nomenclature - I'm self taught) send something that is not visible in the page source code or the HTTP headers? It sounds good if it is not too hard for subscriber's webmasters to implement on whatever platform they may run. This stuff is not sensitive in any real security sense. I'm just trying to limit the freeloading of what will grow to a large collection of area virtual tour panorama photography display (which itself is secured to some extent already - it will only run on it's own server) which will be tempting to casual framing theft.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question