The quick version: I’ve found a way to abuse the login mechanism for both Twitter and Google to detect whether a user is logged in to that service. Facebook provides an API for this. So I provide a cross-browser javascript template that works for all 3 networks. If you want to get straight to the code jump to the implementation section or check out the Social Network Login Status Detector Demo.
Introduction
I was interested in seeing whether it would be possible to track which social networks a website visitor is logged into at the time of their visit; it could be cool for selecting which social media buttons you show them, what sort of marketing you do to them, or simply to evaluate whether you should be participating more on a certain social network. I was interested in Facebook, Twitter and Google+; as an SEO I was also interested in whether people were logged into a general Google account so I could compare which percentage of those had a Google+ account.
A quick search turned up an interesting post from Mike Cardwell who had a method for doing this for Facebook, Twitter and Gmail, but unfortunately it didn’t work in Internet Explorer. Secondly, I knew there was a better method than Mike’s for Facebook, which I’d seen presented by Mat Clayton of Mixcloud; he uses Facebook’s API to do the same thing (see slide 15). Mat’s method works great across browsers, so that solved the Facebook side of this.
Finding a way in to Twitter and Google+
Wat I needed was a method for detecting whether a visitor to my site was logged in to Twitter, Google and more specifically Google+.
Thanks to abraham from Hacker News I discovered that Twitter has an undocumented endpoint that simply returns true or false for whether the current user is logged in! It is very simple:
-
<script>
-
function twitterLoginStatus(state) {
-
alert(state);
-
}
-
</script>
-
<script src='https://api.twitter.com/sessions/present.js?callback=twitterLoginStatus'></script>
However, due to boring technical details concerning MIME types this code doesn’t work on IE9, which (unfortunately) for many purposes makes it less than ideal.
Browsers nowadays are very sensitive to cross site requests and the all to common exploits that abuse them, and so unless the 3rd party site plans to allow it using javascript for this is probably going to be difficult. The other great way to make cross domain requests is with image tags.
Tricking login mechanisms
I came up with the theory that I needed to try to access and image on Twitter/Google’s sites that would only be available to users when they are logged in. Using javascript I could detect whether the image loaded or not and thus determine whether the user was loggedin. However, these are obviously going to be few and far between (image assets are often static and so on CDNs and/or not protected in such a manner), if they exist at all (I didn’t find any), so I was back to square one. I needed a protected area of the site, but needed the file contents to be an image.
My winning moment was realising that some naive login systems might be open to abuse for exactly this purpose. It is often the case that you try to access a specific page on a site, lets say the “Upload a photo” page but you need to be logged in to do so. If you are not logged into the site in question, when you visit the URL the page redirects to the Login page to authenticate you are who you say you are; however the site wants to be helpful and send you to the page you were looking for so they keep a track of that target page in the URL as a parameter and then helpfully redirect you to that page after login is complete.
What happens if you visit the login page with a ‘redirect on login’ parameter and you are already logged in? When implemented in a naive fashion you are simply immediately redirected to the page specified in the parameter. Some sites limit that parameter to being another page on the same domain, but we’ll see that doesn’t help for this trick.
This mechanism is open to abuse in exactly the way I needed; I could set the ‘redirect on login’ page to be an image file on the same domain. For example:
-
<img src="https://twitter.com/login?redirect_after_login=%2Fimages%2Fspinner.gif" />
In this example, if I am logged in Twitter is kind enough to 302 redirect me to the image file I specified, but if I am not logged in I am show the login page. It turns out that both Twitter and Google’s login mechanisms are susceptible to exactly this trick. It seems LinkedIn and Tumblr are currently immune to this, though I didn’t dig too deep so there might be another redirect URL for them.
Putting it all together
From this point on it was quite easy to hack together some javascript; just stick this code in the <head></head> section of your page:
-
<script type="text/javascript">
-
function show_login_status(network, status)
-
{
-
if (status)
-
{
-
alert("Logged in to " + network);
-
}else{
-
alert("Not logged in to " + network);
-
}
-
}
-
</script>
Then, anywhere in your code that seems like a nice place stick this HTML:
-
<img style="display:none;"
-
onload="show_login_status('Google', true)"
-
onerror="show_login_status('Google', false)"
-
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
-
/>
-
-
<img style="display:none;"
-
onload="show_login_status('GooglePlus', true)"
-
onerror="show_login_status('GooglePlus', false)"
-
src="https://plus.google.com/up/?continue=https://www.google.com/intl/en/images/logos/accounts_logo.png&type=st&gpsrc=ogpy0"
-
/>
-
-
<img style="display:none;" src="https://twitter.com/login?redirect_after_login=%2Fimages%2Fspinner.gif" onload="show_login_status('Twitter', true)" onerror="show_login_status('Twitter', false)" />
-
-
<div id="fb-root"></div>
Finally, somewhere after that HTML stick this Javascript:
-
<script>
-
window.fbAsyncInit = function(){
-
FB.init({ appId:'xxxxxxxxxxxx', status:true, cookie:true, xfbml:true});
-
FB.getLoginStatus(function(response){
-
if (response.status != "unknown")
-
{
-
show_login_status("Facebook", true);
-
}else{
-
show_login_status("Facebook", false);
-
}
-
});
-
};
-
// Load the SDK Asynchronously
-
(function(d){
-
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
-
js = d.createElement('script'); js.id = id; js.async = true;
-
js.src = "//connect.facebook.net/en_US/all.js";
-
d.getElementsByTagName('head')[0].appendChild(js);
-
}(document));
-
</script>
You will need to replace xxxxxxxxx above with the appID for an app created for your domain; if you don’t have one you can create one in about 60 seconds. Simply visit https://developers.facebook.com/apps whilst logged in to Facebook, and click “Create New App”. You will be prompted for a “Display Name”, and you can enter any old dummy text here and press Continue. On the next page it is only necessary to fill out the “App Domain” and the “Website” with the URL of the domain you want to use this code on. Do that, save changes and grab the “App ID” from the top of the page and enter it in the code above.
You should be all set! Now you can change your alert() functions to do whatever you want based on the login status of the user. See a demo of it in action Social Network Login Status Detector Demo.
Wrap up
In my testing this worked on a range of versions of Firefox and Chrome, IE versions 7 and up, Safari and Opera. It may be that these loopholes get fixed, but in the meantime I implore you to only use this in nice ways. There is an argument that a 3rd party even knowing what other sites you are logged into is a breach of your privacy, and I can certainly see why some people would feel like that (especially if this was scaled up to more personal sites that you might be logged into). If you want to prevent this then for Firefox you can try RequestPolicy or NoScript. For Chrome you can give ScriptNo a shot. On IE you can try giving Firefox or Chrome a try. 😉
However, I do also think that this sort of thing can be used in good ways – serving only a subset of social buttons to your users, or determining whether you should be providing support on a given social platform etc. If anyone has any nice suggestions for other ways you could use (nicely) use this, I’d love to hear.


毎日記事
December 2, 2015 at 6:22 amトレーナー。
毎日記事
詳しくは
December 2, 2015 at 6:23 am場合そこに二つのタイプがはっきりとあります。
詳しくは
関連記事
December 2, 2015 at 6:23 am大商人のための仰々しいローンかどうか。
関連記事
お勧め記事
December 2, 2015 at 6:23 am単純なオプションは、彼らは、そのようなもだまされやすい人に近づいソーシングウェブのような設計上の特徴を、使用することができますどのようなライオンに存在するこれらの神経物質でシールド。
お勧め記事
deion sanders fsu baseball jersey 529
December 2, 2015 at 6:27 ampanerai watch costco
dior homme genesis
barbour classic bedale jacket review
juicy couture perfume nordstrom
fifa 16 coins cheap usd 1gb
kenneth cole wool pea coat reviews
deion sanders fsu baseball jersey 529
Eduardo
December 2, 2015 at 6:33 amThere is certainly a great deal to learn about this subject.
I like all the points you have made.
longchamps sac.fr
December 2, 2015 at 6:43 amsergio rossi 34 weeks
karen millen grey coat zara
celine inspired mini bag
philadelphia eagles jersey 12 weather
andrew luck game worn jersey auction
ugg website 4chan
Michael Kors Exotic Yellow Satchel Bags Outlet Coupon
longchamp outlet tokyo shopping
Maggie
December 2, 2015 at 6:46 amYes! Finally someone writes about bankruptcy lawyers.
tods sale shop review
December 2, 2015 at 6:53 amrebecca minkoff biscuit recipe
tods handbags gred aaa watch
49ers Jerseys Official Shop
December 2, 2015 at 6:53 amCheap Jerseys,Buy our official shop online jerseys top five seller – San Francisco 49ers,save up to
50% off.China nfl apparel supplier offer at the wholesale price.
more from : 49ers Jerseys Official Shop
adidas predator instinct
December 2, 2015 at 6:57 amnew balance 574 all blue
north face hyvent ladies coat
hermes watch dressage
panerai ferrari wall clock
pandora birthday charms 50th quotes
adidas predator instinct
panerai fiddy joke
December 2, 2015 at 7:05 amarcteryx tactical
nike outlet flushing queens
furla mini 690
panerai watch 176 series ebay
dvd ripping tools
December 2, 2015 at 7:14 amI’ve been browsing online more than 4 hours today, yet I never found any interesting
article like yours. It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the
internet will be a lot more useful than ever before.
parajumpers gobi woman
December 2, 2015 at 7:23 amtiffany grant fdu
wholesale ornaments for christmas tree quilts
parajumpers light long bear rope jeux
sunglasses outlet portsmouth jobs
December 2, 2015 at 7:27 ammoncler store salzburg
haglofs essens ii down jacket
ugg kensington italia
henri lloyd coats sale
roger vivier store locator 85009
dior handbags celebrities
philadelphia eagles black jersey record
geox patrick cox uk
sunglasses hut outlet canada fake
dior homme cologne preço
December 2, 2015 at 7:36 amstella mccartney head office uk
dior homme cologne preço
Isaac
December 2, 2015 at 7:51 amHey there just wanted to give you a quick heads up.
The words in your article seem to be running off the screen in Safari.
I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know.
The layout look great though! Hope you get the problem resolved
soon. Many thanks
jack wolfskin zelt big sky resort rt
December 2, 2015 at 7:56 amstella mccartney baby amazon
raymond weil watches noemia
jack wolfskin travel lodge rt 2015
alexander wang juliana sandal
December 2, 2015 at 8:14 amdvf episodes
detroit lions jersey cheap us
iwc amg black series prezzo
calvin klein one summer zielony
dkny instagram
tods bags nordstrom
alexander wang juliana sandal
geox odina wedge
December 2, 2015 at 8:21 amdallas cowboys jersey discount sales
vivienne westwood rubber heart shoes
asics lyte cheap
geox odina wedge
parajumpers vancouver bc zip
December 2, 2015 at 8:25 amroger vivier shoes polyvore
balmain jeans uk
parajumpers windbreaker ike menn jakke bl
vivienne westwood book 2015 download
December 2, 2015 at 8:53 amparajumpers store nyc midtown
baltimore ravens t shirts uk designer
wholesale wooden christmas ornaments ideas
belstaff leather sale
vivienne westwood and her husband
wholesale garden ornaments perth zoo
December 2, 2015 at 9:02 amugg coupon code dealigg
miu miu outlet the mall
wholesale glass snowflake ornaments uk
parajumpers long bear femme sweat
December 2, 2015 at 9:19 amhouston texans jersey white castle
beats by dr dre headphones online india
reebok shaqnosis nba 2k13
canada goose snow mantra us
parajumpers jacken sale herren jacken
henri lloyd tp2 ventura jacke
December 2, 2015 at 9:32 ambcbgmaxazria eau de parfum review
tiffany heart key diamond charm
deion sanders ravens jersey for sale cheap
darren mcfadden jersey authentic ハンバーガー
henri lloyd tp2 ventura jacke
fitflop black 6
December 2, 2015 at 9:47 amkate spade for sale philippines
beats studio pro wireless 6200
miu miu bedazzled heels
roger vivier history youtube
dallas cowboys dog jersey xs dje
toms river 9 digit zip code
fitflop black 6
iwc las vegas quotes
December 2, 2015 at 9:52 amjack wolfskin hut supplex vent hat
new york giants retired jerseys wholesale
iwc las vegas quotes
omega center robinson pa phone
December 2, 2015 at 9:59 amhenri lloyd fabiola top
panerai online shop
tory burch outlet dawsonville ga outlets
bcbgmaxazria fall 2015 essay
vibram fivefingers kso mens closeout
omega center robinson pa phone
prada shoes at macys
December 2, 2015 at 10:01 amroger vivier u bag it
valentino uk site down
prada shoes at macys
mont blanc meisterstuck 7039 watch 32
December 2, 2015 at 10:21 amvivienne westwood womens dresses uk
Pas Cher Chestnut UGG Ascot 5775 Boots Paris
geox loafers india
pittsburgh steelers miller jersey facebook
mont blanc wallet sale uk gumtree
moncler jacken outlet erfahrungen
December 2, 2015 at 10:25 amlongchamp sale boston 2015
chanel boy 8 mirror
jaeger lecoultre 976 review questions
andrew luck jersey small towns
gucci bags history
dkny wool coat ruffle
moncler jacken outlet erfahrungen