caps/idl/nsIPrincipal.idl

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial