The Facebook JS SDK is causing an XSS error and returning a "user_denied" response, even though the Auth Popup for FB.Login is not being

I currently have a Facebook canvas app located at

Previously, I was using an anchor link to direct users to the OAUTH login flow.

After implementing the Facebook JavaScript SDK, I followed this logic:

1) Initialization of the FB API

    FB.init({
    appId: 'XXXXXXXXXXXXXX',
    xfbml: true, 
    cookie: true,  
    oauth : true, 
    channelUrl: 'http://www.niteflymobile.com/insideny/channel.html' },
    {scope: 'email'});

2) Checking for login status

    FB.getLoginStatus(function(response)    { ... } )

3) If the user is logged in (response.status == "connected"), set a proper cookie and redirect them to the logged-in page.

4) The issue arises here: if response.status != "connected" (usually returns "not_authorized" for new users), then initiate a call to FB.login(function(response) { ... }).

4a) The FB.login function results in 2 errors like the following:

"Unsafe JavaScript attempt to access frame with URL static.ak.fbcdn.net/connect/xd_proxy.php?version=3&error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.#cb=f22684144&origin=http%3a%2F%2Fwww.niteflymobile.com%2Ff185641ad8&relation=opener&transport=postmessage&frame=f39056acd8 from frame with URL www.niteflymobile.com/insideny/#. Domains, protocols and ports must match."

(http:// removed from both links to comply with SO rules for new users)

In addition, the returned object that I wrote to the console contains a null authResponse and the status is "unknown" instead of "not_authorized."

The main problem here is that the authorization popup appears blank and quickly closes without any user interaction.

Any suggestions, assistance, or insights would be greatly appreciated, as I've been struggling with this for quite some time now, and I suspect it may be a simple mistake that I can't see because I'm too involved in it.

I recently disabled sandbox mode - could that have caused this issue?

FULL CODE BELOW:

     $('.fb_link').click(function() {
            FB.init({appId: 'XXXXXXXXXX', xfbml: true, cookie: true,  oauth : true, channelUrl: 'http://www.niteflymobile.com/insideny/channel.html' },{scope: 'email'});
                //setup fb login check
                 FB.getLoginStatus(function(response)   {
                    if(response)    {
                        console.log(response);
                    if(response.status == "connected")  {

                            alert(response.status);
                            alert(response.authResponse.userID+"preajax");
                            //jquery cookie write
                            $.cookie('fbID', response.authResponse.userID, { expires: 29, path: '/' });
                            //secondary cookie write using only javascript
                            createCookie('fbID', response.authResponse.userID, 29);
                            //bandaid to fire ajax to set cookie on server side if the js side fails
                            var fbID_check = readCookie('fbID');
                            if(fbID_check)  {
                                alert("fbID cookie set "+fbID_check);
                                window.location = "http://apps.facebook.com/insideny/";
                            }
                            else    {
                                url_vars = "fbID="+response.authResponse.userID;
                                $.ajax({ 
                                    type: "POST",
                                    url: "set_fb_cookie.php",
                                    data: url_vars,  
                                    success: function(data){

                                        alert(data + "passed back from ajax");
                                        var fbID_check_2 = readCookie("fbID");
                                        alert(fbID_check_2 + "read from cookie");
                                        window.location = "http://apps.facebook.com/insideny/";
                                    }

                                });
                                return false;
                            }

                            alert(response.authResponse.userID+"postajax");

                        }

                        else    {

                            FB.login(function(response) {
                                alert('here');
                                console.log(response);

                            });
                        }
                    }

                })
             })

UPDATE 8.12 @felipe-brahm

Tried the following code with the same effect (popup appears blank and closes down):

    $('.fb_link').click(function()  { 
    FB.init({appId: 'XXXXXXXXXXXXX', xfbml: true, cookie: true, oauth : true,          channelUrl: 'niteflymobile.com/insideny/channel.html'; },{scope: 'email'}); 
    FB.login(function(response) { 
    console.log(response); }) 
    })

Answer №1

Don't worry about the "Unsafe JavaScript attempt to access frame..." message. Despite it showing in the console, my app still functions properly.

If the popup isn't appearing, it could be due to the fact that most browsers require a window.open event to be triggered by a user-initiated action, such as a click.

Solution: To resolve this issue, prompt the user to click on a link that triggers the login function.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it advisable to combine ng-change with ng-blur in AngularJS?

Seeking clarification on the correct usage of AngularJS's ng-change and ng-blur from an expert. Specifically, when updating a form value. In the code snippet below, I have a dropdown where I would like to trigger overrideBusinessDec() when the user ...

Encountering an issue when attempting to access a string offset while creating a JSON object in PHP

After countless attempts and failed solutions, I find myself struggling to make this work. The scenario is as follows: I have an initially empty file named contact.json. If the file is empty, I need to add JSON data to it. If it already contains data, I ...

JQuery Function for Repeatedly Looping through Div Elements

I've been experimenting with creating a loop that alternates the fade-in and fade-out effects for different elements. This is what I have so far: setInterval(function() { jQuery(".loop").each(function(index, k) { jQuery(this).delay(1200 ...

Monitoring Changes in an Array of Objects with Angular's $watch Feature

Imagine having an array of animal objects linked to the scope. Each object contains a 'name' field and a 'sound' field. After that, I set up a $watch on the array with the objectEquality flag set to true (the third argument). Then, in ...

Erasing a comment creates empty spaces

I've encountered an issue with my idea whiteboard where removing comments leaves unwanted blank spaces between ideas. For example, if I have the following comments: But when I delete something: Is there a way to ensure that no gaps are left between ...

Is there a performance benefit to using node.js over client-side JavaScript in comparison to Chrome/V8?

Currently, I am working on a client-side javascript application for image manipulation. However, some of the operations are running quite slowly in the browser, taking about 2-3 seconds to complete. To address this issue, I am considering implementing a s ...

What is the best way to locate the position of a different element within ReactJS?

Within my parent element, I have two child elements. The second child has the capability to be dragged into the first child. Upon successful drag and drop into the first child, a callback function will be triggered. What is the best way for me to determi ...

What is the best way to refresh a page during an ajax call while also resetting all form fields?

Each time an ajax request is made, the page should refresh without clearing all form fields upon loading Custom Form <form method='post'> <input type='text' placeholder='product'/> <input type='number&a ...

Showing hidden errors in specific browsers via JavaScript

I was struggling to make the code work on certain browsers. The code you see in the resource URL below has been a collection of work-around codes to get it functioning, especially for Android browsers and Windows 8. It might be a bit sketchy as a result. ...

Creating visually appealing Jquery-ui tab designs

Trying to customize the jquery tabs, I experimented with styling them to my liking. One thing I did was attempt to reduce the size of the tabs by adding a height:45px; to the UI stylesheet shown below. .ui-tabs-vertical .ui-tabs-nav li { clear: left; ...

Tips for preventing php mail() from being marked as spam by recipients

I'm facing an issue with my code where the registration emails from my website are going into the spam folder. Here is a screenshot of the email that ended up in spam: https://i.stack.imgur.com/7jBV3.png It also shows 'via gator4168.hostgator.co ...

How to Ensure the Security of JSONP?

Currently, I have a script that utilizes JSONP for conducting cross domain ajax calls. While it is functioning effectively, I am pondering if there is a method to hinder other websites from accessing and retrieving data from these particular URLs. My goal ...

Dynamic TextField sizing

I am currently facing an issue while displaying data on a webpage using TextField component from @material-ui. Each record of data has varying lengths, making most values appear unattractive (occupying only 10% of the textfield width). Even though I am ut ...

How to access a $scope variable in the same Angular controller function from outside the function

As a newcomer to AngularJS, I have a question about accessing my $scope variable from an outside function within the same controller. How can I achieve this? Below is the code snippet: .controller('RekapCtrl', ['$scope', '$timeout ...

What steps should I take to resolve a plugin error specifically related to index.js while using Cypress?

I am encountering an error in Cypress A plugin has thrown the following error, causing our tests to stop running due to a plugin crash. Please verify your plugins file (/home/dev2/Desktop/kavitaSeffcon/CypressProject/cypress/plugins/index.js) Error: ENOE ...

Angular ng-if directive contains a specific class

I am trying to create a directive that will only be active when an element has a specific class. I have tried the following code: <feedback-analytics ng-if="$('#analyticTab').hasClass('active')"></feedback-analytics> Unfor ...

Having trouble importing Bootstrap into Next.js? It seems like the issue may be related to the

I am currently facing an issue with importing bootstrap 5.3.2 (not react-bootstrap) into my NextJS 14.1.0 project that utilizes the new App Router. My goal is to strategically utilize individual Bootstrap components (not through data-attrs). I managed to ...

Encountering an issue with jQuery ajax when attempting to make a post

I am having trouble making a rest service call from JQuery ajax using the POST method. Below is my code: <!DOCTYPE html> <html> <head> <script src="lib/js/jquery/jquery-1.7.2.min.js"></script> </head> <body> & ...

Trouble with Bootstrap accordion staying open even after a different one is chosen

Looking for assistance! I am encountering an issue with using jQuery on Bootstrap. The accordion feature is not functioning correctly as it fails to collapse when another section is selected. https://i.stack.imgur.com/uiZPh.png The problem arises when th ...

Calculate the total amount from the selected items on the list, depending on the clicked ('active') element

My main objective is to achieve the following: Before any clicks || After the user selects the desired item After conducting some research, I successfully implemented this using vue.js https://jsfiddle.net/Hanstopz/Lcnxtg51/10/ However, I encountered ...