Privileged Contexts

W3C Working Draft

This version:
Latest version:
Editor's Draft:
Previous Versions:
Version History:
Feedback: with subject line “[powerful-features] … message topic …” (archives)
Issue Tracking:
Inline In Spec
(Google Inc.)
(Yahoo! Inc.)
Bug Reports:
via the w3c/webappsec repository on GitHub


This specification provides guidelines for user agent implementors and spec authors for implementing features whose properties dictate that they be exposed to the web only within a trustworthy environment.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at

This document was published by the Web Application Security Working Group as a Working Draft. This document is intended to become a W3C Recommendation.

The (archived) public mailing list (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “powerful-features” in the subject, preferably like this: “[powerful-features] …summary of comment…

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by the Web Application Security Working Group.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 August 2014 W3C Process Document.

Table of Contents

1. Introduction

This section is not normative.

As the Web platform is extended to enable more useful and powerful applications, it becomes increasingly important to ensure that the features which enable those applications are enabled only in contexts which meet a minimum security bar. This document outlines threat models for feature abuse on the Web and outline normative requirements which should be incorporated into documents specifying new features.

The most obvious of the requirements discussed here is that application code with access to sensitive or private data be delivered over authenticated and confidential channels that guarantee data integrity. Delivering code securely cannot ensure that an application will always meet a user’s security and privacy requirments, but it is a necessary precondition.

2. Key Concepts and Terminology

privileged context
A settings object is considered a privileged context if the algorithm defined in §5.1 Is settings object a privileged context? returns Privileged when executed upon it. Moreover:
embedding document
Given a Document A, the embedding document of A is the Document through which A’s browsing context is nested.

3. Should [insert feature here] require a privileged context?

This section is non-normative.

Certain web platform features that have a distinct impact on a user’s security or privacy should be available for use only in privileged contexts.

Broadly speaking, we consider a feature powerful enough to restrict when it fits into one or more of the following categories:

  1. The feature provides access to sensitive data (personally-identifying information, credentials, payment instruments, and so on). [CREDENTIAL-MANAGEMENT] is an example of such an API.
  2. The feature provides access to sensor data on a user’s device (camera, microphone, and GPS being particularly noteworthy, but certainly including less obviously dangerous sensors like the accelerometer). [GEOLOCATION-API] and [MEDIACAPTURE-STREAMS] are historical examples.
  3. The feature provides access to or information about other devices a user has access to. [DISCOVERY] and [BLUETOOTH] are good examples.
  4. The feature exposes temporary or persistent identifiers, including identifiers which reset themselves after some period of time (e.g. sessionStorage), identifiers the user can manually reset (e.g. [ENCRYPTED-MEDIA], Cookies [RFC6265], and [IndexedDB]), as well as identifying hardware features the user can’t easily reset.
  5. The feature introduces some state for an origin which persists across browsing sessions. [SERVICE-WORKERS] is a great example.
  6. The feature manipulates a user agent’s native UI in some way which removes, obscures, or manipulates details relevant to a user’s understanding of her context. [FULLSCREEN], for instance.
  7. The feature introduces some functionality for which user permission will be required.

This list is non-exhaustive, but should give you a feel for the types of features we should be concerned about when writing or implementing specifications.

Note: While restricting the feature itself to privileged contexts is critical, we ought not forget that facilities that carry such information (such as new network access mechanisms, or other generic functions with access to network data) are equally sensitive.

3.1. Threat Models

Granting permissions to unauthenticated origins is, in the presence of a network attacker, equivalent to granting the permissions to any origin. The state of the Internet is such that we must indeed assume that a network attacker is present. Generally, network attackers fall into 2 classes: passive and active.

3.1.1. Passive Network Attacker

A "Passive Network Attacker" is a party who is able to observe traffic flows but who lacks the ability or chooses not to modify traffic at the layers which this specification is concerned with.

Surveillance of networks in this manner "subverts the intent of communicating parties without the agreement of these parties" and one "cannot defend against the most nefarious actors while allowing monitoring by other actors no matter how benevolent some might consider them to be." [RFC7258] Therefore, the algorithms defined in this document require mechansims that provide for the privacy of data at the application layer, not simply integrity.

3.1.2. Active Network Attacker

An "Active Network Attacker" has all the capabilities of a "Passive Network Attacker" and is additionally able to modify, block or replay any data transiting the network. These capabilities are available to potential adversaries at many levels of capability, from compromised devices offering or simply participating in public wireless networks, to Internet Service Providers indirectly introducing security and privacy vulnerabilities while manipulating traffic for financial gain ([VERIZON] and [COMCAST] are recent examples), to parties with direct intent to compromise security or privacy who are able to target individual users, organizations or even entire populations.

4. Restricting Features

4.1. New Features

When writing a specification for new features, we recommend that authors and editors guard sensitive APIs with checks against §5.1 Is settings object a privileged context? . For example, something like the following would be a good approach:

  1. If the incumbent settings object is not a privileged context, then [insert something appropriate here: perhaps you could reject a Promise with a SecurityError, call an error callback, deny a permission request, etc.].

Note: If you choose to copy/paste the above text for your spec, do remember to put an action appropriate for your use case in place of the placeholder text.

4.2. Legacy Features

The list above clearly includes some existing functionality that is currently available to the web over insecure channels. We recommend that such legacy functionality begin requiring a privileged context as quickly as is reasonably possible.

  1. If such a feature is not widely implemented, we recommend that the specification be immediately modified to include a restriction to privileged contexts.
  2. If such a feature is widely implemented, but not yet in wide use, we recommend that it be quickly restricted to privileged contexts by adding a check as described in §4.1 New Features to existing implementations, and modifying the specification accordingly.
  3. If such a feature is in wide use, we recommend that the existing functionality be deprecated; the specification should be modified to note that it does not conform to the restrictions outlined in this document, and a plan should be developed to both offer a conformant version of the feature and to migrate existing users into that new version.

4.2.1. Example: Geolocation

The [GEOLOCATION-API] is a good concrete example of such an feature; it is widely implemented and used on a large number of insecure sites. A reasonable path forward might look like this:

  1. Modify the specification to include checks against [[#settings-privileged] before executing the algorithms for getCurrentPosition() and watchPosition().

    If §5.1 Is settings object a privileged context? returns Not Privileged, then the algorithms should be aborted, and the errorCallback invoked with a code of PERMISSION_DENIED.

  2. User agents should announce clear intentions to disable the API for unprivileged contexts on a specific date, and warn developers accordingly (via console messages, for example).
  3. Leading up to the flag day, user agents should announce a deprecation schedule to ensure both that site authors recognize the need to modify their code before it simply stops working altogether, and to protect users in the meantime. Such a plan might include:
    • Disallowing persistent permission grants to insecure origins
    • Coarsening the accuracy of the API for insecure origins (perhaps consistently returning city-level data rather than high-accuracy data)
    • UI modifications to inform users and site authors of the risk

5. Algorithms

5.1. Is settings object a privileged context?

Given a settings object settings, this algorithm returns Privileged if the object represents a privileged context, and Not Privileged otherwise.

  1. If settings' TLS state is not authenticated:
    1. Let origin be settings' origin.
    2. If origin is a globally unique identifier, set origin to the origin of settings’s API base URL.

      Note: This is future-proofing against a world where sandboxing Worker is a thing.

      "API base URL" isn’t correct. We should use whatever gets produced as a result of bug 27146.

    3. If the result of executing the §5.2 Is origin potentially trustworthy? algorithm on origin is not Potentially Trustworthy, return Not Privileged.

    TLS State is poorly defined. For example, we should ensure that sandboxed documents retain the TLS State associated with their transport mechanism. See bug 27190.

  2. If settings has a responsible document document, then:

    Note: If settings maps to a Document (either directly, or as the responsible document of a Worker), we’ll walk all the way up the document’s ancestor chain to verify that the whole chain is privileged.

    1. Let documents to check be a list of Documents containing document and the active document in each of document’s ancestor browsing contexts.
    2. For each ancestor in documents to check:
      1. If ancestor corresponds to an IFrame srcdoc Document, skip to the next ancestor.
      2. If ancestor’s incumbent settings object’s TLS State is Authenticated, skip to the next ancestor.
      3. Let origin be ancestor’s origin if ancestor’s active sandboxing flag set does not have its sandboxed origin browsing context flag set, and the origin of ancestor’s URL otherwise.
      4. If the result of executing the §5.2 Is origin potentially trustworthy? algorithm on origin is not Potentially Trustworthy, return Not Privileged.
  3. Return Privileged

5.2. Is origin potentially trustworthy?

Certain origins are always potentially trustworthy. In particular, UAs MUST treat file URLs and URLs with hostnames names equivalent to "localhost" as potentially trustworthy. In principle the UA could treat local files and local web servers as untrustworthy. However, given the information that is available to the UA at runtime, the resources appear to have been transported securely. Additionally, treating such resources as potentially trustworthy is convenient for developers building an application before deploying it to the public.

A user agent MAY choose to extend this trust to other, vendor-specific URL schemes like app: or chrome-extension:.

Given an origin origin, the following algorithm returns Potentially Trustworthy or Not Trustworthy as appropriate.

  1. If origin is a potentially secure origin, return Potentially Trustworthy.

    Note: The origin of blob: and filesystem: URLs is the origin of the context in which they were created. Therefore, blobs created in an potentially secure origin will themselves be potentially secure. The origin of data: and javascript: URLs is an opaque identifier, which will not be considered potentially secure.

  2. If origin’s host component is or falls within localhost. [RFC6761], return Potentially Trustworthy.
  3. If origin’s host component matches one of the CIDR notations or ::1/128 [RFC4632], return Potentially Trustworthy.
  4. If origin’s scheme component is file, return Potentially Trustworthy.
  5. If origin’s scheme component is one which the user agent considers to be authenticated, return Potentially Trustworthy.

    Note: See §6.1 Packaged Applications for detail here.

  6. If origin has been configured as a trustworthy origin, return Potentially Trustworthy.

    Note: See §6.2 Development Environments for detail here.

  7. Return Not Trusted.

6. Implementation Considerations

6.1. Packaged Applications

User agents that support packaged applications MAY whitelist specific URL schemes whose contents are authenticated by the user agent. For example, FirefoxOS application resources are referred to by a URL whose scheme component is app:. Likewise, Chrome’s extensions and apps live on chrome-extension: schemes. These could reasonably be considered trusted origins.

6.2. Development Environments

In order to support developers who run staging servers on non-loopback hosts, user agents MAY allow users to configure specific sets of origins as trustworthy, even though §5.2 Is origin potentially trustworthy? would normally return Not Trusted.

7. Acknowledgements

This document is largely based on the Chrome Security team’s work on [POWERFUL-NEW-FEATURES]. Chris Palmer, Ryan Sleevi, and David Dorwin have been particularly engaged. Anne van Kesteren and Henri Sivonen have also provided very helpful feedback.


Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word "Note" and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Conformance Classes

A conformant user agent must implement all the requirements listed in this specification that are applicable to user agents.

A conformant server must implement all the requirements listed in this specification that are applicable to servers.


Terms defined by this specification

Terms defined by reference


Normative References

Anne van Kesteren. Fetch. Living Standard. URL:
Mike West. Mixed Content. LCWD. URL:
Vince Fuller; Tony Li. Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan. RFC. URL:
Adam Barth. The Web Origin Concept. RFC. URL:
Stuart Cheshire; Marc Krochmal. Special-Use Domain Names. RFC. URL:
Anne van Kesteren. URL. Living Standard. URL:
Charles McCathie Nevile. World Wide Web Consortium Process Document. URL:
Anne van Kesteren; et al. W3C DOM4. 10 July 2014. LCWD. URL:
Andrei Popescu. Geolocation API Specification. 24 October 2013. REC. URL:
Robin Berjon; et al. HTML5. 28 October 2014. REC. URL:
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL:
Alex Russell; Jungkee Song. Service Workers. 8 May 2014. WD. URL:
Ian Hickson. Web Workers. 1 May 2012. CR. URL:

Informative References

Jeffrey Yasskin; Vincent Scheib. Web Bluetooth. URL:
David Kravets. Comcast Wi-Fi serving self-promotional ads via JavaScript injection. URL:
Mike West. Credential Management. ED. URL:
Rich Tibbett. Network Service Discovery. URL:
Nikunj Mehta; et al. Indexed Database API. 4 July 2013. CR. URL:
Chrome Security Team. Prefer Secure Origins For Powerful New Features. URL:
Stephen Farrell; Hannes Tschofenig. Pervasive Monitoring Is an Attack. RFC. URL:
Mark Bergen; Alex Kantrowitz. Verizon looks to target its mobile subscribers with ads. URL:
David Dorwin; et al. Encrypted Media Extensions. 28 August 2014. WD. URL:
Anne van Kesteren; Tantek Çelik. Fullscreen. 3 July 2012. WD. URL:
Daniel Burnett; et al. Media Capture and Streams. 3 September 2013. WD. URL:
A. Barth. HTTP State Management Mechanism. April 2011. Proposed Standard. URL:

Issues Index

"API base URL" isn’t correct. We should use whatever gets produced as a result of bug 27146.
TLS State is poorly defined. For example, we should ensure that sandboxed documents retain the TLS State associated with their transport mechanism. See bug 27190.