caps/idl/nsIPrincipal.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* Defines the abstract interface for a principal. */
     8 #include "nsISerializable.idl"
    10 %{C++
    11 struct JSPrincipals;
    12 #include "nsCOMPtr.h"
    13 #include "nsTArray.h"
    14 %}
    16 interface nsIURI;
    17 interface nsIContentSecurityPolicy;
    19 [ptr] native JSContext(JSContext);
    20 [ptr] native JSPrincipals(JSPrincipals);
    21 [ptr] native PrincipalArray(nsTArray<nsCOMPtr<nsIPrincipal> >);
    23 [scriptable, builtinclass, uuid(204555e7-04ad-4cc8-9f0e-840615cc43e8)]
    24 interface nsIPrincipal : nsISerializable
    25 {
    26     /**
    27      * Returns whether the other principal is equivalent to this principal.
    28      * Principals are considered equal if they are the same principal, or
    29      * they have the same origin.
    30      */
    31     boolean equals(in nsIPrincipal other);
    33     /**
    34      * Like equals, but takes document.domain changes into account.
    35      */
    36     boolean equalsConsideringDomain(in nsIPrincipal other);
    38     %{C++
    39     inline bool Equals(nsIPrincipal* aOther) {
    40       bool equal = false;
    41       return NS_SUCCEEDED(Equals(aOther, &equal)) && equal;
    42     }
    44     inline bool EqualsConsideringDomain(nsIPrincipal* aOther) {
    45       bool equal = false;
    46       return NS_SUCCEEDED(EqualsConsideringDomain(aOther, &equal)) && equal;
    47     }
    48     %}
    50     /**
    51      * Returns a hash value for the principal.
    52      */
    53     [noscript] readonly attribute unsigned long hashValue;
    55     /**
    56      * The codebase URI to which this principal pertains.  This is
    57      * generally the document URI.
    58      */
    59     readonly attribute nsIURI URI;
    61     /**
    62      * The domain URI to which this principal pertains.
    63      * This is congruent with HTMLDocument.domain, and may be null.
    64      * Setting this has no effect on the URI.
    65      */
    66     [noscript] attribute nsIURI domain;
    68     /**
    69      * The origin of this principal's codebase URI.
    70      * An origin is defined as: scheme + host + port.
    71      */
    72     // XXXcaa this should probably be turned into an nsIURI.
    73     // The system principal's origin should be some caps namespace
    74     // with a chrome URI.  All of chrome should probably be the same.
    75     readonly attribute string origin;
    77     /**
    78      * Returns whether the other principal is equal to or weaker than this
    79      * principal. Principals are equal if they are the same object or they
    80      * have the same origin.
    81      *
    82      * Thus a principal always subsumes itself.
    83      *
    84      * The system principal subsumes itself and all other principals.
    85      *
    86      * A null principal (corresponding to an unknown, hence assumed minimally
    87      * privileged, security context) is not equal to any other principal
    88      * (including other null principals), and therefore does not subsume
    89      * anything but itself.
    90      */
    91     boolean subsumes(in nsIPrincipal other);
    93     /**
    94      * Same as the previous method, subsumes(), but takes document.domain into
    95      * account.
    96      */
    97     boolean subsumesConsideringDomain(in nsIPrincipal other);
    99     %{C++
   100     inline bool Subsumes(nsIPrincipal* aOther) {
   101       bool subsumes = false;
   102       return NS_SUCCEEDED(Subsumes(aOther, &subsumes)) && subsumes;
   103     }
   105     inline bool SubsumesConsideringDomain(nsIPrincipal* aOther) {
   106       bool subsumes = false;
   107       return NS_SUCCEEDED(SubsumesConsideringDomain(aOther, &subsumes)) && subsumes;
   108     }
   109     %}
   111     /**
   112      * Checks whether this principal is allowed to load the network resource
   113      * located at the given URI under the same-origin policy. This means that
   114      * codebase principals are only allowed to load resources from the same
   115      * domain, the system principal is allowed to load anything, and null
   116      * principals are not allowed to load anything. This is changed slightly
   117      * by the optional flag allowIfInheritsPrincipal (which defaults to false)
   118      * which allows the load of a data: URI (which inherits the principal of
   119      * its loader) or a URI with the same principal as its loader (eg. a
   120      * Blob URI).
   121      * In these cases, with allowIfInheritsPrincipal set to true, the URI can
   122      * be loaded by a null principal.
   123      *
   124      * If the load is allowed this function does nothing. If the load is not
   125      * allowed the function throws NS_ERROR_DOM_BAD_URI.
   126      *
   127      * NOTE: Other policies might override this, such as the Access-Control
   128      *       specification.
   129      * NOTE: The 'domain' attribute has no effect on the behaviour of this
   130      *       function.
   131      *
   132      *
   133      * @param uri    The URI about to be loaded.
   134      * @param report If true, will report a warning to the console service
   135      *               if the load is not allowed.
   136      * @param allowIfInheritsPrincipal   If true, the load is allowed if the
   137      *                                   loadee inherits the principal of the
   138      *                                   loader.
   139      * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
   140      */
   141     void checkMayLoad(in nsIURI uri, in boolean report,
   142                       in boolean allowIfInheritsPrincipal);
   144     /**
   145      * A Content Security Policy associated with this principal.
   146      */
   147     [noscript] attribute nsIContentSecurityPolicy csp;
   149     /**
   150      * Returns the jar prefix of the principal.
   151      * The jar prefix is a string that can be used to isolate data or
   152      * permissions between different principals while taking into account
   153      * parameters like the app id or the fact that the principal is embedded in
   154      * a mozbrowser.
   155      * Some principals will return an empty string.
   156      * Some principals will assert if you try to access the jarPrefix.
   157      *
   158      * The jarPrefix is intended to be an opaque identifier. It is currently
   159      * "human-readable" but no callers should assume it will stay as is and
   160      * it might be crypto-hashed at some point.
   161      */
   162     readonly attribute AUTF8String jarPrefix;
   164     /**
   165      * The base domain of the codebase URI to which this principal pertains
   166      * (generally the document URI), handling null principals and
   167      * non-hierarchical schemes correctly.
   168      */
   169     readonly attribute ACString baseDomain;
   171     const short APP_STATUS_NOT_INSTALLED = 0;
   172     const short APP_STATUS_INSTALLED     = 1;
   173     const short APP_STATUS_PRIVILEGED    = 2;
   174     const short APP_STATUS_CERTIFIED     = 3;
   176     /**
   177      * Gets the principal's app status, which indicates whether the principal
   178      * corresponds to "app code", and if it does, how privileged that code is.
   179      * This method returns one of the APP_STATUS constants above.
   180      *
   181      * Note that a principal may have
   182      *
   183      *   appId != nsIScriptSecurityManager::NO_APP_ID &&
   184      *   appId != nsIScriptSecurityManager::UNKNOWN_APP_ID
   185      *
   186      * and still have appStatus == APP_STATUS_NOT_INSTALLED.  That's because
   187      * appId identifies the app that contains this principal, but a window
   188      * might be contained in an app and not be running code that the app has
   189      * vouched for.  For example, the window might be inside an <iframe
   190      * mozbrowser>, or the window's origin might not match the app's origin.
   191      *
   192      * If you're doing a check to determine "does this principal correspond to
   193      * app code?", you must check appStatus; checking appId != NO_APP_ID is not
   194      * sufficient.
   195      */
   196     [infallible] readonly attribute unsigned short appStatus;
   198     /**
   199      * Gets the id of the app this principal is inside.  If this principal is
   200      * not inside an app, returns nsIScriptSecurityManager::NO_APP_ID.
   201      *
   202      * Note that this principal does not necessarily have the permissions of
   203      * the app identified by appId.  For example, this principal might
   204      * correspond to an iframe whose origin differs from that of the app frame
   205      * containing it.  In this case, the iframe will have the appId of its
   206      * containing app frame, but the iframe must not run with the app's
   207      * permissions.
   208      *
   209      * Similarly, this principal might correspond to an <iframe mozbrowser>
   210      * inside an app frame; in this case, the content inside the iframe should
   211      * not have any of the app's permissions, even if the iframe is at the same
   212      * origin as the app.
   213      *
   214      * If you're doing a security check based on appId, you must check
   215      * appStatus as well.
   216      */
   217     [infallible] readonly attribute unsigned long appId;
   219     /**
   220      * Returns true iff the principal is inside a browser element.  (<iframe
   221      * mozbrowser mozapp> does not count as a browser element.)
   222      */
   223     [infallible] readonly attribute boolean isInBrowserElement;
   225     /**
   226      * Returns true if this principal has an unknown appId. This shouldn't
   227      * generally be used. We only expose it due to not providing the correct
   228      * appId everywhere where we construct principals.
   229      */
   230     [infallible] readonly attribute boolean unknownAppId;
   232     /**
   233      * Returns true iff this principal is a null principal (corresponding to an
   234      * unknown, hence assumed minimally privileged, security context).
   235      */
   236     [infallible] readonly attribute boolean isNullPrincipal;
   237 };
   239 /**
   240  * If nsSystemPrincipal is too risky to use, but we want a principal to access
   241  * more than one origin, nsExpandedPrincipals letting us define an array of
   242  * principals it subsumes. So script with an nsExpandedPrincipals will gain
   243  * same origin access when at least one of its principals it contains gained
   244  * sameorigin acccess. An nsExpandedPrincipal will be subsumed by the system
   245  * principal, and by another nsExpandedPrincipal that has all its principals.
   246  * It is added for jetpack content-scripts to let them interact with the
   247  * content and a well defined set of other domains, without the risk of
   248  * leaking out a system principal to the content. See: Bug 734891
   249  */
   250 [uuid(f3e177Df-6a5e-489f-80a7-2dd1481471d8)]
   251 interface nsIExpandedPrincipal : nsISupports
   252 {
   253   /**
   254    * An array of principals that the expanded principal subsumes.
   255    * Note: this list is not reference counted, it is shared, so
   256    * should not be changed and should only be used ephemerally.
   257    */
   258   [noscript] readonly attribute PrincipalArray whiteList;
   259 };

mercurial