Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:29:48+00:00 2026-05-31T10:29:48+00:00

I have a window containing an iframe (same origin), so scripts from this iframe

  • 0

I have a window containing an iframe (same origin), so scripts from this iframe can access the top window’s attributes by simply referencing top.foo. I want to grant access to some of these attributes, and hide others via blacklist.

This is what I have so far:

(function(){
    var private = PrivateObject;
    Object.defineProperty(window, 'PrivateObject', {
        get: function getter() {
            if (!(getter.caller instanceof Function)) {
                throw 'You can\'t access PrivateObject from the iframe';
            }
            return private;
        },
        set: function setter(x) {
            if (!(setter.caller instanceof Function)) {
                throw 'You can\'t access PrivateObject from the iframe';
            }
            private = x;
        },
    });
})();

The basic idea behind this is that f.caller instanceof Function should detect calls from foreign window objects, since window1.Function !== window2.Function.

But this does not work if the accessors are called from top-level code, where f.caller === null. Any solutions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:29:49+00:00Added an answer on May 31, 2026 at 10:29 am

    For now, I’ve decided to go with the following approach, since I don’t think it’s possible to detect top-level calls:

    /**
    * Hide objects from access from other window objects. For example, this may be used to prevent access to
    * top.Ext from scipts inside iframes.
    * <strong>Warning:</strong> This does not work reliably, since calls from top-level code cannot be detected.
    * You may either <strong>allow all</strong> top-level access (from top and other windows), or <strong>disallow all</strong> top-level access.
    * Also remember that objects may have indirect references.
    * @param {Object} object The object whose properties shall be hidden
    * @param {Array|String} properties A comma-separated list or an array of property names
    * @param {Boolean} allowTopLevel <tt>true</tt> to allow access from top-level code. Defaults to <tt>false</tt>
    */
    hideObjectsFromFrames = function (object, properties, allowTopLevel) {
        if (typeof properties == 'string') {
            properties = properties.split(/ *, */);
        }
        Ext.each(properties, function (property) {
            var orig = object[property];
            if (allowTopLevel) { // checking outside the accessors improves performance
                Object.defineProperty(object, property, {
                    get: function g() {
                        if (g.caller && !(g.caller instanceof Function)) {
                            throw 'Security error. Attempt to access ' + property + ' from foreign window';
                        }
                        return orig;
                    },
                    set: function s(x) {
                        if (s.caller && !(s.caller instanceof Function)) {
                            throw 'Security error. Attempt to overwrite ' + property + ' from foreign window';
                        }
                        orig = x;
                    }
                });
            } else {
                Object.defineProperty(object, property, {
                    get: function g() {
                        if (!(g.caller instanceof Function)) {
                            throw 'Security error. Attempt to access ' + property + ' from foreign window';
                        }
                        return orig;
                    },
                    set: function s(x) {
                        if (!(s.caller instanceof Function)) {
                            throw 'Security error. Attempt to overwrite ' + property + ' from foreign window';
                        }
                        orig = x;
                    }
                });
            }
        });
    };
    

    If anyone comes up with a better solution, please let me know!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window containing a form (formPanel). Users can show this window clicking
I have a greasemonkey script that opens an iframe containing a form from a
I have window containing multiple panels. I don't have access to window code. (I
I don't have access to this iframe's source directly, so I would like to
I have a general question. I would like to have a window containing some
I have window form in my WPF Application when I open new window from
I have a window (derived from JFrame) and I want to disable the close
I have a window in WPF which shows some media contents. This content contains
I have a link which opens up a Jquery UI Dialog containing an iframe.
In our application, we have a window containing a Grid and two buttons -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.