Thursday, January 12, 2012

Dealing with zombie Facebook cookies...

Not able to logout in your Facebook Connect applications? Facebook recently pushed a change in the past day or so such that the domain= parameter is now added to your fbsr_ cookies. If you find that your cookies are not being removed after a user attemps to logout, chances are you're experiencing the repercussions of these recent changes.

In the timestamped version (1326413659,169943147), there is a section that was added to the Facebook Connect Library:

23402348 }
23412349 return b;
23422350 },
2351 loadMeta: function() {
2352 var a = document.cookie.match('\\bfbm_' + FB._apiKey + '="([^;]*)\\b'),
2353 b;
2354 if (a) {
2355 b = FB.QS.decode(a[1]);
2356 if (!FB.Cookie._domain) FB.Cookie._domain = b.base_domain;
2357 }
2358 return b;
2359 },
23432360 loadSignedRequest: function() {
23442361 var a = document.cookie.match('\\bfbsr_' + FB._apiKey + '=([^;]*)\\b');
23452362 if (!a) return null;

The regexp apparently fails to match because there is an extra quotation mark. Instead of:
var a = document.cookie.match('\\bfbm_' + FB._apiKey + '="([^;]*)\\b'), b;
It should be:
var a = document.cookie.match('\\bfbm_' + FB._apiKey + '=([^;]*)\\b'), b;
If you inspect document.cookie in a JavaScript console, you'll see no sign of how this regexp could match (i.e. the regexp would match fbm_1234="abcde" but not fm_1234=abcde). You can also use the Chrome/Safari Web Inspector, put breakpoints on this function, and use the deminifier feature (look for the {} icon at the bottom) to double-check.

Background info: Before the OAuth2 migration, the fbs_ cookie was used. Included in the fbs_cookie was a query string that needed to be decoded and the base_domain parameter used for the domain= cookie parameter.(For more background about how to set or delete cookies in JavaScript, see: http://www.quirksmode.org/js/cookies.html.)

Cookies be cleared by setting the expiration date to 01/01/1970 GMT. However, most browsers won't know how to delete the cookie unless the path= and domain= parameters are set correctly too. In other words, if you had a cookie named fbsr_1234, with domain=abc.com, the browser would not be able to delete it unless you also specified this parameter.

Until now, OAuth2 didn't include the domain= parameter in fbsr_ cookies. But with today's recent push, it is now being used. The result? If you had an old cookie without this domain= parameter and attempted to logout with this new JavaScript code, you might find that you're unable to clear them. You may also encounter strange logout issues in general and not see the fbsr_ cookie cleared correctly.

When you logout, a cross-domain request gets sent to Facebook to invalidate the session. When you hit reload and invoke another FB.init() command, another request gets sent to Facebook's site -- since FB recognizes the existing cookie as invalid, it correctly deletes the cookie from your browser (the cross-domain response appears to pass in the domain= parameter correctly). Unfortunately the clearing of the cookie initially doesn't work because the fbm_ cookie isn't parsed correctly because of this regexp bug.

Facebook will most likely fix this issue soon, though in the interim your users may not be able to logout of your app. One thing we've done is to use a server-side code to instruct the browser to clear the cookie, though it may not always work unless your page invokes FB.init() properly and receives back a cross-domain request from Facebook to set the domain= properly.

You can examine this code for how you can delete cookies from the server-side:

https://github.com/rogerhu/facebook_oauth2/blob/master/views.py

Want to track Facebook Connect JavaScript changes? Check out:

Tuesday, January 10, 2012

Using FTP/TLS with Python 2.6...

FTP over SSL/TLS can be supported on Python 2.6. If you have prod machines that are running Python 2.6 and you want to avoid upgrading, you can do the following:

wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz

...untar the file and grab the Lib/ftplib.py file.

You can then do:
from ftplib import FTP_TLS

ftps = FTP_TLS('ftp.mysite.com')
ftps.login('userid', 'pw')
ftps.prot_p()
ftps.retrlines('LIST')

To download a file, you would do:
ftps.retrbinary('RETR file.bin', open('output.bin', 'wb').write)

or to upload a file, you would do something on the order of (borrowed from http://www.daniweb.com/software-development/python/threads/110195)
def upload(ftp, file):
  ext = os.path.splitext(file)[1]
  if ext in (".txt", ".htm", ".html"):
     ftp.storlines("STOR %s" % (file), open(file))
  else:
     print ftp.storbinary("STOR %s" % (file), open(file, "rb"), 1024)

jQuery UI 1.9

Cool slide presentation about jQuery UI 1.9..

http://ajpiano.com/widgetfactory/

Cisco Unified Communications 500 Series - Cisco Smart Business Communication Systems

https://supportforums.cisco.com/docs/DOC-9772

Can the T1/E1 module on UC500 terminate Voice and Data?
The VWIC-2MFT-T1/E1 card on UC500 can only be used for Voice T1 termination. It cannot be used for terminating Data T1s. On UC500, this card does not support multiplexing of Voice and Data. For Data connectivity, using an ISR based T1/E1 is recommended.

What are the total number of PSTN interfaces that the UC500 can support?
Depending on the UC500 model or SKU - can have any of the below:
4 to 12 FXO ports or 2 to 6 BRI ports (VIC slot can be used to add interfaces in certain model)
T1/E1 VWIC interface card for use in the 8-, 16-, and 32-user UC500 SKUs (VIC slot can be used to add this T1/E1 interface card)
UC500 48-user SKU is also available with integrated T1/E1 interface.

What T1 parameters are supported on the UC500 for voice termination?
The below parameters are supported:
T1 line coding = B8ZS
T1 framing = ESF
Interface switch Type for PRI - National with FAS (User side)
Hunt Type = two way, descending (channel 23 to 1)
Switch Protocol = See ISDN PRI switch-types above

Tuesday, January 3, 2012

Tracking the SWF file..

Facebook doesn't often change the SWF file that is used for its cross-domain handler, but sometimes it's useful to download automatically the right binary file:


SWF_FILE=`grep --color=none all_deminified.js | "_swfPath\": " | sed -E "s/(.*?)swfPath\": \"rsrc.php(.*?.swf)\"/\2/" | sed 's/\\\\//g'`
/usr/bin/wget "http://static.ak.fbcdn.net/rsrc.php/${SWF_FILE}" -O ${SWF_OUTPUT}


https://github.com/rogerhu/connect-js/blob/master/update_fb_github.sh

Monday, January 2, 2012

Friday, December 23, 2011

Changes in Facebook's swf flash handler..

Ever since Facebook introduced a change in their Facebook Connect Library that caused severe login issues for IE users that lasted for more than a week, we've created scripts to monitor Facebook's JavaScript Connect Library to detect for any changes that might affect our users. Nate Frieldy first created the first version to monitor for diffs, and I soon forked it here to monitor for diffs that span more than just the changes that happen on the 1st line that indicates timestamp changes.

On December 8, 2011, our diff detection scripts picked up this change:

1 /*1323218538,169893481,JIT Construction: v482006,en_US*/
1 /*1323305592,169920374,JIT Construction: v482779,en_US*/
22
33 if (!window.FB) window.FB = {
44 _apiKey: null,
53615361 [10, 3, 181, 34],
53625362 [11, 0, 0]
53635363 ],
5364 "_swfPath": "rsrc.php\/v1\/yK\/r\/RIxWozDt5Qq.swf"
5364 "_swfPath": "rsrc.php\/v1\/yD\/r\/GL74y29Am1r.swf"
53655365 }, true);
53665366 FB.provide("XD", {
53675367 "_xdProxyUrl": "connect\/xd_proxy.php?version=3"

This SWF file is Facebook's cross-domain handler for web browsers that don't implement HTML5 but can use a Flash-based version of HTML5's postMessage() function that allows messages to be passed between different domains. Facebook doesn't often recompile the SWF file, so this diff caught my attention. The most reliable decompiler I've found is Sothink's SWF decompiler, which can be used to export the ActionScript files with a 30-day trial (for more context about how to decompile, see http://hustoknow.blogspot.com/2011/06/facebooks-flash-xdcomm-receiver.html).

I've decompiled the SWF file and ActionScript files from http://static.ak.fbcdn.net/rsrc.php\/v1\/yD\/r\/GL74y29Am1r.swf and reviewed the diffs between the previously decompiled SWF with this one. If you were to compare the diff changes for the XdComm.as file, you would see:
15a16,17
> private static var initialized:Boolean = false;
> private static var origin_validated:Boolean = false;
20,21c22,29
< Security.allowDomain("*"); < Security.allowInsecureDomain("*"); --- > if (XdComm.initialized)
> {
> return;
> }
> XdComm.initialized = true;
> var _loc_1:* = PostMessage.getCurrentDomain();
> Security.allowDomain(_loc_1);
> Security.allowInsecureDomain(_loc_1);
51a60
> ExternalInterface.addCallback("postMessage_init", this.initPostMessage);
60a70,76
> private function initPostMessage(param1:String, param2:String) : void
> {
> origin_validated = true;
> this.postMessage.init(param1, param2);
> return;
> }// end function
>
164a181,189
> public static function proxy(param1:String, param2:String) : void
> {
> if (origin_validated)
> {
> ExternalInterface.call(param1, param2);
> }
> return;
> }// end function
>

The changes indicate that Facebook has tightened the cross-domain security policies. Instead of using wildcard domains to accept messages in its allowDomain() function, it now invokes a call to getCurrentDomain(), which is a function defined in the PostMessage.as file used to execute a call to document.domain, relying more on the browser to define the security restrictions.

Most of these change should not affect your users...just wished Facebook would discuss more what's going on behind the scenes since your apps may very well be using the Facebook Connect Library without realizing these changes are happening beneath you!

I've started to post the decompiled SWF files here:
https://github.com/rogerhu/connect-js/tree/master/swf

Note that these updates are only manually. If someone knows of an open-source SWF decompiler, then the diffs could be much more automated!