Security/Reviews/B2G/WebNFC

< Security‎ | Reviews‎ | B2G


Overview

Gecko API Review Details

  • API: Web NFC
  • Review Date: September 2013
  • Review Lead: Paul Theriault

This is a design review of the Web NFC API as currently designed, as of Sept 2, 2013. The API is not finalised but the Mozilla security team has been working with developers involved to provide security feedback to inform the finalization of this API, and guide future direction. While this review did cover some level of code review, final security code will be required once the implementation is stable, and there are apps planning to actually use this API.

Scope

The following system components were reviewed:

  • Gaia
    • System Application changes
    • Web Activities
    • System messages
    • Communication between system app and NFC demo app
  • Gecko
    • mozNfc APIs
    • Gecko Permissions
    • Messaging (NFC:* messages, system messages)
    • NFC System worker
    • Interface to nfcd on IPC socket (JSON-based communication protocol)
  • Gonk
    • NFC Daemon (nfcd)
    • Interface

There was also some discussion on the following topics, however these were are not included in the formal review below:

  • NFC Wallet
  • Transit applications (e.g. miFare)
  • Secure Element (GSMA)

Architecture

The diagram below shows the current interactions between the major components of Web NFC.

 

Components

From order of lowest layer to highest, the main system components are described below.

NFCd

Receives NFC events & messages from hardware. Communicates these messages to Gecko via a JSON based protocol (see bug 897312 for a description of this protocol. Currently this is a JSON based protocol, but an upcoming change will likely convert this to be a binary-based protocol instead.

NFC Worker

NFC worker runs only in the parent b2g process, and connects to the '/dev/socket/nfcd' socket to send and receive messages from NFCd. Messages from NFCd are then posted to the the main thread (nfc.js) via DOM messages.

nfc.js

This component in the main process converts messages into NFC:* messages to be sent to the NfcContentHelper.js. When receiving messages it doesn't do any more than just check the type, and then create the appropriate message. In the reverse direction (when the web page is using the navigator.mozNfc API) some security checks are performed here to make sure the connecting child has the appropriate permission.

MozNfc API

This is the API exposed to web content which allows for listening for NFC events, and sending messages to NFC tags.

System App

NFC Client App

Other Gaia App

Relevant Source Code

Key Bugs Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=749325 Feature Bug (meta): https://bugzilla.mozilla.org/show_bug.cgi?id=860906 Dependent bugs: https://bugzilla.mozilla.org/showdependencytree.cgi?maxdepth=2&id=860906&hide_resolved=0

Gonk 860907: NFC Daemon for B2G (daemon for supporting lib-nxp) 906579: B2G NFC: NFC Daemon for supporting libnfc-nci (daemon for supporting lib-nci) 897312: B2G NFC: Define protocol to communicate between nfcd and b2g Gecko 674741: WebNFC (near-field communication) Gaia 860910: B2G Gaia Integration for NFC Secure Element Support 879861: NFC Secure Element Support 884594: Support Nfc Access Control for Secure Element Access


Permission Model

Parent/Child Communication

Code Review Notes

1. Content/Chrome Segregation

2. Process Segregation

3. Data validation & Sanitization

4. Denial of Service

5. Use of Privileged APIs

6. Interfaces with other Apps/Content

Security Risks & Mitigating Controls

Actions & Recommendations