2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-01-21 10:41:24 -08:00
|
|
|
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
|
|
|
|
interface nsIURI;
|
|
|
|
interface nsIHttpChannel;
|
|
|
|
interface nsIDocShell;
|
|
|
|
|
|
|
|
/**
|
2012-10-15 13:54:58 -07:00
|
|
|
* nsIContentSecurityPolicy
|
2013-09-12 09:25:32 -07:00
|
|
|
* Describes an XPCOM component used to model and enforce CSPs. Instances of
|
|
|
|
* this class may have multiple policies within them, but there should only be
|
|
|
|
* one of these per document/principal.
|
2010-01-21 10:41:24 -08:00
|
|
|
*/
|
|
|
|
|
2013-11-08 09:20:43 -08:00
|
|
|
[scriptable, uuid(781b6511-f1fa-4e2c-8eff-1739d091eb2f)]
|
2010-01-21 10:41:24 -08:00
|
|
|
interface nsIContentSecurityPolicy : nsISupports
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to true when the CSP has been read in and parsed and is ready to
|
|
|
|
* enforce. This is a barrier for the nsDocument so it doesn't load any
|
|
|
|
* sub-content until either it knows that a CSP is ready or will not be used.
|
|
|
|
*/
|
|
|
|
attribute boolean isInitialized;
|
|
|
|
|
|
|
|
/**
|
2013-09-12 09:25:32 -07:00
|
|
|
* Accessor method for a read-only string version of the policy at a given
|
|
|
|
* index.
|
2010-01-21 10:41:24 -08:00
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
AString getPolicy(in unsigned long index);
|
2010-01-21 10:41:24 -08:00
|
|
|
|
|
|
|
/**
|
2013-09-12 09:25:32 -07:00
|
|
|
* Returns the number of policies attached to this CSP instance. Useful with
|
|
|
|
* getPolicy().
|
2010-01-21 10:41:24 -08:00
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
attribute long policyCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a policy associated with this CSP context.
|
|
|
|
* @throws NS_ERROR_FAILURE if the index is out of bounds or invalid.
|
|
|
|
*/
|
|
|
|
void removePolicy(in unsigned long index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse and install a CSP policy.
|
|
|
|
* @param aPolicy
|
|
|
|
* String representation of the policy (e.g., header value)
|
|
|
|
* @param selfURI
|
|
|
|
* the URI of the protected document/principal
|
|
|
|
* @param reportOnly
|
|
|
|
* Should this policy affect content, script and style processing or
|
|
|
|
* just send reports if it is violated?
|
|
|
|
* @param specCompliant
|
|
|
|
* Whether or not the policy conforms to the W3C specification.
|
|
|
|
* If this is false, that indicates this policy is from the older
|
|
|
|
* implementation with different semantics and directive names.
|
|
|
|
*/
|
|
|
|
void appendPolicy(in AString policyString, in nsIURI selfURI,
|
|
|
|
in boolean reportOnly, in boolean specCompliant);
|
2010-01-21 10:41:24 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this policy allows in-page script.
|
2013-09-12 09:25:32 -07:00
|
|
|
* @param shouldReportViolations
|
2012-10-15 13:54:58 -07:00
|
|
|
* Whether or not the use of inline script should be reported.
|
|
|
|
* This function always returns "true" for report-only policies, but when
|
2013-09-12 09:25:32 -07:00
|
|
|
* any policy (report-only or otherwise) is violated,
|
|
|
|
* shouldReportViolations is true as well.
|
2012-10-15 13:54:58 -07:00
|
|
|
* @return
|
|
|
|
* Whether or not the effects of the inline script should be allowed
|
|
|
|
* (block the compilation if false).
|
2010-01-21 10:41:24 -08:00
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
boolean getAllowsInlineScript(out boolean shouldReportViolations);
|
2010-01-21 10:41:24 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* whether this policy allows eval and eval-like functions
|
|
|
|
* such as setTimeout("code string", time).
|
2013-09-12 09:25:32 -07:00
|
|
|
* @param shouldReportViolations
|
2012-10-15 13:54:58 -07:00
|
|
|
* Whether or not the use of eval should be reported.
|
2013-09-12 09:25:32 -07:00
|
|
|
* This function returns "true" when violating report-only policies, but
|
|
|
|
* when any policy (report-only or otherwise) is violated,
|
|
|
|
* shouldReportViolations is true as well.
|
2012-10-15 13:54:58 -07:00
|
|
|
* @return
|
|
|
|
* Whether or not the effects of the eval call should be allowed
|
|
|
|
* (block the call if false).
|
2010-01-21 10:41:24 -08:00
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
boolean getAllowsEval(out boolean shouldReportViolations);
|
2010-01-21 10:41:24 -08:00
|
|
|
|
2012-08-30 10:58:24 -07:00
|
|
|
/**
|
|
|
|
* Whether this policy allows in-page styles.
|
|
|
|
* This includes <style> tags with text content and style="" attributes in
|
|
|
|
* HTML elements.
|
2013-09-12 09:25:32 -07:00
|
|
|
* @param shouldReportViolations
|
|
|
|
* Whether or not the use of inline style should be reported.
|
|
|
|
* If there are report-only policies, this function may return true
|
|
|
|
* (don't block), but one or more policy may still want to send
|
|
|
|
* violation reports so shouldReportViolations will be true even if the
|
|
|
|
* inline style should be permitted.
|
2012-08-30 10:58:24 -07:00
|
|
|
* @return
|
2013-09-12 09:25:32 -07:00
|
|
|
* Whether or not the effects of the inline style should be allowed
|
|
|
|
* (block the rules if false).
|
2012-08-30 10:58:24 -07:00
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
boolean getAllowsInlineStyle(out boolean shouldReportViolations);
|
2012-08-30 10:58:24 -07:00
|
|
|
|
2013-11-08 09:20:43 -08:00
|
|
|
/**
|
|
|
|
* Whether this policy accepts the given nonce
|
|
|
|
* @param aNonce
|
|
|
|
* The nonce string to check against the policy
|
|
|
|
* @param aContentType
|
|
|
|
* The type of element on which we encountered this nonce
|
|
|
|
* @param shouldReportViolation
|
|
|
|
* Whether or not the use of an incorrect nonce should be reported.
|
|
|
|
* This function always returns "true" for report-only policies, but when
|
|
|
|
* the report-only policy is violated, shouldReportViolation is true as
|
|
|
|
* well.
|
|
|
|
* @return
|
|
|
|
* Whether or not this nonce is valid
|
|
|
|
*/
|
|
|
|
boolean getAllowsNonce(in AString aNonce,
|
|
|
|
in unsigned long aContentType,
|
|
|
|
out boolean shouldReportViolation);
|
|
|
|
|
2011-01-31 10:09:44 -08:00
|
|
|
/**
|
2013-09-12 09:25:32 -07:00
|
|
|
* For each violated policy (of type violationType), log policy violation on
|
|
|
|
* the Error Console and send a report to report-uris present in the violated
|
|
|
|
* policies.
|
2011-01-31 10:09:44 -08:00
|
|
|
*
|
|
|
|
* @param violationType
|
|
|
|
* one of the VIOLATION_TYPE_* constants, e.g. inline-script or eval
|
|
|
|
* @param sourceFile
|
|
|
|
* name of the source file containing the violation (if available)
|
|
|
|
* @param contentSample
|
|
|
|
* sample of the violating content (to aid debugging)
|
|
|
|
* @param lineNum
|
|
|
|
* source line number of the violation (if available)
|
2013-11-08 09:20:43 -08:00
|
|
|
* @param aNonce
|
|
|
|
* (optional) If this is a nonce violation, include the nonce so we can
|
|
|
|
* recheck to determine which policies were violated and send the
|
|
|
|
* appropriate reports.
|
2011-01-31 10:09:44 -08:00
|
|
|
*/
|
|
|
|
void logViolationDetails(in unsigned short violationType,
|
|
|
|
in AString sourceFile,
|
|
|
|
in AString scriptSample,
|
2013-11-08 09:20:43 -08:00
|
|
|
in int32_t lineNum,
|
|
|
|
[optional] in AString nonce);
|
2011-01-31 10:09:44 -08:00
|
|
|
|
|
|
|
const unsigned short VIOLATION_TYPE_INLINE_SCRIPT = 1;
|
2013-11-08 09:20:43 -08:00
|
|
|
const unsigned short VIOLATION_TYPE_EVAL = 2;
|
|
|
|
const unsigned short VIOLATION_TYPE_INLINE_STYLE = 3;
|
|
|
|
const unsigned short VIOLATION_TYPE_NONCE_SCRIPT = 4;
|
|
|
|
const unsigned short VIOLATION_TYPE_NONCE_STYLE = 5;
|
2011-01-31 10:09:44 -08:00
|
|
|
|
2010-01-21 10:41:24 -08:00
|
|
|
/**
|
|
|
|
* Called after the CSP object is created to fill in the appropriate request
|
|
|
|
* and request header information needed in case a report needs to be sent.
|
|
|
|
*/
|
|
|
|
void scanRequestData(in nsIHttpChannel aChannel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies ancestry as permitted by the policy.
|
|
|
|
*
|
2013-09-12 09:25:32 -07:00
|
|
|
* NOTE: Calls to this may trigger violation reports when queried, so this
|
|
|
|
* value should not be cached.
|
2010-01-21 10:41:24 -08:00
|
|
|
*
|
|
|
|
* @param docShell
|
|
|
|
* containing the protected resource
|
|
|
|
* @return
|
2013-09-12 09:25:32 -07:00
|
|
|
* true if the frame's ancestors are all allowed by policy (except for
|
|
|
|
* report-only policies, which will send reports and then return true
|
|
|
|
* here when violated).
|
2010-01-21 10:41:24 -08:00
|
|
|
*/
|
|
|
|
boolean permitsAncestry(in nsIDocShell docShell);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delegate method called by the service when sub-elements of the protected
|
|
|
|
* document are being loaded. Given a bit of information about the request,
|
|
|
|
* decides whether or not the policy is satisfied.
|
|
|
|
*
|
|
|
|
* Calls to this may trigger violation reports when queried, so
|
|
|
|
* this value should not be cached.
|
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
short shouldLoad(in unsigned long aContentType,
|
|
|
|
in nsIURI aContentLocation,
|
|
|
|
in nsIURI aRequestOrigin,
|
|
|
|
in nsISupports aContext,
|
|
|
|
in ACString aMimeTypeGuess,
|
2010-01-21 10:41:24 -08:00
|
|
|
in nsISupports aExtra);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delegate method called by the service when sub-elements of the protected
|
|
|
|
* document are being processed. Given a bit of information about the request,
|
|
|
|
* decides whether or not the policy is satisfied.
|
|
|
|
*/
|
2013-09-12 09:25:32 -07:00
|
|
|
short shouldProcess(in unsigned long aContentType,
|
|
|
|
in nsIURI aContentLocation,
|
|
|
|
in nsIURI aRequestOrigin,
|
|
|
|
in nsISupports aContext,
|
2010-01-21 10:41:24 -08:00
|
|
|
in ACString aMimeType,
|
|
|
|
in nsISupports aExtra);
|
|
|
|
|
|
|
|
};
|