Security/Reviews/Gaia/Contacts: Difference between revisions

From MozillaWiki
< Security‎ | Reviews‎ | Gaia
Jump to navigation Jump to search
(Created page with "=== App Review Details === * App: Contacts, which is part of the Communications application * Review Date: March 4th, 2013 * Review Lead: Stefan Arentz * Review Bug: {{bug|75473...")
 
(indications about the use of the datastore api)
 
(26 intermediate revisions by 2 users not shown)
Line 2: Line 2:


* App: Contacts, which is part of the Communications application
* App: Contacts, which is part of the Communications application
* Review Date: March 4th, 2013
* Review Date: November 19th, 2013
* Review Lead: Stefan Arentz
* Review Lead: Stéphanie Ouillon
* Review Bug: {{bug|754738}} [Security Review] B2G Gaia - Communications / Contacts
* Branch reviewed: master
* Dependency Tree: https://bugzilla.mozilla.org/showdependencytree.cgi?id=754738&hide_resolved=0
* Latest commit: https://github.com/mozilla-b2g/gaia/commit/6b8572b10572059a359ff0fc68a0e0b83eda250b


This review also covers the Facebook integration because that is mostly integrated in the Contacts application.
Please see page history for details of previous reviews.
 
This review does *not* cover the Facebook integration that is also part of the communications/contacts code. See separate [https://wiki.mozilla.org/Security/Reviews/Gaia/FacebookIntegration review].
A separate review focuses on the contacts import/export features of the app: [[/Import]].
 
Contacts are currenlty being moved to use the DataStore API. Another review may be conducted to focus on this implementation.


=== Overview ===
=== Overview ===
The Contacts app allows you to browse through a list of Contacts, to add, edit and delete each one of them.
A contact form allows you to edit several entries such as name, phone numbers, emails, addresses, and comments.
You can synchronize your contacts with Facebook, and import them from Google, Live, Facebook, your SIM card or your SD card.
You can also get a vCard by bluetooth. The Contacts API is based on the vCard file format. It implements the vCArd4/hCard 1.0 specifications. hCard is a microformat allowing a vCard to be embedded inside a HTML page. It identifies vCard properties to CSS class names.


===Architecture===
===Architecture===
The Contact apps is more a module  which is part of a bigger app Communications.
{{bug|847417}} points out security concerns about this architecture. The use of the new [https://wiki.mozilla.org/WebAPI/DataStore Datastore API] would be the first step to deal with it.
Permissions and privacy concerns: see [https://wiki.mozilla.org/WebAPI/ContactsAPI#permissions_and_privacy here].


====Components====
====Components====


The contacts app is part of a the communications application. This is an umbrella app that also contains the dialer app, the connect-to-facebook app and the first-time-setup app. I say 'app' here, but they are really just pages as part of the single communications app.


This is not great from a security point of view and should ideally be fixed in a future version. The best scenario is that these are three different applications. If they have to talk to eachother they should use WebActivities. This greatly reduces the attack surface.
====Relevant Source Code====
 
Source code can be found at https://github.com/mozilla-b2g/gaia/tree/master/apps/communications/contacts
 
 
OAuth2:
* oauth2/js/flow.js - the logic to obtain an access token through OAuth2
* oauth2/js/oauth2.js -
 
UI elements:
* elements/confirm.html
* elements/details.html
* elements/form.html
* elements/overlay.html
* elements/screenshot.html
* elements/search.html
* elements/settings.html
* elements/status.html
* elements/tag.html
 
contacts/js/:
* js/activities.js- handling activities
* js/contacts_cleaner.js - deleting contacts
* js/contacts_importer.js - main file to import contacts from external services
* js/contacts.js -  displaying contact info
* js/contacts_matcher.js
* js/contacts_matching_controller.js
* js/contacts_matching_ui.js
* js/contacts_merger.js
* js/contacts_shirtcuts.js
* js/contacts_tag.js
* js/fixed_header.js
* js/importer_ui.js - Contacts import UI
* js/import_init.js
* js/import_utils.js
* js/merger_adapter.js
* js/navigation.js
* js/service_extension.js - Connects to available external services to import contacts
* js/sms_integration.js - send a sms from the contact page
* js/value_selector.js


ISSUE: Contacts should be separated from contacts and maybe even facebook
Facebook specific code:
* js/fb_loader.js
* js/fb_resolver.js
* js/fb/fb_contact.js
* js/fb/fb_contact_utils.js
* js/fb/fb_data.js
* js/fb/fb_init.js
* js/fb/fb_link_init.js
* js/fb/fb_link.js
* js/fb/fb_messaging.js
* js/fb/fb_query.js
* js/fb/fb_utils.js
* js/fb/friends_list.js


* {{bug|847417}} Contacts should be turned into minimal standalone application
export/*: audited in the review of Import/Export Contacts
 
utilities:
* js/utilities/binary_search.js
* js/utilities/config.js
* js/utilities/confirm.js
* js/utilities/cookie.js - Cookies for local usage
* js/utilities/dom.js
* js/utilities/event_listeners.js
* js/utilities/extract_params.js - function to extract params in a url separated by ‘&’
* js/utilities/http_rest.js
* js/utilities/image_loader.js
* js/utilities/image_square.js
* js/utilities/import_from_vcard.js - Read vcard file imported from bluetooth
* js/utilities/import_sim_contacts.js - Import contacts from the SIM card
* js/utilities/normalizer.js
* js/utilities/overlay.js
* js/utilities/sdcard.js
* js/utilities/status.js
* js/utilities/templates.js - HTML template
* js/utilities/vcard_parser.js - Parse a vCard file (Quoted-Printable)


====Relevant Source Code====
views:
* js/views/details.js
* js/views/form.js - Form to add/update a contact:q
* js/views/list.js
* js/views/search.js
* js/views/settings.js


Source code can be found at https://github.com/mozilla-b2g/gaia/tree/v1-train/apps/communications/contacts


TODO List relevant files


====Permissions====
====Permissions====


The (communications) app has the following permissions:
The (communications) app has the following permissions (App permissions are documented on [https://developer.mozilla.org/en-US/Apps/Developing/App_permissions?redirectlocale=en-US&redirectslug=Web%2FApps%2FApp_permissions their MDN page]):
 
Certified
    "attention":{},
    "audio-channel-telephony":{},
    "audio-channel-ringer":{},
    "bluetooth":{},
    "idle":{},   
    "mobileconnection":{},
    "settings":{ "access": "readwrite" },
    "telephony":{},
    "time": {},
    "voicemail":{},
    "wifi-manage":{},
 
Privileged
    "contacts":{ "access": "readwrite" },
    "device-storage:sdcard": { "access": "readcreate" }
    "systemXHR": {},
 
Hosted
    "alarms": {},
    "desktop-notification":{},
    "storage": {},


*  "telephony":{},
*  "voicemail":{},
*  "contacts":{ "access": "readwrite" },
*  "mobileconnection":{},
*  "attention":{},
*  "settings":{ "access": "readwrite" },
*  "desktop-notification":{},
*  "alarms": {},
*  "systemXHR": {},
*  "wifi-manage":{},
*  "time": {},
*  "audio-channel-telephony":{},
*  "audio-channel-ringer":{},
*  "browser":{}


ISSUE: Because the communications app is an 'umbrella app' for dialer, contacts, first-time setup and some generic facebook code, it has more permissions than it needs to have. Ideally we separate the three applications in the communications app into three separate apps.
ISSUE: Because the communications app is an 'umbrella app' for dialer, contacts, first-time setup and some generic facebook code, it has more permissions than it needs to have. Ideally we separate the three applications in the communications app into three separate apps.


====Web Activity Handlers ====
====Web Activity Handlers ====


===== new =====
All activities are handled in https://github.com/mozilla-b2g/gaia/blob/v1-train/apps/communications/contacts/js/activities.js
 
Activities handled by the Contacts app are ‘new’, ‘pick’, ‘import’, ‘open’, and ‘update’. They may take as an argument/parameter the following objects:
* webcontacts/contact
* webcontacts/email
* webcontacts/tel
* text/vcard
 
The new activity is used to create a new contact. It opens the contact editor screen.


TODO
    "new": {
      "filters": {
        "type": "webcontacts/contact"
      },
      "disposition": "inline",
      "href": "/contacts/index.html?new",
      "returnValue": true
    },


===== update =====


TODO
The pick activity is used to choose a contact. It simply opens a contact picker and returns a contact, an email or a tel object..


===== pick =====
"pick": {
      "filters": {
        "type": {
          "required": true,
          "value": ["webcontacts/contact","webcontacts/email","webcontacts/tel"]
        }
      },
      "disposition": "inline",
      "href": "/contacts/index.html?pick",
      "returnValue": true
    },
 
Import a vcard from bluetooth:
    "import": {
      "filters": {
        "type": "text/vcard"
      },
      "disposition": "inline",
      "href": "/contacts/index.html?open",
      "returnValue": true
    },
 
Open a contact:
    "open": {
      "filters": {
        "type": "webcontacts/contact"
      },
      "disposition": "inline",
      "href": "/contacts/index.html?open",
      "returnValue": true
    },
 
Update a contact object:
      "update": {
      "filters": {
        "type": "webcontacts/contact"
      },
      "disposition": "inline",
      "href": "/contacts/index.html?update",
      "returnValue": true
    },
 
 
The actual contact editor is shown at https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/contacts/js/contacts.js#L53
 
 
The last review of the app raised concern about validating the ‘extras’ parameters, still valid :
* {{bug|847649}} Contacts' "new" activity does not validate parameters
* {{bug|847650}} Contacts' "new" activity is also "edit" in disguise


TODO


==== System Messages ====
==== System Messages ====
Line 75: Line 236:
     { "telephony-new-call": "/dialer/index.html#keyboard-view" },
     { "telephony-new-call": "/dialer/index.html#keyboard-view" },
     { "ussd-received": "/dialer/index.html#keyboard-view" }
     { "ussd-received": "/dialer/index.html#keyboard-view" }
   ]
   ],
 


The contacts app does not handle any of these messages. They are all for the Dialer and Facebook integration.
The contacts app does not handle any of these messages. They are all for the Dialer and Facebook integration.
Line 83: Line 245:
The <code>alarm</code> message is used by the facebook integration code to schedule periodic updates of the Facebook contact data.
The <code>alarm</code> message is used by the facebook integration code to schedule periodic updates of the Facebook contact data.


The code for this can be found in https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/facebook/js/fb_sync_init.js#L22
The code for this can be found in https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/facebook/js/fb_sync_init.js#L23


==== Post Messages ====
==== Post Messages ====


The dialer (and the other code in the communications app) depends on window.postMessage() and setEventHandler('message',...) to send and receive cross origin messages. Usually between different pages in the same app, like dialer/index.html and dialer/oncall.html but also for remote sites like for example when we integrate with Facebook.
postMessage is used in different places :
* In oauth, see the Import/Export contacts review. There are messages between the facebook and the contacts components inside the communications app, so they’re internal messages.
* Some messages are sent to fb.CONTACTS_APP_ORIGIN where CONTACTS_APP_ORIGIN = 'app://communications.gaiamobile.org’, so they’re for internal use also.


The app handles the following post messages:


* js/dialer.js:200
====Web Activity Usage ====
** "closing"
** "notification"
** "recent"
** "contactsiframe"
* js/oncall.js:505
** "exitCallScreen"
* js/ussd.js:33
** "reply"
** "close"
 
ISSUE: None of the handlers verify that the message originated from a trusted/expected source.
 
I was able to exploit this and let remote content post messages to the Dialer to trigger Missed Calls notifications to appear.
 
ACTION: Add strict checking of event sources as described on MDN at https://developer.mozilla.org/en-US/docs/DOM/window.postMessage#Security_concerns


* {{bug|845487}} Dialer responds to cross-origin messages without verifying the source (exploitable)
The contacts app uses MozActivity for the following:


====Web Activity Usage ====
* Create a new email when you tap an email address
* Pick an image for the contact sheet
* Create a new <code>websms/sms</code> when to send an sms from a contact sheer


The only WebActivity that the dialer uses is in they keypad where it sends out a "new" activity to create a "webcontacts/contact" for the current phone number. This is triggered by hitting the + button next to the dial button. It simply opens the contacts app in the Add Contact screen with the specified phone number filled in.
None of these do anything interesting except passing an email or phonenumber to the activity or grabbing a resulting image blob.


==== Notable Event Handlers ====
==== Notable Event Handlers ====
Line 120: Line 270:
====1. XSS & HTML Injection attacks====
====1. XSS & HTML Injection attacks====


None found. The dialer app has no text fields. The keypad only accepts user input through a limited on screen keyboard.
The app is pretty good at using templates and escaping html. There are however some cases where content is not escaped. These are all cases where the input is expected to be a number or a keyword with no possible side effects.


====2. Secure Communications ====
I recommend against using shortcuts like this. It is usually fine but it is better to escape as a rule than as an exception as experience shows that the best XSS exploits are when those 'known values' can somehow be modified in an unexpected way in an unexpected location.


===== Remote Services =====
There a few of these cases in views/details.js where <code>utils.templates.render()</code> is used.


The dialer does not directly talk to remote services. There is talk to Facebook through the Contacts but that will be looked at in the Contacts review.
====2. Secure Communications ====


===== BlueTooth =====
The app talks to Facebook, Google services, Live and BT Yahoo! through the Contacts integration. This is covered in the Facebook code review and the Import/Export feature review.


The dialer blindly accepts phone numbers from a bluetooth device, which are passed directly to <code>mozTelephony</code> without any further (input) validation. Since <code>mozTelephony</code> passes this data on to the RIL without validation, it opens up possibilities for RIL attacks.
====3. (Secure) data storage ====
 
* {{bug|845930}} Dialer does not validate phone numbers received via BlueTooth


====3. (Secure) data storage ====
The contacts are stored using the mozContacts API which uses IndexedDB under the covers. The app also uses async_storage, a wrapper around IndexedDB, to store settings and for example the Facebook oauth token.


The recent calls database is stored on the device using indexDB. The code for this is abstracted in <code>recents_db.js</code>. Looks pretty solid, no comments.
The mozContacts data is global to every app with contacts permission while the IndexedDB with app specific data is only available to the communications app. (Dialer, FTU, Contacts)


It also uses asyncStorage, which is implemented in <code>shared/js/async_storage.js</code>. The app stores the Facebook oauth token in there (the contacts app does, but it is checked in the dialer to see if facebook has been 'connected') and the time the call log was last visited.
The Facebook Contacts is currenlty being moved to use the Datastore API.  


There is nothing wrong with this approach, except that because the dialer is part of the communications 'umbrella' app, more code than needed has access to these databases. See:
  "datastores-owned": {
    "Gaia_Facebook_Friends": {
      "description": "Imported Facebook Friends"
    } 
  }


* {{bug|845945}} Dialer should be turned into minimal standalone application


====4. Denial of Service ====
====4. Denial of Service ====


* {{bug|845383}} Dialer accepts super long phone number which breaks the phone until reboot
The fields of a contact form are checked against very big chunks of data (it displayed “Infinity” in case of a really big string).


====5. Use of Privileged APIs ====
====5. Use of Privileged APIs ====


====6. Interfaces with other Apps/Content====
* mozContacts - store contacts
* mozMobileConnection - detect SIM card changes
* mozTelephony (via TelephonyHelper) - initiate calls
* mozIccManager - Export/import SIM contacts


Because the dialer is part of the communications app, things are complicated and less secure than they can be. The attack described in {{bug|845487}} is only possible because the dialer opens the contacts which opens a remote site, which really all happens in the same application.


It is highly recommended to split up the communications app into separate applications that talk to eachother through WebActivities. This minimizes the attack surface and also decreases the complexity of things having to work together. This results in easier to understand code and smaller attack surfaces.
====6. Interfaces with other Apps/Content====


==== 7. Oddities ====
==== 7. Oddities ====
The whole USSD code is a bit of a mystery and hard to play with for testing. It is difficult to find out what this code does in practice and how it can be attacked from the outside.


==== 8. Input Validation Problems ====
==== 8. Input Validation Problems ====


* {{bug|845361}} Dialer does not correctly validate input to the dial activity handler
No input validation is done in the activity handlers. Specifically the blind copying of data from the <code>new</code> activity to the page request params is troublesome as it looks like this is purely for internal usage.
* {{bug|845383}} Dialer accepts super long phone number which breaks the phone until reboot
* {{bug|845045}} Dialer can be tricked into displaying one number but dialing another
 
Note that all these issues are about phone numbers accepted through the dial activity. In general there is not enough / not strong enough checking of incoming data through activities.


=== Security Risks & Mitigating Controls ===
=== Security Risks & Mitigating Controls ===
Line 172: Line 319:
=== Actions & Recommendations ===
=== Actions & Recommendations ===


The dialer unnecessarily has access to all system settings. This is an issue with the Settings API that should be improved in a future version of Firefox OS:
The contacts app unnecessarily has access to all system settings. This is an issue with the Settings API that should be improved in a future version of Firefox OS:


* {{bug|841071}}  Settings are globally shared between applications
* {{bug|841071}}  Settings are globally shared between applications


The dialer is embedded in a bigger app, which is not great from a security pov:
The contacts app is embedded in a bigger app, which is not great from a security point of view:
 
* {{bug|847417}} Contacts should be turned into minimal standalone application
 
Usage of innerHTML:


* {{bug|845945}} Dialer should be turned into minimal standalone application
* {{bug|828751}} Favor use of createElement and textContent instead of innerHTML in Gaia:Contacts


Multiple input validation issues that need to be fixed:
It is not clear what the intent is of the "new" activity:


* {{bug|845383}} Dialer accepts super long phone number which breaks the phone until reboot
* {{bug|847650}} Contacts' "new" activity is also "edit" in disguise
* {{bug|845361}} Dialer does not correctly validate input to the dial activity handler
* {{bug|845045}} Dialer can be tricked into displaying one number but dialing another
* {{bug|845930}} Dialer does not validate phone numbers received via BlueTooth


The dialer does not verify the source of 'postMessage()' messages:
The "new" activity blindly accepts incoming parameters - no validation


* {{bug|845487}} Dialer responds to cross-origin messages without verifying the source (exploitable)
* {{bug|847649}} Contacts' "new" activity does not validate parameters

Latest revision as of 13:39, 20 November 2013

App Review Details

Please see page history for details of previous reviews.

This review does *not* cover the Facebook integration that is also part of the communications/contacts code. See separate review. A separate review focuses on the contacts import/export features of the app: /Import.

Contacts are currenlty being moved to use the DataStore API. Another review may be conducted to focus on this implementation.

Overview

The Contacts app allows you to browse through a list of Contacts, to add, edit and delete each one of them. A contact form allows you to edit several entries such as name, phone numbers, emails, addresses, and comments.

You can synchronize your contacts with Facebook, and import them from Google, Live, Facebook, your SIM card or your SD card.

You can also get a vCard by bluetooth. The Contacts API is based on the vCard file format. It implements the vCArd4/hCard 1.0 specifications. hCard is a microformat allowing a vCard to be embedded inside a HTML page. It identifies vCard properties to CSS class names.

Architecture

The Contact apps is more a module which is part of a bigger app Communications. bug 847417 points out security concerns about this architecture. The use of the new Datastore API would be the first step to deal with it.

Permissions and privacy concerns: see here.

Components

Relevant Source Code

Source code can be found at https://github.com/mozilla-b2g/gaia/tree/master/apps/communications/contacts


OAuth2:

  • oauth2/js/flow.js - the logic to obtain an access token through OAuth2
  • oauth2/js/oauth2.js -

UI elements:

  • elements/confirm.html
  • elements/details.html
  • elements/form.html
  • elements/overlay.html
  • elements/screenshot.html
  • elements/search.html
  • elements/settings.html
  • elements/status.html
  • elements/tag.html

contacts/js/:

  • js/activities.js- handling activities
  • js/contacts_cleaner.js - deleting contacts
  • js/contacts_importer.js - main file to import contacts from external services
  • js/contacts.js - displaying contact info
  • js/contacts_matcher.js
  • js/contacts_matching_controller.js
  • js/contacts_matching_ui.js
  • js/contacts_merger.js
  • js/contacts_shirtcuts.js
  • js/contacts_tag.js
  • js/fixed_header.js
  • js/importer_ui.js - Contacts import UI
  • js/import_init.js
  • js/import_utils.js
  • js/merger_adapter.js
  • js/navigation.js
  • js/service_extension.js - Connects to available external services to import contacts
  • js/sms_integration.js - send a sms from the contact page
  • js/value_selector.js

Facebook specific code:

  • js/fb_loader.js
  • js/fb_resolver.js
  • js/fb/fb_contact.js
  • js/fb/fb_contact_utils.js
  • js/fb/fb_data.js
  • js/fb/fb_init.js
  • js/fb/fb_link_init.js
  • js/fb/fb_link.js
  • js/fb/fb_messaging.js
  • js/fb/fb_query.js
  • js/fb/fb_utils.js
  • js/fb/friends_list.js

export/*: audited in the review of Import/Export Contacts

utilities:

  • js/utilities/binary_search.js
  • js/utilities/config.js
  • js/utilities/confirm.js
  • js/utilities/cookie.js - Cookies for local usage
  • js/utilities/dom.js
  • js/utilities/event_listeners.js
  • js/utilities/extract_params.js - function to extract params in a url separated by ‘&’
  • js/utilities/http_rest.js
  • js/utilities/image_loader.js
  • js/utilities/image_square.js
  • js/utilities/import_from_vcard.js - Read vcard file imported from bluetooth
  • js/utilities/import_sim_contacts.js - Import contacts from the SIM card
  • js/utilities/normalizer.js
  • js/utilities/overlay.js
  • js/utilities/sdcard.js
  • js/utilities/status.js
  • js/utilities/templates.js - HTML template
  • js/utilities/vcard_parser.js - Parse a vCard file (Quoted-Printable)

views:

  • js/views/details.js
  • js/views/form.js - Form to add/update a contact:q
  • js/views/list.js
  • js/views/search.js
  • js/views/settings.js


Permissions

The (communications) app has the following permissions (App permissions are documented on their MDN page):

Certified

   "attention":{}, 
   "audio-channel-telephony":{},
   "audio-channel-ringer":{},
   "bluetooth":{},
   "idle":{},    
   "mobileconnection":{},
   "settings":{ "access": "readwrite" },
   "telephony":{},
   "time": {},
   "voicemail":{},
   "wifi-manage":{},

Privileged

   "contacts":{ "access": "readwrite" },
   "device-storage:sdcard": { "access": "readcreate" }
   "systemXHR": {},

Hosted

   "alarms": {},
   "desktop-notification":{},
   "storage": {},


ISSUE: Because the communications app is an 'umbrella app' for dialer, contacts, first-time setup and some generic facebook code, it has more permissions than it needs to have. Ideally we separate the three applications in the communications app into three separate apps.


Web Activity Handlers

All activities are handled in https://github.com/mozilla-b2g/gaia/blob/v1-train/apps/communications/contacts/js/activities.js

Activities handled by the Contacts app are ‘new’, ‘pick’, ‘import’, ‘open’, and ‘update’. They may take as an argument/parameter the following objects:

  • webcontacts/contact
  • webcontacts/email
  • webcontacts/tel
  • text/vcard

The new activity is used to create a new contact. It opens the contact editor screen.

   "new": {
     "filters": {
       "type": "webcontacts/contact"
     },
     "disposition": "inline",
     "href": "/contacts/index.html?new",
     "returnValue": true
   },


The pick activity is used to choose a contact. It simply opens a contact picker and returns a contact, an email or a tel object..

"pick": {

     "filters": {
       "type": {
         "required": true,
         "value": ["webcontacts/contact","webcontacts/email","webcontacts/tel"]
       }
      },
     "disposition": "inline",
     "href": "/contacts/index.html?pick",
     "returnValue": true
   },

Import a vcard from bluetooth:

   "import": {
     "filters": {
       "type": "text/vcard"
     },
     "disposition": "inline",
     "href": "/contacts/index.html?open",
     "returnValue": true
   },

Open a contact:

   "open": {
     "filters": {
       "type": "webcontacts/contact"
     },
     "disposition": "inline",
     "href": "/contacts/index.html?open",
     "returnValue": true
   },

Update a contact object:

      "update": {
     "filters": {
       "type": "webcontacts/contact"
     },
     "disposition": "inline",
     "href": "/contacts/index.html?update",
     "returnValue": true
   },


The actual contact editor is shown at https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/contacts/js/contacts.js#L53


The last review of the app raised concern about validating the ‘extras’ parameters, still valid :

  • bug 847649 Contacts' "new" activity does not validate parameters
  • bug 847650 Contacts' "new" activity is also "edit" in disguise


System Messages

The (communications) app listens to the following system messages:

 "messages": [
    { "alarm": "/facebook/fb_sync.html" },
    { "bluetooth-dialer-command": "/dialer/index.html#keyboard-view" },
    { "headset-button": "/dialer/index.html#keyboard-view" },
    { "notification": "/dialer/index.html#keyboard-view" },
    { "telephony-new-call": "/dialer/index.html#keyboard-view" },
    { "ussd-received": "/dialer/index.html#keyboard-view" }
 ],


The contacts app does not handle any of these messages. They are all for the Dialer and Facebook integration.

alarm

The alarm message is used by the facebook integration code to schedule periodic updates of the Facebook contact data.

The code for this can be found in https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/facebook/js/fb_sync_init.js#L23

Post Messages

postMessage is used in different places :

  • In oauth, see the Import/Export contacts review. There are messages between the facebook and the contacts components inside the communications app, so they’re internal messages.
  • Some messages are sent to fb.CONTACTS_APP_ORIGIN where CONTACTS_APP_ORIGIN = 'app://communications.gaiamobile.org’, so they’re for internal use also.


Web Activity Usage

The contacts app uses MozActivity for the following:

  • Create a new email when you tap an email address
  • Pick an image for the contact sheet
  • Create a new websms/sms when to send an sms from a contact sheer

None of these do anything interesting except passing an email or phonenumber to the activity or grabbing a resulting image blob.

Notable Event Handlers

Code Review Notes

1. XSS & HTML Injection attacks

The app is pretty good at using templates and escaping html. There are however some cases where content is not escaped. These are all cases where the input is expected to be a number or a keyword with no possible side effects.

I recommend against using shortcuts like this. It is usually fine but it is better to escape as a rule than as an exception as experience shows that the best XSS exploits are when those 'known values' can somehow be modified in an unexpected way in an unexpected location.

There a few of these cases in views/details.js where utils.templates.render() is used.

2. Secure Communications

The app talks to Facebook, Google services, Live and BT Yahoo! through the Contacts integration. This is covered in the Facebook code review and the Import/Export feature review.

3. (Secure) data storage

The contacts are stored using the mozContacts API which uses IndexedDB under the covers. The app also uses async_storage, a wrapper around IndexedDB, to store settings and for example the Facebook oauth token.

The mozContacts data is global to every app with contacts permission while the IndexedDB with app specific data is only available to the communications app. (Dialer, FTU, Contacts)

The Facebook Contacts is currenlty being moved to use the Datastore API.

 "datastores-owned": {
   "Gaia_Facebook_Friends": {
     "description": "Imported Facebook Friends"
   }   
 }


4. Denial of Service

The fields of a contact form are checked against very big chunks of data (it displayed “Infinity” in case of a really big string).

5. Use of Privileged APIs

  • mozContacts - store contacts
  • mozMobileConnection - detect SIM card changes
  • mozTelephony (via TelephonyHelper) - initiate calls
  • mozIccManager - Export/import SIM contacts


6. Interfaces with other Apps/Content

7. Oddities

8. Input Validation Problems

No input validation is done in the activity handlers. Specifically the blind copying of data from the new activity to the page request params is troublesome as it looks like this is purely for internal usage.

Security Risks & Mitigating Controls

Actions & Recommendations

The contacts app unnecessarily has access to all system settings. This is an issue with the Settings API that should be improved in a future version of Firefox OS:

  • bug 841071 Settings are globally shared between applications

The contacts app is embedded in a bigger app, which is not great from a security point of view:

  • bug 847417 Contacts should be turned into minimal standalone application

Usage of innerHTML:

  • bug 828751 Favor use of createElement and textContent instead of innerHTML in Gaia:Contacts

It is not clear what the intent is of the "new" activity:

  • bug 847650 Contacts' "new" activity is also "edit" in disguise

The "new" activity blindly accepts incoming parameters - no validation

  • bug 847649 Contacts' "new" activity does not validate parameters