-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Labels
Description
As an F2 app, I'd like to specify who can receive the events I broadcast. This is required to prevent nefarious apps from spying on the data I'm sending.
My proposed API is below. It's targeted at F2 version 2, which is AMD compliant.
// F2 library definition
// ----------------------------------------------------------------------------
define('F2', [], function() {
var F2 = function(options) {
if (options) {
this._trustedAppIds = options.trustedAppIds;
}
};
F2.prototype = {
spawn: function(options) {
return new F2(options);
},
emit: function(name, data) {
// Normal messaging
},
secureEmit: function(name, data) {
// Emit to the trusted AppIds only
}
};
return new F2();
});
// AppClass from "Red" client
// ----------------------------------------------------------------------------
define('com_red_appId', ['F2'], function(F2) {
F2 = F2.spawn({
trustedAppIds: [
'com_red_*',
'com_blue_*'
]
});
// Emit an event to everyone
F2.emit('global broadcast');
// Send an event to all appIds that begin with "com_red_" or "com_blue_"
F2.secureEmit('secret password', 'hopscotch');
});
// AppClass from "Blue" client
// ----------------------------------------------------------------------------
define('com_blue_appId', ['F2'], function(F2) {
F2 = F2.spawn({
trustedAppIds: [
'com_blue_*'
]
});
// Send an event to all appIds that begin with "com_blue_"
F2.secureEmit('secret password', 'butterscotch');
});The results of the example are that com_red_appid will broadcast its secure events to any "red" or "blue" apps. The other app, com_blue_appid, will only send its secure messages to "blue" apps.
The secureEmit could be replaced with an additional parameter to the regular emit event. The community can decide which is the better API.
I believe this example fulfills the following goals of secure messaging:
- Prevent "F2.Events.emit = function() { }" hijacking
- Apps can sandbox themselves without the container
- Sandboxing is optional
- Sandboxed apps can emit global events
- Apps can be sandboxed with any app from any domain
Reactions are currently unavailable