diff --git a/idl/draft.idl b/idl/draft.idl
deleted file mode 100644
index 3d4ba89..0000000
--- a/idl/draft.idl
+++ /dev/null
@@ -1,56 +0,0 @@
-// This is the WebIDL for the next version under work
-// based on discussions on issues #2, #3, #26, #40.
-//
-// Changes:
-// - reintroduce watch (since addEventListener is not allowed to prompt, and
-// events vs watches were tricky to implement: too many corner cases
-// - reintroduce watch options, filtering on URL patterns, data type etc.
-// - replace onmessage event with MessageCallback
-// - change send() to pushMessage() - better aligned with semantics
-// - add timeout to push options
-// - NFCRecord data should be "any"
-// - replace scope with URL
-// - permission policies changed (in the spec)
-
-partial interface Navigator {
- readonly attribute NFC nfc;
-};
-
-interface NFC {
- Promise
- This specification defines an API to manage selected NFC use-cases from web - pages, and to enable new use-cases based on NFC technology. + This document defines an API to enable selected use-cases based on + NFC technology.
- Implementors need to be aware that this specification is considered unstable.
- Implementors who are not taking part in the discussions will find the
+ Implementers need to be aware that this specification is considered
+ unstable.
+ Implementers who are not taking part in the discussions will find the
specification changing out from under them in incompatible ways. Vendors
interested in implementing this specification before it eventually reaches
the Candidate Recommendation phase should subscribe to the repository on
@@ -112,55 +139,114 @@
- This specification defines conformance criteria that apply to a single
- product: the user agent that implements the interfaces
- it contains.
+ This document defines conformance criteria that apply to a single
+ product: the user agent that implements the interfaces it contains.
Implementations that use ECMAScript to implement the APIs defined in
- this specification MUST implement them in a manner consistent with the
+ this document MUST implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as
- this specification uses that specification and terminology.
+ this document uses that specification and terminology.
+
+
+ The term
+ browsing context refers to the environment in which
+ Document objects are
+ presented to the user. A given browsing context has a single
+ origin and a single
- The terms
-
- event handler and
-
- event handler event types are defined in [[!HTML5]].
+ The term
+
+ incumbent settings object is defined in [[!HTML5]].
-
-
- The algorithms
- utf-8 encode, and
-
- utf-8 decode are defined in [[!ENCODING]].
+ The term of executing algorithms
+ in parallel
+ is defined in [[!HTML5]].
-
- EventInit,
+ URL
+ is defined in [[!URL]].
+
+ The term
+
+ document base URL is defined in [[!HTML5]].
+
+ The term
+ URL path is defined in [[!URL]].
+
+ The term
+
+ origin is defined in [[!HTML5]].
+
+ The term
+ ASCII serialized origin is defined in [[!HTML5]].
+
+ The term URL pattern is defined in the
+ URL patterns section.
+
+ The term match pattern is defined in the
+ Match patterns section.
+
+
+
+
DOMException,
@@ -170,45 +256,57 @@
NotSupportedError,
- NotFoundError, and
+ NotFoundError,
+
+ NetworkError,
SecurityError
are defined in [[!DOM4]].
- The term web app refers to a Web application, i.e. an application
- implemented using Web technologies, and executing within the context of a
- Web user agent, e.g. a Web browser or other Web-based runtime
- environments.
+
+ Promise,
+
+ JSON and
+
+ JSON.parse
+ are defined in [[!ECMASCRIPT]].
- The term expressed permission refers to an act by the user, e.g.
- via user interface or host device platform features, via which the user
- approves the permission of a web app to access the Web NFC API.
+ The algorithms
+ utf-8 encode, and
+
+ utf-8 decode are defined in [[!ENCODING]].
- The term obtain permission for a certain operation refers to
- obtain expressed permission or to ensure the existence of a
- prearranged trust relationship.
+ IANA media types (formerly known as MIME types) are defined in
+ RFC2046.
-
-
-
-
+ The term obtain permission for a certain operation indicates
+ that the user agent has either obtained expressed permission, or
+ asks for forgiveness, or ensured a
+ prearranged trust relationship exists.
NFC stands for Near Field Communications, short-range wireless
@@ -217,7 +315,8 @@
data exchange formats, and are based on existing radio-frequency
identification (RFID) standards, including ISO/IEC 14443 and FeliCa.
The NFC standards include ISO/IEC 18092[5] and those defined by the NFC
- Forum. See http://www.nfc-forum.org/specs/spec_list/ for a complete listing.
+ Forum. See https://www.nfc-forum.org/specs/spec_list/ for a complete
+ listing.
An NFC adapter is the software entity in the underlying
@@ -226,7 +325,7 @@
adapters, for instance a built-in one, and one attached via USB.
- An NFC tag is a passive, unpowered NFC device.
+ An NFC tag is a passive NFC device.
The NFC tag is powered by magnetic induction when an active NFC
device is in proximity range. An NFC tag contains a single
NDEF message.
@@ -237,22 +336,25 @@
Terminology
- WindowProxy
object, but it
+ can have many Document
objects, with their associated
+ Window
objects. The browsing context identifies
+ the entity which invokes this API, which can be a web app, a
+ web page, or an
+ iframe.
Promise
, and
-
- JSON.parse
are defined in [[!ECMASCRIPT]].
+ The term
+
+ secure context is defined in [[!WEBAPPSEC]].
DOMString
,
+
+ ArrayBuffer
,
+
+ BufferSource
and
+
+ any
+ are defined in [[!WEBIDL]].
+ URL
-
is defined in [[!URL]].
+ The term expressed permission refers to an act by the user, e.g.
+ via user interface or setting or host device platform features, using which
+ the user approves the permission of a browsing context to access the
+ given functionality.
Blob
-
is defined in [[!FILEAPI]].
+ The term ask for forgiveness refers to some
+ form of unobtrusive notification that informs the user of an operation
+ while it is running.
+ User agents SHOULD provide the user with means to ignore similar future
+ operations from the same origin and advertise this to the user.
DOMString
,
-
- ArrayBuffer
,
-
- BufferSource
and
-
- any
- are defined in [[!WEBIDL]].
+ The term prearranged trust relationship means that the
+ user agent has already established a trust relationship for a
+ certain operation using a platform specific mechanism, so that an
+ expressed permission from the user is not any more needed.
+ See also this section in the Security and Privacy document.
+
- An NFC peer is another device, which can interact with other - devices in order to exchange data using NFC. + An NFC peer is an active, powered device, which can interact + with other devices in order to exchange data using NFC. +
++ An NFC device is either an NFC peer, or an NFC tag.
An NDEF message encapsulates one or more application-defined - NDEF records. NDEF stands for NFC Forum Data Exchange - Format, a lightweight binary message format. NDEF messages can be stored on - a NFC tag or exchanged between NFC-enabled devices. + NDEF records. NDEF is an abbreviation for NFC Forum + Data Exchange Format, a lightweight binary message format. NDEF messages + can be stored on an NFC tag or exchanged between NFC-enabled devices.
An NDEF record has a maximum payload of 2^32-1 bytes. The record also contains information about the payload size, type, and an optional identifier. NFC Forum standardized a small set of useful data types to be - used in NDEF records, for instance text, URL, media. In addition, - there are record types designed for more complex interactions, such as - Smart Poster, and handover records. + used in NDEF records, for instance text, URL, and binary data such as + media. In addition, there are record types designed for more complex + interactions, such as Smart Poster, and handover records.
Part of the NDEF record is the TNF field, standing for @@ -303,16 +405,52 @@ data and possible actions).
- A Web NFC message is an NDEF message which contains at - least one Web NFC record. + Part of the NDEF record is the NDEF Id field, which may or + may not be present. If present, it contains a maximum 256 octets long + string which is a URL and it is used for identifying the payload, + in an application specific way. In this specification it is used for storing + the ASCII serialized origin of the browsing context which has + written the content. +
++ The term NFC content is a synonym for NDEF message, + which can originate either from an NFC tag or an NFC peer. +
++ The term Web NFC origin is the ASCII serialized origin + of the browsing context that has written the Web NFC message.
- A Web NFC record is an NDEF record with TNF=4
- (External Type Record), and the type field set to
- "urn:nfc:ext:w3.org:webnfc"
. Further formatting details are
- described Data Types.
+ The Web NFC Id is a special URL stored in the
+ Web NFC record, and it is used for matching NFC content with
+ URL patterns specified by listeners.
+ For more details see the Web NFC Id section.
An NFC handover defines NFC Forum Well Known Types and the +
+ A Web NFC record is a special NDEF record which identifies + Web NFC content meant for web pages, rather than generic + NFC content. For a detailed description see the + Web NFC record section. +
++ A Web NFC message represents a set of the NDEF records + from a given NDEF message and a special Web NFC record. + For more details see the Web NFC Message + format section. +
++ The term Web NFC content denotes all Web NFC messages + contained in an NDEF message. This version of the specification + supports one Web NFC message per NDEF message. +
++ The term trusted integrity NFC content refers to an + NDEF message, or an NDEF record, which can be trusted for + data integrity, i.e. the content is not changed by third party between + writing and reading. +
++ An NFC handover defines NFC Forum Well Known Types and the corresponding message structure that allows negotiation and activation of an alternative communication carrier, such as Bluetooth or WiFi. The negotiated communication carrier would then be used (separately) to @@ -321,41 +459,29 @@ a television set.
- The term sufficient permission in this document means that a - web app which is invoking the methods of this API has been checked to - comply with the security policies set by the underlying platform and API - implementation in the moment and context of invoking the API method. - Further details are described in - Security and Privacy. -
-- The term - - document base URL is defined in [[!HTML5]]. -
-- The term URL scope is introduced in this document for NFC - operations as a sub-domain match to the web app's - document URL, which includes the domain of the calling web app. + An NFC watch is defined in + The watch() method section.
- There are three groups of user scenarios for NFC: + In general, there are three groups of user scenarios for NFC:
@@ -435,59 +561,82 @@ Card emulation mode capabilities also depend on the NFC chip in the device. For payments, a Secure Element is often needed.
++ This document does not aim supporting all possible use cases of NFC + technology, but only a few use cases which are considered relevant to be + used by web pages in browsers, using the browser security model. +
+- A few Web NFC user scenarios are described in - this document. - These user scenarios can be grouped along - criteria based on security, privacy and feature categories, resulting in - generic flows as follows. + A few Web NFC user scenarios are described in the + Use Cases + document. These user scenarios can be grouped by criteria based on + security, privacy and feature categories, resulting in generic flows as + follows.
+ The user opens a web page which can write an NFC tag. The write + operations may be one of the following: +
+ Note that an NFC write operation to an NFC tag always involves + also a read operation. +
+
In general, sending data to another Web NFC capable device requires that
on the initiating device the user would first have to navigate to a web
site. The user would then touch the device against another Web NFC
equipped device, and data transfer would occur. On the receiving device
- the user agent will dispatch the content to a web site registered
- to handle the content and in case of multiple such web sites, the one
- chosen by the second user.
+ the user agent will dispatch the content to an application registered
+ and eligible to handle the content, and if that application is a browser
+ which has a web page open and in focus that uses the Web NFC API and has
+ set up a NFC watch to listen to Web NFC content, then the
+ content is delivered to the web page through the parameters of an
+ NFCMessageCallback
.
High level features for the Web NFC specification include the following:
+ The trust model, attacker model, threat model and possible mitigation + proposals for the Web NFC API are presented in the + + Security and Privacy document. This section presents the chosen + security and privacy model through normative requirements to + implementations. +
+ ++ Web pages using the NFC API are not trusted. + This means that the user needs to be aware of exactly what a web page is + intending to do with NFC at any given moment. Implementations SHOULD + make sure that when the user authorizes an NFC operation, then only that + action is run, without side effects, and exactly in the context and the + number of times the user allows the execution of NFC operations. +
++ The content of Web NFC messages is not trusted, unless the user agent + can safely assume that the content has not been change by third parties + between writing and reading it, e.g. in the case of a + prearranged trust relationship can be established. +
++ The main threats are summarized in the + Security and Privacy document. +
++ In this specification the following threats are handled with the highest + priority: +
+ User agents MUST NOT provide Web NFC API access to browsing contexts + without complying with the security policies described in this document. +
++ This specification attempts to help minimizing the user prompts needed to + use the Web NFC API and tries to involve implicit policies which can + address the + + threats. + However, this specification does not describe, nor does it + mandate specific user prompting policies. The term obtain permission + is used for acquiring trust for a given operation. +
The Permissions API SHOULD
- be supported by user agents for implementing NFC related
+ be supported by user agents for implementing NFC related
[[permissions]]. The required
permission name is "nfc"
.
+ This allows saving user permissions for a given origin in a
+ persistent database until revocation.
- User agents MUST NOT provide Web NFC API access - to web apps without the expressed permission of the user. - User agents must acquire consent for [[permissions]] for each call to the - methods of this API, unless a prearranged trust relationship applies. + User agents MUST acquire user consent, i.e. expressed permission for + for using the methods of this API, unless a + prearranged trust relationship applies, or unless an implicit policy + specified in this document allows it, eventually with an + ask for forgiveness indication.
- Permissions that are preserved beyond the current browsing session MUST be - revocable. + The choice of trusting the integrity of NFC content when + used for implementing security policies, for instance the authenticity of + origins saved in the NDEF Id field, or that of the + URL path of the browsing context, and then used for + same-origin or allowed-origins policy by the user agent, SHOULD be based on + prearranged trust relationship (such as encryption and other means), + otherwise the integrity of the content MUST NOT be trusted by user agents + and security policies MUST NOT be based on this.
-- The Permissions API does - not yet address the issue of revoking permissions. When it will be - addressed, this section will be updated. +
+ All expressed permissions that are preserved beyond the current + browsing session MUST be revocable.
+- User agents MUST implement the following policies: + User agents MUST implement the following policies:
"https"
SHOULD be able to access
+ NFC content.
Browsers MAY ignore this rule for development purposes only.
Window
object associated with the
+ active Document
of the browsing context using
+ the Web NFC API MUST be visible and
+ in focus. This also means that user agents
+ SHOULD make sure the display is on, and the device is unlocked.
+ For web pages in background, receiving and sending NFC content
+ MUST be suspended.
+ + As a consequence, since every access from a browsing context + needs the attention of the user, and since the user must do a physical + gesture of tapping the device to another one in order to use NFC, it + is assumed in this specification that the user has + expressed permission for each NFC operation, provided the + other conditions described in this specification are fulfilled. +
getAdapter
+ method, or when setting up listeners for reading, or when sending
+ NFC content, the user agent MAY warn the user that
+ physical location may be inferred from the act of using NFC by the
+ origin of the reading browsing context.
+ "https://"
SHOULD be able to read NFC tags that is
- not empty and does not contain a Web NFC messages.
+ For Bluetooth and WiFi handover (supported in later versions),
+ the user SHOULD have to grant access to the secondary API and must be
+ able to properly understand what they are granting.
JSON
data, the content
- SHOULD be validated by implementations.
+ The payload data on NFC content is untrusted, and MUST NOT be used
+ by the user agent to do automatic handling such as opening a web page
+ with a URL found in an NFC tag, unless the user approves that.
- Web NFC implementations SHOULD use Web NFC messages, which SHOULD
- be sufficiently differentiated in order to avoid accidental matching with
- a generic NDEF message used in regular NFC tags or between
- NFC peers. This is achieved by using an additional
- Web NFC record, and in rest using normal NDEF records in
- order to compose the NDEF message.
+ The Web NFC Id SHOULD contain a valid URL according to
+ [[RFC3986]].
+ The scheme of a Web NFC Id MUST always be "https"
.
+ The Web NFC Id MUST contain the Web NFC origin, (i.e. the
+ ASCII serialized origin), optionally followed by the
+ URL path of the browsing context that has sent the
+ Web NFC content.
+
+ The format of a Web NFC message is the following: +
The format of a Web NFC record is the following.
@@ -670,122 +983,210 @@
Type field set to urn:nfc:ext:w3.org:webnfc
.
+ The content of any Web NFC message is exposed by the following + sequence: +
++ The content of any NDEF record is exposed by the following + dictionary: +
+
+ The kind
+ property MUST return the NFCDataType
of the
+ NDEF record.
+
+ The type
+ property MUST return the IANA media type of the NDEF record
+ payload.
+
+ The
+ data
property MUST return the
+ payload data of the NDEF record with an appropriate ECMAScript
+ type, which depends on the IANA media type.
+
- The payload of a Web NFC message is represented by using normal - NDEF records. - The following types can be used as payload, i.e. when writing to - NFC tags, sending data to NFC peers, and when reading - NDEF messages. + NFCDataType denotes the data types + supported as NDEF record payload in read and send operations in + this API.
-
- NFCData denotes the data types
- supported as NDEF record payload in read and send operations in
- this API.
+ The mapping from data types of an NFCRecord
to and from
+ NDEF record types is presented in the algorithmic steps which handle
+ the data, i.e. the receiving NFC content
+ algorithm and sending NFC content algorithm.
- The mapping from supported NFCData
to
- NDEF record types, as used in the send()
- method is as follows:
+ The mapping from data types of an NFCRecord
to
+ NDEF record types, as used in the sending NFC content
+ algorithm is as follows:
NFCData | +NFCRecord kind | +NFCRecord type | +NFCRecord data | NDEF record type | |
---|---|---|---|---|---|
DOMString | +"empty" | +not used | +not used | +NFC Forum Empty Type (TNF=0) | +|
"text" | +not used | +DOMString |
NFC Forum Well Known Type (TNF=1) with type Text | ||
URL | -+ | "url" | +not used | +DOMString |
+ NFC Forum Well Known Type (TNF=1) with type URI |
JSON | +"json" | +"application/json", "application/* +json" |
+
+ null or DOMString or Number or
+ Object
+ |
Media-type as defined in [[RFC2046]] (TNF=2) with associated
- MIME type "application/json"
+ IANA media type specified in the type attribute.
|
|
Blob with MIME type | +"opaque" | +IANA media type | +ArrayBuffer or typed array |
Media-type as defined in [[RFC2046]] (TNF=2) | |
Blob without MIME type | +"opaque" | +"" (empty) |
+ ArrayBuffer or typed array |
NFC Forum External Type (TNF=4) |
- The mapping from NDEF record types to NFCData
,
- as used for incoming NDEF messages exposed by the
- NFCMessageEvent
, is as follows:
+ The mapping from NDEF record types to NFCRecord
,
+ as used for incoming NDEF messages described by the
+ receiving NFC content algorithm is as
+ follows:
NDEF record type | -NFCData | +NFCRecord kind | +NFCRecord type | +NFCRecord data | +
---|---|---|---|---|
NFC Forum Empty Type (TNF=0) | +"empty" | +"" | +null |
|
NFC Forum Well Known Type (TNF=1) with type Text | -DOMString | +"text" | +"text/plain" | +DOMString |
NFC Forum Well Known Type (TNF=1) with type URI | -URL object | +"url" | +"text/plain" | +DOMString |
NFC Forum Well Known Type (TNF=1) with type Smart Poster | -URL object | +"url" | +"text/plain" | +DOMString |
Absolute URI as defined in [[RFC3986]] (TNF=3) | -URL object | +"url" | +"text/plain" | +DOMString |
Media-type as defined in [[RFC2046]] (TNF=2) with associated
- MIME type "application/json"
+ IANA media type "application/json" or
+ "application/*-json"
+ |
+ "json" | +The IANA media type used in the NDEF record | +
+ null or DOMString or Number or
+ Object
|
- JSON object |
Media-type as defined in [[RFC2046]] (TNF=2) | -Blob object | +"opaque" | +The IANA media type used in the NDEF record | +ArrayBuffer |
NFC Forum External Type (TNF=4) with type other than
- urn:nfc:ext:w3.org:webnfc |
- Blob object | +"opaque" | +"application/octet-stream" | +ArrayBuffer |
Any other NDEF record type | -Blob object | +"opaque" | +"application/octet-stream" | +ArrayBuffer |
- Note that Web NFC records are not exposed to client web apps. + The Web NFC records MUST NOT be exposed to client + browsing contexts.
- The HTML specification defines a
+ The HTML document defines a
When getting the nfc attribute, the
- user agent MUST return the NFC object, which provides
+ user agent MUST return the NFC object, which provides
NFC related functionality.
Navigator
interface [HTML] which this specification
extends.
@@ -805,7 +1206,7 @@
The nfc attribute
Implementations MAY expose multiple NFC adapters. By using the - - requestAdapter() method, web apps can obtain an adapter object - providing NFC functionality. - When this method is invoked, the user agent MUST run the following + + requestAdapter() method, the browsing context can obtain an + adapter object providing NFC functionality. + When this method is invoked, the user agent MUST run the following steps:
Promise
object.
+ Promise
object.
"SecurityError"
,
- and terminate these steps.
+ and terminate this algorithm.
"NotSupportedError"
, and terminate these steps.
+ "NotSupportedError"
, and terminate this algorithm.
+ null
.NFCAdapter
object, or if that does not
+ exist, a new NFCAdapter
object which is bound to
+ work with the default NFC adapter.
+ Resolve promise with adapter, and terminate these
+ steps.
"NotSupportedError"
, and terminate these steps.
+ "NotFoundError"
, and terminate this algorithm.
null
.NFCAdapter
+ object.
+ "NotFoundError"
, and terminate these steps.
+ Otherwise if user prompt is blocked or canceled, select the
+ first built-in NFC adapter.
- The NFCAdapter
interface handles incoming NDEF messages,
- exposed by the NFCMessageEvent
event, either from an
- NFC tag or an NFC peer. By default, listening to this event
- SHOULD be disabled.
-
- The following are the event handlers implemented by the
- NFCAdapter
interface.
-
event handler | -event name | -event type | -
---|---|---|
onmessage |
- message |
- NFCMessageEvent |
-
- The message
event is used for notifying the adapter
- object about an NDEF message dispatched to the web app.
-
- In this specification, NDEF message content is delivered by an - NFCMessageEvent event. -
-
- The message
- property MUST return the NFCMessage
representing the
- payload data of the NDEF message.
+ The NFCAdapter
interface provides sending
+ Web NFC messages to NFC tags or NFC peers within range,
+ and to set up and cancel NFC watches to handle incoming
+ Web NFC messages either from an NFC tag or an NFC peer.
- The content of the NDEF message is exposed by the following - interface: -
-
- The scope
- property MUST return the URL scope which has written the message.
-
The
- data
property MUST return the
- payload data of the NDEF message as an array of either
- DOMString
, or URL
object, or Blob
- object, or serializable JSON object as a generic Object
.
+
+ pushMessage() method is used for saving a NDEF message
+ to be sent to an NFC tag for writing, or to an NFC peer
+ device for pushing, next time when they get into proximity range, or until
+ a timeout expires. At any time there is maximum 2 Web NFC messages
+ that can be set for sending: one targeted to NFC tags and one for
+ NFC peers. When there is a Web NFC message set for sending
+ to any target, then no more messages are accepted to be set until the
+ current message is sent or a timeout happens.
+ The target property
+ denotes the intended target for the pending pushMessage()
+ operation. The default value is "any"
.
+
+ The timeout property
+ denotes the timeout for the pending pushMessage()
+ operation expressed in milliseconds. The default, and maximal value is
+ 10000, i.e. 10 seconds. After the timeout expires, the
+ message set for sending is cleared, an error is returned, and a new
+ Web NFC message can be set for sending.
+
- The
-
- send()
method is used for sending an NDEF message to
- either an NFC tag for writing, or to an NFC peer device,
- next time when they get into proximity range.
- When this method is invoked, the user agent MUST run the following
- steps:
-
+
+ pushMessage()
method is invoked, the user agent
+ MUST run the following sending NFC content algorithm:
+ Promise
object.
"SecurityError"
, and terminate these steps.
+ If the incumbent settings object is not a
+ secure context, then reject promise with
+ "SecurityError"
, and terminate this algorithm.
"NotSupportedError"
, and terminate these steps.
+ "NotSupportedError"
, and terminate this algorithm.
undefined
- or null
, then use the default values.
- Otherwise if invalid, then reject promise with
- "SyntaxError"
, and terminate these steps.
+ Let origin be the origin of the
+ browsing context invoking this method.
undefined
, then set scope to
- the DOMString
describing the document base URL.
- If it is invalid in the given platform, or if it is not a
- sub-domain match of the document base URL, then reject
- promise with "SyntaxError"
, and terminate
- these steps.
+ Try to obtain permission by applying the following sub-steps:
+ "SecurityError"
, and terminate this algorithm.
+ "SyntaxError"
, and
- terminate these steps.
- For each valid element create an NDEF record.
- The implementation choose the best suitable NDEF record format
- for the given platform.
- Each element in the input array given in message.data
- SHOULD map to a separate NDEF record in the NDEF message
- to be sent.
+ Let timeout be the value of options.timeout if
+ it is defined, or otherwise 10000 (milliseconds).
"any"
.
NFCRecord
objects, then reject
+ promise with "SyntaxError"
,
+ and terminate this algorithm.
"TimeoutError"
.
+ Let output be the notation for the NDEF message
+ to be created by an API call to the underlying platform, based on
+ data provided by these steps.
"tag"
, then
- the sending should only happen if an NFC tag is tapped within
- a platform specific timeout, otherwise reject promise with
- a "TimeoutError"
in the case of timeout, or
- "InvalidAccessError"
if an NFC peer is
- tapped instead of a tag.
+ For each NFCRecord record in the sequence
+ message, execute the following steps, or make sure
+ that the underlying platform provides equivalent values to
+ ndef:
+ "empty"
, then
+ execute the following steps:
+ NFCMessage
output to
+ contain only the current empty record record,
+ and continue with step 11.
+ "text"
, then
+ execute the following steps, or make sure
+ that the underlying platform provides equivalent values to
+ ndef:
+
+ This is to be used when clients specifically want to write an
+ NDEF Well Known Type Text record. Otherwise clients could
+ also use "opaque"
with an explicit IANA media
+ type also for text, which has the advantage of better
+ differentiation, e.g. when using "text/xml", or "text/vcard".
+
"string"
+ or "number"
, then then reject promise
+ with "SyntaxError"
, and terminate this algorithm.
+ "string"
+ or if it does not start with "text/"
, then
+ reject promise with "SyntaxError"
,
+ and terminate this algorithm.
+ In addition, user agents MAY check that
+ record.type is a IANA registered media type
+ for text. If not, then the user agent MAY
+ reject promise with "SyntaxError"
,
+ and terminate this algorithm.
+ "en"
.
+ If record.type does include a lang=
+ parameter for language encoding (e.g.
+ "text/plain; lang=fr"), then set language to
+ the language code extracted from record.type.
+ If language is not one of the language codes listed
+ in the IANA language registry
+ (or [[ISO-639.2]]),
+ then user agents MAY reject promise with
+ "SyntaxError"
, and terminate this algorithm.
+
+ Note that lang=
is not standard parameter
+ to IANA media types, but it is used in this specification
+ in order to maintain compatibility with NFC specifications.
+
"T"
+ (value 0x54 in NFC binary encoding).
+ + Since the URL path of origin is saved in + the Web NFC record, this step is not required, + and since it occupies space in NFC content, + implementations SHOULD NOT use this step unless they + want to be future-proof about possible variations in + this specification, when writing NFC tags. +
+"url"
, then
+ execute the map URL to NDEF sub-steps, or make sure
+ that the underlying platform provides equivalent values to
+ ndef:
+ string
,
+ then reject promise with
+ "SyntaxError"
, and terminate this algorithm.
+ "json"
, then
+ execute the map JSON to NDEF sub-steps, or make sure
+ that the underlying platform provides equivalent values to
+ ndef:
+ "string"
, or "number"
, or
+ "object"
, then reject promise with
+ "SyntaxError"
, and terminate this algorithm.
+ "application/json"
, or another IANA type for JSON
+ ("application/<type>+json"
), then reject
+ promise with "SyntaxError"
, and
+ terminate this algorithm.
+ "opaque"
, then
+ execute the map binary to NDEF sub-steps, or make sure
+ that the underlying platform provides equivalent values to
+ ndef:
+ ArrayBuffer
, then reject promise with
+ "SyntaxError"
, and terminate this algorithm.
+ "SyntaxError"
, and
+ terminate this algorithm.
+ undefined
,
+ then:
+ ArrayBuffer
, then set record.type to
+ "application/octet-stream"
and execute the
+ map binary to NDEF
+ steps.
+ "object"
, then set record.type to
+ "application/json"
and execute the
+ map JSON to NDEF steps.
+ "number"
or "string"
, then
+ set record.type to "plain/text"
and
+ execute the
+ map text to NDEF steps.
+ "SyntaxError"
, and terminate this algorithm.
+ "urn:nfc:ext:w3.org:webnfc"
.
+ + In future versions a list of "allowed-origins" may be supported. + It needs more discussions, since there is a security issue with + it. See the + Security and Privacy document. +
+pushMessage()
method replaces the previously set
+ push message, and also resets the timer associated with it.
"peer"
, then
- the sending should only happen if an NFC peer is tapped within
- a platform specific timeout, otherwise reject promise with
- a "TimeoutError"
in the case of timeout, or
- "InvalidAccessError"
if an NFC tag is
- tapped instead of a peer.
+ If timer expires, reject promise with
+ "TimeoutError"
and terminate this algorithm.
"any"
(which
- is the default value), then the sending should happen if either an
- NFC peer or an NFC tag is tapped within a platform
- specific timeout, otherwise reject promise with
- "TimeoutError"
.
+ When an NFC device comes in communication range,
+ "tag"
,
+ then the sending should only happen if an NFC tag is
+ tapped, otherwise reject promise
+ "InvalidAccessError"
and terminate this algorithm.
+ "peer"
,
+ then the sending should only happen if an NFC peer is
+ tapped, otherwise reject promise with
+ "InvalidAccessError"
and terminate this algorithm.
+ "any"
+ (which is the default value), then the sending should happen if
+ either an NFC peer or an NFC tag is tapped within
+ the specified timeout.
+ "NetworkError"
and
+ terminate this algorithm.
+ cancelPush()
+ method is called, reject promise with
+ "AbortError"
, as described in the
+ cancelPush()
algorithm.
+
+ The
+ cancelPush
+ method is used for resetting the NDEF message set to be pushed next
+ time an NFC device comes in range.
+
+ When the cancelPush()
method is invoked, the user agent
+ MUST run the following algorithm:
+
"SecurityError"
, and terminate this algorithm.
+ pushMessage()
algorithm,
+ or no active timers associated with it, then terminate this algorithm.
+
+ This step also covers the case when the timer has already fired,
+ which also means that the message buffer is invalid, and is to be
+ replaced by the next invocation of pushMessage()
.
+
messagePush()
.
+ pushMessage()
algorithm
+ with "AbortError"
.
+
+ The
+
+ watch()
method enables listening to incoming
+ NDEF messages.
+
+ The NFC content to which clients listen can be filtered based on + its data type, and based on the URL path of the + browsing context which has been saved to the Web NFC record + of the NFC content. The latter is matched against + URL patterns used in NFC watches. +
+
+ A NFC watch is referring to a NFCWatchOptions
+ filter saved together the information with NFC adapter it belongs
+ to, and a locally unique identifier which is used for cancellation.
+ The
+ receiving NFC algorithm uses NFC watches to match incoming
+ NFC content.
+
+ Multiple consecutive calls to the watch()
method from the
+ same origin create filters which are in OR relationship.
+
+ Watch filters are grouped by NFC adapter. +
+
+ A match pattern is a string which can contain the
+ '*'
wildcard character.
+ Match patterns are used primarily for matching IANA media types, for
+ instance the match pattern 'application/*+json'
matches
+ 'application/calendar+json'
, but does not match
+ 'application/json'
. The match pattern
+ '*/*json'
matches both.
+
+ A URL pattern is a URL which can contain '*'
+ characters. Each URL pattern is in the form of
+
+ The syntax is the following: +
+ <url-pattern> := <scheme>://<host><path> + <scheme> := '*' | 'https' + <host> := '*' | '*.' <any char except '/' and '*'>+ + <path> := '/' <any chars> ++ +
+ Note that '*'
has slightly different meaning depending on
+ whether it is in the scheme, host or path part.
+ In a scheme '*'
will match only the allowed
+ 'https'
scheme.
+ If the host is '*'
, then it matches any host. If the
+ host is e.g. '*.myhost'
, then it will match the
+ specified host or any of its subdomains.
+ In the path part, each '*'
matches 0 or more
+ characters.
+
+ For example, '*://*.mydomain.com/*'
will match
+ 'https://services.mydomain.com/myservice1/myapp2/'
and
+ 'https://info.mydomain.com/general/'
.
+
+ The "web-only"
value means that only those
+ NDEF messages are exposed which contain a
+ Web NFC record, i.e. which are meant for web pages.
+ This is the default value.
+
+ The "all"
value means that all NDEF messages
+ are exposed.
+
+ To describe which messages an application is interested in, the + following dictionary is used: +
+
- The target property
- denotes the intended target for the pending send()
- operation. The default value is "any"
.
+ The url property
+ denotes the URL pattern which is used for matching the
+ URL path of the Web NFC message which is stored in the
+ Web NFC record.
+ The values null
, undefined
, and
+ ""
mean that no matching happens.
+ The kind property
+ denotes the string value which is used for matching the
+ kind
property of each NFCRecord
object
+ in a Web NFC message.
+ The values null
and undefined
mean that
+ no matching happens.
+
+ The type property
+ denotes the match pattern which is used for matching the
+ type
property of each NFCRecord
object
+ in a Web NFC message.
+ The values null
and undefined
mean that
+ no matching happens. The value ""
matches missing type
+ information.
+
+ The mode property tells + whether only Web NFC content or any NFC content will be + watched. +
++ var watchOptions = { + url: "www.w3.org/*", // all paths from the domain are accepted + kind: "json", + type: "application/*json" // all IANA media types dealing with JSON + } ++
+ var watchOptions = { + url: "*://*/info/restaurant/daily-menu/", // accepted from any domain + kind: "opaque", + type: "application/octet-stream" + } ++
+ When the
+
+ watch()
method is invoked, the user agent MUST run
+ the following NFC watch algorithm:
+
Promise
object.
+ "SecurityError"
, and terminate this algorithm.
+ "NotSupportedError"
, and
+ terminate this algorithm.
+ "SecurityError"
, and terminate this algorithm.
+ "all"
, then also include in this information that the
+ origin is requesting to read all NFC content, not only
+ those meant for web pages.
+ "SecurityError"
, and terminate this algorithm.
+ + The ask for forgiveness interaction + might show choices like "block now" or "block forever", etc. If the + user has chosen to "block forever" the given origin, it + is the responsibility of the user agent to remember these user + choices for each origin, regardless of which + NFC adapter is used, and consult them on later invocations. +
+"SyntaxError"
,
+ and terminate this algorithm.
+ "NotSupportedError"
, and terminate this algorithm.
+
+ When the
+ unwatch()
method is invoked, the user agent
+ MUST run the following steps:
+
Promise
object.
+ "SecurityError"
, and terminate this algorithm.
+ undefined
, then
+ remove all watches and filters set by successive calls of the
+ NFC watch()
method on the current
+ NFC adapter.
+ "NotFoundError"
, and terminate this algorithm.
+ + If there are any NFC watches set up for any NFC adapter, then + user agents MUST listen to NDEF messages, according to step 9 + of the NFC watch algorithm. + When an NDEF message is received by the underlying platform, + user agents MUST run the following algorithm: +
+ This is a placeholder for a possible future feature. In this step, + implementations MAY check if the Web NFC origin saved in + the Web NFC record of input matches with the + origin of the browsing context. If yes, and also + prearranged trust relationship exists so that + input is trusted integrity NFC content, then + same-origin policies MAY be applied. +
++ This is a placeholder for a possible future feature. In this step, + implementations MAY check if any of the URL patterns saved + in the Web NFC record match with the origin of the + browsing context. If yes, and also if + prearranged trust relationship exists so that + input is trusted integrity NFC content, then + allowed-origin policies MAY be applied. +
+NFCRecord
object.
+ "empty"
,
+ record.type to ""
,
+ and record.data to null
.
+ "T"
(value 0x54 in NFC binary
+ encoding), then execute the following sub-steps for
+ parsing NDEF Text record, or make sure that the
+ underlying platform provides equivalent values to the
+ record object properties:
+ "text"
."text/plain"
.";lang="
and then the value of
+ language to record.type.
+ "U"
(value 0x55 in NFC binary
+ encoding), then execute the following sub-steps for
+ parsing NDEF URL record, or make sure that the
+ underlying platform provides equivalent values to the
+ record object properties:
+ "url"
."text/plain"
."url"
,
+ set record.type to "text/plain"
and
+ set record.data to the string converted from
+ ndef.PAYLOAD.
+ "application/*json"
, then
+ "json"
.+ The payload SHOULD NOT be evaluated by user agents for + security reasons. +
+"opaque"
.ArrayBuffer
+ object constructed from the octets of ndef.PAYLOAD.
+ "opaque"
."application/octet-stream
.
+ ArrayBuffer
+ object constructed from the octets of ndef.PAYLOAD.
+ - navigator.permissions.query({name: 'nfc'}).then((result) => { - if (result.status == 'granted') { - enableNFCUseCase(); // Do things here. - } else if (result.status == 'prompt') { - // The user agent will prompt. - } - // Otherwise don't do anything since it will fail. - }); -
var adapter = null; + var id = null; navigator.nfc.requestAdapter().then((nfcAdapter) => { - adapter = nfcAdapter; - adapter.onmessage = onMessage; + id = adapter.watch({}, onMessage); }; - function onMessage(event) { - console.log("NDEF message received from scope " + event.message.scope); - var data = event.message.data; - - if (!data) { // empty tag - writeMessageOnTag({data: “Initializing a passive tag”}); + function onMessage(message, url) { + console.log("NDEF message received from URL " + url); + if (message[0].kind == 'empty') { + adapter.pushMessage([ + { kind: "text", type: "", data: “Initializing a passive tag”}]); } - if (typeof data == ‘string’) { - console.log(“Data is string: “ + data); - } else if (data instanceof Blob) { - processBlob(data); - } else if (data instanceof URL) { - console.log(“Data is URL: “ + data.toString()); - } else if (typeof data == ‘object’) { - processJSON(data); - } - }; - - function writeMessageOnTag(msg) { - adapter.send(msg, {target: "tag"}) - .then(() => { console.log("Send was successful")}) - .catch(() => { console.log("Send failed")}); + message.forEach((record) => { + if (record.kind == "string") { + console.log(“Data is string: “ + data); + } else if (record.kind == "json") { + processJSON(record.data); + } else if (record.kind == "url") { + console.log(“Data is URL: “ + record.data; + } else if (record.kind == "opaque") { + processBinary(data); + }); }; - function processBlob(data) { - console.log(“Blob size: ” + data.size + “ bytes”); - console.log(“Blob type: ” + data.type); - var reader = new FileReader(); - reader.addEventListener(“loadend”, function() { - console.log(“Blob data: ” + reader.result); - // Now send a response based on the data. - adapter.send({data: “Response to blob” }) - .then(() => { console.log("Send was successful")}) - .catch(() => { console.log("Send failed")}); - }); - reader.readAsText(data); + function processBinary(data) { + console.log("Binary data we know being a string: "); + console.log(String.fromCharCode.apply(null, new Uint16Array(data))); }; function processJSON(data) { - if (myCondition(data.myKnownProperty)) { - adapter.send({data: “Custom data”}); + var obj = JSON.parse(data); + console.log("My data: " + obj.myProperty.toString()); + }; ++
+ navigator.nfc.requestAdapter().then((adapter) => { + adapter.pushMessage([ + { kind: "text", type: "", data: “Data meant for peers”}]) + .then(() => { console.log("Message sent")}) + .catch(() => {console.log("Send failed, try again.")}); };
navigator.nfc.requestAdapter().then((adapter) => { console.log("Waiting for game state"); - adapter.onmessage = (event) => { - console.log("Game state received from: " + event.message.scope); - console.log("Game state: " + event.message.data); + adapter.watch({ url: "*://myserver/mygame/*"}, (message, url) => { + console.log("Game state received from: " + url; + console.log("Game state: " + message.data); // Now do some calculations and update the state. - adapter.send({ scope: event.message.scope, - data: [ { level: 3, points: 4500, lives: 3 } ] }) + adapter.pushMessage([ data: { level: 3, points: 4500, lives: 3 } ]) .then(() => { console.log("Send was successful")}) .catch(() => { console.log("Send failed")}); }; @@ -1179,19 +2428,25 @@ recently closed bugs.
The editors would like to express their gratitude to the former editors - Luc Yriarte and Samuel Ortiz, and also to Don Coleman, Jeffrey Yasskin, - Salvatore Iovene, and Alexander Shalamov for their technical guidance, + Luc Yriarte and Samuel Ortiz, and also to Don Coleman, Anne van Kesteren, + Domenic Denicola, Jonas Sickling, Jeffrey Yasskin, Alexander Shalamov, + Salvatore Iovene, and Rijubrata Bhaumik for their technical guidance, implementation feedback and support.
+ URL
+
is defined in [[!URL]].
+
+ The term
+ browsing context refers to the environment in which
+ Document objects are
+ presented to the user. A given browsing context has a single
+ origin and a single WindowProxy
object, but it
+ can have many Document
objects, with their associated
+ Window
objects. The browsing context identifies
+ the entity which invokes this API, which can be a web app, a
+ web page, or an
+ iframe.
+
+ The term + + origin is defined in [[!HTML5]]. +
++ The term + ASCII serialized origin is defined in [[!HTML5]]. +
++ NFC stands for Near Field Communications, short-range wireless + technology operating at 13.56 MHz which enables communication between + devices at a distance less than 10 cm. +
++ An NFC adapter is the software entity in the underlying + platform which provides access to NFC functionality implemented in a + given hardware element (NFC chip). A device may have multiple NFC + adapters, for instance a built-in one, and one attached via USB. +
++ An NFC tag is a passive NFC device. + The NFC tag is powered by magnetic induction when an active NFC + device is in proximity range. An NFC tag contains a single + NDEF message. +
++ An NFC peer is an active, powered device, which can interact + with other devices in order to exchange data using NFC. +
++ An NFC device is either an NFC peer, or an NFC tag. +
++ An NDEF message encapsulates one or more application-defined + NDEF records. NDEF is an abbreviation for NFC Forum + Data Exchange Format, a lightweight binary message format. NDEF messages + can be stored on an NFC tag or exchanged between NFC-enabled devices. +
++ An NDEF record has a maximum payload of 2^32-1 bytes. The record + also contains information about the payload size, type, and an optional + identifier. NFC Forum standardized a small set of useful data types to be + used in NDEF records, for instance text, URL, and binary data such as + media. In addition, there are record types designed for more complex + interactions, such as Smart Poster, and handover records. +
++ Part of the NDEF record is the NDEF Id field, which may or + may not be present. If present, it contains a maximum 256 octets long + string which is a URL and it is used for identifying the payload, + in an application specific way. +
++ The term NFC content is a synonym for NDEF message, + which can originate either from an NFC tag or an NFC peer. +
++ The term Web NFC origin is the ASCII serialized origin + of the browsing context that has written the Web NFC message. +
++ The Web NFC Id is a special URL stored in the + Web NFC record, and it is used for matching NFC content with + URL patterns specified by listeners. + For more details see the Web NFC Id section. +
++ A Web NFC record is a special NDEF record which identifies + Web NFC content meant for web pages, rather than generic + NFC content. For a detailed description see the + Web NFC record section. +
++ A Web NFC message represents a set of the NDEF records + from a given NDEF message and a special Web NFC record. + For more details see the Web NFC Message + format section. +
++ The term Web NFC content denotes all Web NFC messages + contained in an NDEF message. This version of the specification + supports one Web NFC message per NDEF message. +
++ The term trusted integrity NFC content refers to an + NDEF message, or an NDEF record, which can be trusted for + data integrity, i.e. the content is not changed by third party between + writing and reading. +
+ ++ The key security related definitions are the following. +
++ The term expressed permission refers to an act by the user, e.g. + via user interface or setting or host device platform features, using which + the user approves the permission of a browsing context to access the + given functionality. +
++ The term ask for forgiveness refers to some + form of unobtrusive notification that informs the user of an operation + while it is running. + User agents SHOULD provide the user with means to ignore similar future + operations from the same origin and advertise this to the user. +
++ The term prearranged trust relationship means that the + user agent has already established a trust relationship for a + certain operation using a platform specific mechanism, so that an + expressed permission from the user is not any more needed. + See also the + Prearranged trust relationship section. +
++ The term obtain permission for a certain operation indicates + that the user agent has either obtained expressed permission, or + asks for forgiveness, or ensured a + prearranged trust relationship exists. +
+ Discussions in + issues such as in + Verify security model, + Suggest a permission UI + flow, and + Simplify process for + obtaining permissions make it clear that NFC technology has a few + peculiarities with regards to content handling. In summary, +
+ Malicious 3rd parties can write arbitrary URL's into the + NDEF Id field, and provide a prepared attack vector as data to + services which use the Web NFC API as well. + Therefore the Web NFC Id cannot be considered the authentic + origin of the data of the NDEF message. +
+Web pages using the NFC API are not trusted. @@ -119,8 +332,13 @@ The following patterns have been considered:
Threat | -Comments | +Comments, possible mitigation |
---|---|---|
@@ -138,13 +356,22 @@ consent of the user. | + The user SHOULD be able to be aware of what data can be shared using + NFC from the given web page. Use permissions and user prompts for accessing personal data, minimize user data exposed to NFC. | |
Malicious web page overwrites tags without user consent. | -Permission and user prompt needed for writing tags. | ++ Make sure the write is additive to previous content. + Or, require permission and user prompt needed for writing tags. + Or, control what tags can be written by a given web page, for instance + a web page can write only a tag which can be connected to its origin. + Or, allow this since tags not meant to be written can be protected + by making them read only. + |
@@ -152,9 +379,9 @@ devices. | - Permission/user prompt for writing tags and peers. + The user SHOULD be able to be aware of what data can be shared using + NFC from the given web page. + Use permission/user prompt for writing tags and peers. | |
- This is a generic problem with all existing NFC tags; - implementations need security hardening; involuntary touch is low - probability due to short range and critical angle for reading; - it’s easier to attack elsewhere (e.g. WiFi and Bluetooth). + This is a generic problem with all existing NFC tags. + The data is considered application specific. + Implementations need security hardening. + Involuntary touch is low probability due to short range and critical + angle for reading. + It’s easier to attack elsewhere (e.g. WiFi and Bluetooth). | ||