Blame caps/nsIPrincipal.idl

Packit f0b94e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
/* Defines the abstract interface for a principal. */
Packit f0b94e
Packit f0b94e
#include "nsISerializable.idl"
Packit f0b94e
Packit f0b94e
%{C++
Packit f0b94e
struct JSPrincipals;
Packit f0b94e
#include "nsCOMPtr.h"
Packit f0b94e
#include "nsTArray.h"
Packit f0b94e
#include "mozilla/DebugOnly.h"
Packit f0b94e
namespace mozilla {
Packit f0b94e
class OriginAttributes;
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Some methods have a fast path for the case when we're comparing a principal
Packit f0b94e
 * to itself. The situation may happen for example with about:blank documents.
Packit f0b94e
 */
Packit f0b94e
Packit f0b94e
#define DECL_FAST_INLINE_HELPER(method_)                       \
Packit f0b94e
  inline bool method_(nsIPrincipal* aOther)                    \
Packit f0b94e
  {                                                            \
Packit f0b94e
    mozilla::DebugOnly<bool> val = false;                      \
Packit f0b94e
    MOZ_ASSERT_IF(this == aOther,                              \
Packit f0b94e
                  NS_SUCCEEDED(method_(aOther, &val)) && val); \
Packit f0b94e
                                                               \
Packit f0b94e
    bool retVal = false;                                       \
Packit f0b94e
    return                                                     \
Packit f0b94e
      this == aOther ||                                        \
Packit f0b94e
      (NS_SUCCEEDED(method_(aOther, &retVal)) && retVal);      \
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
%}
Packit f0b94e
Packit f0b94e
interface nsIURI;
Packit f0b94e
interface nsIContentSecurityPolicy;
Packit f0b94e
interface nsIDOMDocument;
Packit f0b94e
Packit f0b94e
[ptr] native JSContext(JSContext);
Packit f0b94e
[ptr] native JSPrincipals(JSPrincipals);
Packit f0b94e
[ref] native PrincipalArray(const nsTArray<nsCOMPtr<nsIPrincipal>>);
Packit f0b94e
[ref] native const_OriginAttributes(const mozilla::OriginAttributes);
Packit f0b94e
Packit f0b94e
[scriptable, builtinclass, uuid(f75f502d-79fd-48be-a079-e5a7b8f80c8b)]
Packit f0b94e
interface nsIPrincipal : nsISerializable
Packit f0b94e
{
Packit f0b94e
    /**
Packit f0b94e
     * Returns whether the other principal is equivalent to this principal.
Packit f0b94e
     * Principals are considered equal if they are the same principal, or
Packit f0b94e
     * they have the same origin.
Packit f0b94e
     */
Packit f0b94e
    boolean equals(in nsIPrincipal other);
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Like equals, but takes document.domain changes into account.
Packit f0b94e
     */
Packit f0b94e
    boolean equalsConsideringDomain(in nsIPrincipal other);
Packit f0b94e
Packit f0b94e
    %{C++
Packit f0b94e
      DECL_FAST_INLINE_HELPER(Equals)
Packit f0b94e
      DECL_FAST_INLINE_HELPER(EqualsConsideringDomain)
Packit f0b94e
    %}
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns a hash value for the principal.
Packit f0b94e
     */
Packit f0b94e
    [noscript] readonly attribute unsigned long hashValue;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * The codebase URI to which this principal pertains.  This is
Packit f0b94e
     * generally the document URI.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute nsIURI URI;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * The domain URI to which this principal pertains.
Packit f0b94e
     * This is null unless script successfully sets document.domain to our URI
Packit f0b94e
     * or a superdomain of our URI.
Packit f0b94e
     * Setting this has no effect on the URI.
Packit f0b94e
     * See https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Changing_origin
Packit f0b94e
     */
Packit f0b94e
    [noscript] attribute nsIURI domain;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns whether the other principal is equal to or weaker than this
Packit f0b94e
     * principal. Principals are equal if they are the same object or they
Packit f0b94e
     * have the same origin.
Packit f0b94e
     *
Packit f0b94e
     * Thus a principal always subsumes itself.
Packit f0b94e
     *
Packit f0b94e
     * The system principal subsumes itself and all other principals.
Packit f0b94e
     *
Packit f0b94e
     * A null principal (corresponding to an unknown, hence assumed minimally
Packit f0b94e
     * privileged, security context) is not equal to any other principal
Packit f0b94e
     * (including other null principals), and therefore does not subsume
Packit f0b94e
     * anything but itself.
Packit f0b94e
     */
Packit f0b94e
    boolean subsumes(in nsIPrincipal other);
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Same as the previous method, subsumes(), but takes document.domain into
Packit f0b94e
     * account.
Packit f0b94e
     */
Packit f0b94e
    boolean subsumesConsideringDomain(in nsIPrincipal other);
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Same as the subsumesConsideringDomain(), but ignores the first party
Packit f0b94e
     * domain in its originAttributes.
Packit f0b94e
     */
Packit f0b94e
    boolean subsumesConsideringDomainIgnoringFPD(in nsIPrincipal other);
Packit f0b94e
Packit f0b94e
    %{C++
Packit f0b94e
      DECL_FAST_INLINE_HELPER(Subsumes)
Packit f0b94e
      DECL_FAST_INLINE_HELPER(SubsumesConsideringDomain)
Packit f0b94e
      DECL_FAST_INLINE_HELPER(SubsumesConsideringDomainIgnoringFPD)
Packit f0b94e
#undef DECL_FAST_INLINE_HELPER
Packit f0b94e
    %}
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Checks whether this principal is allowed to load the network resource
Packit f0b94e
     * located at the given URI under the same-origin policy. This means that
Packit f0b94e
     * codebase principals are only allowed to load resources from the same
Packit f0b94e
     * domain, the system principal is allowed to load anything, and null
Packit f0b94e
     * principals can only load URIs where they are the principal. This is
Packit f0b94e
     * changed by the optional flag allowIfInheritsPrincipal (which defaults to
Packit f0b94e
     * false) which allows URIs that inherit their loader's principal.
Packit f0b94e
     *
Packit f0b94e
     * If the load is allowed this function does nothing. If the load is not
Packit f0b94e
     * allowed the function throws NS_ERROR_DOM_BAD_URI.
Packit f0b94e
     *
Packit f0b94e
     * NOTE: Other policies might override this, such as the Access-Control
Packit f0b94e
     *       specification.
Packit f0b94e
     * NOTE: The 'domain' attribute has no effect on the behaviour of this
Packit f0b94e
     *       function.
Packit f0b94e
     *
Packit f0b94e
     *
Packit f0b94e
     * @param uri    The URI about to be loaded.
Packit f0b94e
     * @param report If true, will report a warning to the console service
Packit f0b94e
     *               if the load is not allowed.
Packit f0b94e
     * @param allowIfInheritsPrincipal   If true, the load is allowed if the
Packit f0b94e
     *                                   loadee inherits the principal of the
Packit f0b94e
     *                                   loader.
Packit f0b94e
     * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
Packit f0b94e
     */
Packit f0b94e
    void checkMayLoad(in nsIURI uri, in boolean report,
Packit f0b94e
                      in boolean allowIfInheritsPrincipal);
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * A Content Security Policy associated with this principal.
Packit f0b94e
     * Use this function to query the associated CSP with this principal.
Packit f0b94e
     * Please *only* use this function to *set* a CSP when you know exactly what you are doing.
Packit f0b94e
     * Most likely you want to call ensureCSP instead of setCSP.
Packit f0b94e
     */
Packit f0b94e
    [noscript] attribute nsIContentSecurityPolicy csp;
Packit f0b94e
Packit f0b94e
    /*
Packit f0b94e
     * Use this function to query a CSP associated with this principal.
Packit f0b94e
     * If no CSP is associated with this principal then one is created
Packit f0b94e
     * internally and setRequestContext is called on the CSP using aDocument.
Packit f0b94e
     *
Packit f0b94e
     * Please note if aDocument is null, then setRequestContext on the
Packit f0b94e
     * CSP object is called using the current principal.
Packit f0b94e
     */
Packit f0b94e
    [noscript] nsIContentSecurityPolicy ensureCSP(in nsIDOMDocument aDocument);
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * A speculative Content Security Policy associated with this
Packit f0b94e
     * principal. Set during speculative loading (preloading) and
Packit f0b94e
     * used *only* for preloads.
Packit f0b94e
     *
Packit f0b94e
     * If you want to query the CSP associated with that principal,
Packit f0b94e
     * then this is *not* what you want. Instead query 'csp'.
Packit f0b94e
     */
Packit f0b94e
    [noscript] readonly attribute nsIContentSecurityPolicy preloadCsp;
Packit f0b94e
Packit f0b94e
    /*
Packit f0b94e
     * Use this function to query a speculative CSP associated with this
Packit f0b94e
     * principal. If no speculative CSP is associated with this principal
Packit f0b94e
     * then one is created internally and setRequestContext is called on
Packit f0b94e
     * the CSP using aDocument.
Packit f0b94e
     *
Packit f0b94e
     * Please note if aDocument is null, then setRequestContext on the
Packit f0b94e
     * speculative CSP object is called using the current principal.
Packit f0b94e
     */
Packit f0b94e
    [noscript] nsIContentSecurityPolicy ensurePreloadCSP(in nsIDOMDocument aDocument);
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * The CSP of the principal in JSON notation.
Packit f0b94e
     * Note, that the CSP itself is not exposed to JS, but script
Packit f0b94e
     * should be able to obtain a JSON representation of the CSP.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute AString cspJSON;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * A dictionary of the non-default origin attributes associated with this
Packit f0b94e
     * nsIPrincipal.
Packit f0b94e
     *
Packit f0b94e
     * Attributes are tokens that are taken into account when determining whether
Packit f0b94e
     * two principals are same-origin - if any attributes differ, the principals
Packit f0b94e
     * are cross-origin, even if the scheme, host, and port are the same.
Packit f0b94e
     * Attributes should also be considered for all security and bucketing decisions,
Packit f0b94e
     * even those which make non-standard comparisons (like cookies, which ignore
Packit f0b94e
     * scheme, or quotas, which ignore subdomains).
Packit f0b94e
     *
Packit f0b94e
     * If you're looking for an easy-to-use canonical stringification of the origin
Packit f0b94e
     * attributes, see |originSuffix| below.
Packit f0b94e
     */
Packit f0b94e
    [implicit_jscontext]
Packit f0b94e
    readonly attribute jsval originAttributes;
Packit f0b94e
Packit f0b94e
    [noscript, notxpcom, nostdcall, binaryname(OriginAttributesRef)]
Packit f0b94e
    const_OriginAttributes OriginAttributesRef();
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * A canonical representation of the origin for this principal. This
Packit f0b94e
     * consists of a base string (which, for codebase principals, is of the
Packit f0b94e
     * format scheme://host:port), concatenated with |originAttributes| (see
Packit f0b94e
     * below).
Packit f0b94e
     *
Packit f0b94e
     * We maintain the invariant that principalA.equals(principalB) if and only
Packit f0b94e
     * if principalA.origin == principalB.origin.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute ACString origin;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * The base part of |origin| without the concatenation with |originSuffix|.
Packit f0b94e
     * This doesn't have the important invariants described above with |origin|,
Packit f0b94e
     * and as such should only be used for legacy situations.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute ACString originNoSuffix;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * A string of the form !key1=value1&key2=value2, where each pair represents
Packit f0b94e
     * an attribute with a non-default value. If all attributes have default
Packit f0b94e
     * values, this is the empty string.
Packit f0b94e
     *
Packit f0b94e
     * The value of .originSuffix is automatically serialized into .origin, so any
Packit f0b94e
     * consumers using that are automatically origin-attribute-aware. Consumers with
Packit f0b94e
     * special requirements must inspect and compare .originSuffix manually.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute AUTF8String originSuffix;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * The base domain of the codebase URI to which this principal pertains
Packit f0b94e
     * (generally the document URI), handling null principals and
Packit f0b94e
     * non-hierarchical schemes correctly.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute ACString baseDomain;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Gets the id of the app this principal is inside.  If this principal is
Packit f0b94e
     * not inside an app, returns nsIScriptSecurityManager::NO_APP_ID.
Packit f0b94e
     *
Packit f0b94e
     * Note that this principal does not necessarily have the permissions of
Packit f0b94e
     * the app identified by appId.  For example, this principal might
Packit f0b94e
     * correspond to an iframe whose origin differs from that of the app frame
Packit f0b94e
     * containing it.  In this case, the iframe will have the appId of its
Packit f0b94e
     * containing app frame, but the iframe must not run with the app's
Packit f0b94e
     * permissions.
Packit f0b94e
     *
Packit f0b94e
     * Similarly, this principal might correspond to an <iframe mozbrowser>
Packit f0b94e
     * inside an app frame; in this case, the content inside the iframe should
Packit f0b94e
     * not have any of the app's permissions, even if the iframe is at the same
Packit f0b94e
     * origin as the app.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute unsigned long appId;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Gets the ID of the add-on this principal belongs to.
Packit f0b94e
     */
Packit f0b94e
    readonly attribute AString addonId;
Packit f0b94e
Packit f0b94e
    readonly attribute nsISupports addonPolicy;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Gets the id of the user context this principal is inside.  If this
Packit f0b94e
     * principal is inside the default userContext, this returns
Packit f0b94e
     * nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute unsigned long userContextId;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Gets the id of the private browsing state of the context containing
Packit f0b94e
     * this principal. If the principal has a private browsing value of 0, it
Packit f0b94e
     * is not in private browsing.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute unsigned long privateBrowsingId;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns true iff the principal is inside an isolated mozbrowser element.
Packit f0b94e
     * <xul:browser> is not considered to be a mozbrowser element.
Packit f0b94e
     * <iframe mozbrowser noisolation> does not count as isolated since
Packit f0b94e
     * isolation is disabled.  Isolation can only be disabled if the
Packit f0b94e
     * containing document is chrome.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute boolean isInIsolatedMozBrowserElement;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns true iff this is a null principal (corresponding to an
Packit f0b94e
     * unknown, hence assumed minimally privileged, security context).
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute boolean isNullPrincipal;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns true iff this principal corresponds to a codebase origin.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute boolean isCodebasePrincipal;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns true iff this is an expanded principal.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute boolean isExpandedPrincipal;
Packit f0b94e
Packit f0b94e
    /**
Packit f0b94e
     * Returns true iff this is the system principal.
Packit f0b94e
     */
Packit f0b94e
    [infallible] readonly attribute boolean isSystemPrincipal;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * If SystemPrincipal is too risky to use, but we want a principal to access
Packit f0b94e
 * more than one origin, ExpandedPrincipals letting us define an array of
Packit f0b94e
 * principals it subsumes. So script with an ExpandedPrincipals will gain
Packit f0b94e
 * same origin access when at least one of its principals it contains gained
Packit f0b94e
 * sameorigin acccess. An ExpandedPrincipal will be subsumed by the system
Packit f0b94e
 * principal, and by another ExpandedPrincipal that has all its principals.
Packit f0b94e
 * It is added for jetpack content-scripts to let them interact with the
Packit f0b94e
 * content and a well defined set of other domains, without the risk of
Packit f0b94e
 * leaking out a system principal to the content. See: Bug 734891
Packit f0b94e
 */
Packit f0b94e
[uuid(f3e177Df-6a5e-489f-80a7-2dd1481471d8)]
Packit f0b94e
interface nsIExpandedPrincipal : nsISupports
Packit f0b94e
{
Packit f0b94e
  /**
Packit f0b94e
   * An array of principals that the expanded principal subsumes.
Packit f0b94e
   *
Packit f0b94e
   * When an expanded principal is used as a triggering principal for a
Packit f0b94e
   * request that inherits a security context, one of its constitutent
Packit f0b94e
   * principals is inherited rather than the expanded principal itself. The
Packit f0b94e
   * last principal in the whitelist is the default principal to inherit.
Packit f0b94e
   *
Packit f0b94e
   * Note: this list is not reference counted, it is shared, so
Packit f0b94e
   * should not be changed and should only be used ephemerally.
Packit f0b94e
   */
Packit f0b94e
  [noscript, notxpcom, nostdcall]
Packit f0b94e
  PrincipalArray WhiteList();
Packit f0b94e
};