Results 1 to 8 of 8

Thread: frame buster problem

  1. #1
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default frame buster problem

    i have a question. I have a framed website. Is it possible to stop another site loading one of my content pages without the framebreaker, breaking the frames for a regular visitor to my site?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Should be possible. Say your break out of frames code is something like:

    Code:
    if (location!=top.location)
    top.location = location;
    Instead of testing for location==top.location, you can test for the top location being a part of your domain:

    Code:
    if(!/http:\/\/(www\.)|()yourdomain\.com/.test(top.location.href))
    top.location.href = location.href;
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Code:
    if(!/http:\/\/(www\.)|()yourdomain\.com/.test(top.location.href))
    top.location.href = location.href;
    That will generate an 'access denied' error which must be caught:
    Code:
    try
    {
     if( top.document.domain != document.domain )
     ;
    } catch(e)
      {
       top.location.href = 'http://myurl.com';
      }

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's odd, because the other code works without a security problem. But in testing, try/catch doesn't seem to solve the issue. If I'm right about that, it may be because try/catch is only for errors. A security violation isn't an error. To allow try/catch to work around a security violation wouldn't be much security, now would it?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    My attitude to try-catch is that anything that doesn't support it doesn't support the today's web, and its users will expect and get constant trouble.
    A security violation quite plainly is an error.
    I just tried the exact code that I posted, loaded as a foreign iframe. It threw an exception and executed the catch block as expected (Moz,IE,Opera & Safari).

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I tried it with my code and it didn't execute the catch block. Well, if your code works, I've no problem with that, and brunomartelli's problem is basically solved, except for older browsers. I question primarily that, if it is a security violation, try catch shouldn't allow you to do what you couldn't otherwise do. If it does, where's the security?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    I question primarily that, if it is a security violation, try catch shouldn't allow you to do what you couldn't otherwise do. If it does, where's the security?
    It doesn't, it just branches to alternative code that doesn't violate security.

    Here's a try-catch free alternative that I tested successfully:
    Code:
    window.onerror=function()
    {
     alert('I will not be framed!'); 
     top.location.href='http://myURL.com';
    }
    
    if( self.document.domain != top.document.domain )
    ;
    
    window.onerror=null;

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by clueful View Post
    Here's a try-catch free alternative that I tested successfully:
    Code:
    window.onerror=function()
    {
     alert('I will not be framed!'); 
     top.location.href='http://myURL.com';
    }
    
    if( self.document.domain != top.document.domain )
    ;
    
    window.onerror=null;
    That looks really good, even though I know what mean when you talk about user agents that don't support try/catch, it just still seems prudent to avoid it where possible - or to shield browsers that cannot handle it from it. One of my pet peeves on this are the myriad of AJAX request scripts which routinely use it to determine the request method. Simple if/else if statements will work for that except as regards the two versions of Active X request objects supported by various versions of IE. For those try/catch statements though, cc script comments may be used to assure that only those versions of IE that would even be able to benefit or at least not choke on the code would parse those sections, ex snippet:

    Code:
    /*@cc_on @*/
    /*@if(@_jscript_version >= 5)
    try {
    http_request = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
    try {
    http_request = new ActiveXObject('Microsoft.XMLHTTP');
    } catch(e) {
    http_request = null;
    }
    }
    @end @*/
    Which would be seen as a script comment to all but IE 5 and above.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •