tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsIContentPolicy.idl (19330B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ft=cpp tw=78 sw=2 et ts=8 : */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "nsISupports.idl"
      8 
      9 interface nsIURI;
     10 interface nsILoadInfo;
     11 
     12 /**
     13 * Interface for content policy mechanism.  Implementations of this
     14 * interface can be used to control loading of various types of out-of-line
     15 * content, or processing of certain types of in-line content.
     16 *
     17 * WARNING: do not block the caller from shouldLoad or shouldProcess (e.g.,
     18 * by launching a dialog to prompt the user for something).
     19 */
     20 
     21 [scriptable, uuid(caad4f1f-d047-46ac-ae9d-dc598e4fb91b)]
     22 interface nsIContentPolicy : nsISupports
     23 {
     24  /**
     25   * The type of nsIContentPolicy::TYPE_*
     26   */
     27  cenum nsContentPolicyType : 8 {
     28    /**
     29     * Indicates a unset or bogus policy type.
     30     */
     31    TYPE_INVALID = 0,
     32 
     33    /**
     34     * Gecko/Firefox developers: Avoid using TYPE_OTHER. Especially for
     35     * requests that are coming from webpages. Or requests in general which
     36     * you expect that security checks will be done on.
     37     * Always use a more specific type if one is available. And do not hesitate
     38     * to add more types as appropriate.
     39     * But if you are fairly sure that no one would care about your more specific
     40     * type, then it's ok to use TYPE_OTHER.
     41     *
     42     * Implementations of nsIContentPolicy should treat this the same way they
     43     * treat unknown types, because existing users of TYPE_OTHER may be converted
     44     * to use new content types.
     45     *
     46     * Note that the TYPE_INTERNAL_* constants are never passed to content
     47     * policy implementations.  They are mapped to other TYPE_* constants, and
     48     * are only intended for internal usage inside Gecko.
     49     */
     50    TYPE_OTHER = 1,
     51 
     52    /**
     53     * Indicates an executable script (such as JavaScript).
     54     */
     55    TYPE_SCRIPT = 2,
     56 
     57    /**
     58     * Indicates an image (e.g., IMG elements).
     59     */
     60    TYPE_IMAGE = 3,
     61 
     62    /**
     63     * Indicates a stylesheet (e.g., STYLE elements).
     64     */
     65    TYPE_STYLESHEET = 4,
     66 
     67    /**
     68     * Indicates a generic object (plugin-handled content typically falls under
     69     * this category).
     70     */
     71    TYPE_OBJECT = 5,
     72 
     73    /**
     74     * Indicates a document at the top-level (i.e., in a browser).
     75     */
     76    TYPE_DOCUMENT = 6,
     77 
     78    /**
     79     * Indicates a document contained within another document (e.g., IFRAMEs,
     80     * FRAMES, and OBJECTs).
     81     */
     82    TYPE_SUBDOCUMENT = 7,
     83 
     84    /*
     85     * XXX: nsContentPolicyType = 8 used to indicate a timed refresh request.
     86     */
     87 
     88    /*
     89     * XXX: nsContentPolicyType = 9 used to indicate an XBL binding request.
     90     */
     91 
     92    /**
     93     * Indicates a ping triggered by a click on <A PING="..."> element.
     94     */
     95    TYPE_PING = 10,
     96 
     97    /**
     98     * Indicates an XMLHttpRequest. Also used for document.load and for EventSource.
     99     */
    100    TYPE_XMLHTTPREQUEST = 11,
    101 
    102    /*
    103     * XXX: nsContentPolicyType = 12 used to indicate plugin/object sub-requests.
    104     */
    105 
    106    /**
    107     * Indicates a DTD loaded by an XML document.
    108     */
    109    TYPE_DTD = 13,
    110 
    111    /**
    112     * Indicates a font loaded via @font-face rule.
    113     */
    114    TYPE_FONT = 14,
    115 
    116    /**
    117     * Indicates a video or audio load.
    118     */
    119    TYPE_MEDIA = 15,
    120 
    121    /**
    122     * Indicates a WebSocket load.
    123     */
    124    TYPE_WEBSOCKET = 16,
    125 
    126    /**
    127     * Indicates a Content Security Policy report.
    128     */
    129    TYPE_CSP_REPORT = 17,
    130 
    131    /**
    132     * Indicates a style sheet transformation.
    133     */
    134    TYPE_XSLT = 18,
    135 
    136    /**
    137     * Indicates a beacon post.
    138     */
    139    TYPE_BEACON = 19,
    140 
    141    /**
    142     * Indicates a load initiated by the fetch() function from the Fetch
    143     * specification.
    144     */
    145    TYPE_FETCH = 20,
    146 
    147    /**
    148     * Indicates a <img srcset> or <picture> request.
    149     */
    150    TYPE_IMAGESET = 21,
    151 
    152    /**
    153     * Indicates a web manifest.
    154     */
    155    TYPE_WEB_MANIFEST = 22,
    156 
    157    /**
    158     * Indicates an internal constant for scripts loaded through script
    159     * elements.
    160     *
    161     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    162     * implementations.
    163     */
    164    TYPE_INTERNAL_SCRIPT = 23,
    165 
    166    /**
    167     * Indicates an internal constant for scripts loaded through a dedicated
    168     * worker.
    169     *
    170     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    171     * implementations.
    172     */
    173    TYPE_INTERNAL_WORKER = 24,
    174 
    175    /**
    176     * Indicates an internal constant for scripts loaded through a shared
    177     * worker.
    178     *
    179     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    180     * implementations.
    181     */
    182    TYPE_INTERNAL_SHARED_WORKER = 25,
    183 
    184    /**
    185     * Indicates an internal constant for content loaded from embed elements.
    186     *
    187     * This will be mapped to TYPE_OBJECT.
    188     */
    189    TYPE_INTERNAL_EMBED = 26,
    190 
    191    /**
    192     * Indicates an internal constant for content loaded from object elements.
    193     *
    194     * This will be mapped to TYPE_OBJECT.
    195     */
    196    TYPE_INTERNAL_OBJECT = 27,
    197 
    198    /**
    199     * Indicates an internal constant for content loaded from frame elements.
    200     *
    201     * This will be mapped to TYPE_SUBDOCUMENT.
    202     */
    203    TYPE_INTERNAL_FRAME = 28,
    204 
    205    /**
    206     * Indicates an internal constant for content loaded from iframe elements.
    207     *
    208     * This will be mapped to TYPE_SUBDOCUMENT.
    209     */
    210    TYPE_INTERNAL_IFRAME = 29,
    211 
    212    /**
    213     * Indicates an internal constant for content loaded from audio elements.
    214     *
    215     * This will be mapped to TYPE_MEDIA.
    216     */
    217    TYPE_INTERNAL_AUDIO = 30,
    218 
    219    /**
    220     * Indicates an internal constant for content loaded from video elements.
    221     *
    222     * This will be mapped to TYPE_MEDIA.
    223     */
    224    TYPE_INTERNAL_VIDEO = 31,
    225 
    226    /**
    227     * Indicates an internal constant for content loaded from track elements.
    228     *
    229     * This will be mapped to TYPE_MEDIA.
    230     */
    231    TYPE_INTERNAL_TRACK = 32,
    232 
    233    /**
    234     * Indicates an internal constant for an asynchronous XMLHttpRequest.
    235     *
    236     * This will be mapped to TYPE_XMLHTTPREQUEST.
    237     */
    238    TYPE_INTERNAL_XMLHTTPREQUEST_ASYNC = 33,
    239 
    240    /**
    241     * Indicates an internal constant for EventSource.
    242     *
    243     * This will be mapped to TYPE_XMLHTTPREQUEST.
    244     */
    245    TYPE_INTERNAL_EVENTSOURCE = 34,
    246 
    247    /**
    248     * Indicates an internal constant for scripts loaded through a service
    249     * worker.
    250     *
    251     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    252     * implementations.
    253     */
    254    TYPE_INTERNAL_SERVICE_WORKER = 35,
    255 
    256    /**
    257     * Indicates an internal constant for *preloaded* scripts
    258     * loaded through script elements.
    259     *
    260     * This will be mapped to TYPE_SCRIPT before being passed
    261     * to content policy implementations.
    262     */
    263    TYPE_INTERNAL_SCRIPT_PRELOAD = 36,
    264 
    265    /**
    266     * Indicates an internal constant for normal images.
    267     *
    268     * This will be mapped to TYPE_IMAGE before being passed
    269     * to content policy implementations.
    270     */
    271    TYPE_INTERNAL_IMAGE = 37,
    272 
    273    /**
    274     * Indicates an internal constant for *preloaded* images.
    275     *
    276     * This will be mapped to TYPE_IMAGE before being passed
    277     * to content policy implementations.
    278     */
    279    TYPE_INTERNAL_IMAGE_PRELOAD = 38,
    280 
    281    /**
    282     * Indicates an internal constant for normal stylesheets.
    283     *
    284     * This will be mapped to TYPE_STYLESHEET before being passed
    285     * to content policy implementations.
    286     */
    287    TYPE_INTERNAL_STYLESHEET = 39,
    288 
    289    /**
    290     * Indicates an internal constant for *preloaded* stylesheets.
    291     *
    292     * This will be mapped to TYPE_STYLESHEET before being passed
    293     * to content policy implementations.
    294     */
    295    TYPE_INTERNAL_STYLESHEET_PRELOAD = 40,
    296 
    297    /**
    298     * Indicates an internal constant for favicon.
    299     *
    300     * This will be mapped to TYPE_IMAGE before being passed
    301     * to content policy implementations.
    302     */
    303    TYPE_INTERNAL_IMAGE_FAVICON = 41,
    304 
    305    /**
    306     * Indicates an importScripts() inside a worker script.
    307     *
    308     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    309     * implementations.
    310     */
    311    TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS = 42,
    312 
    313    /**
    314     * Indicates an save-as link download from the front-end code.
    315     */
    316    TYPE_SAVEAS_DOWNLOAD = 43,
    317 
    318    /**
    319     * Indicates a speculative connection.
    320     */
    321    TYPE_SPECULATIVE = 44,
    322 
    323    /**
    324     * Indicates an internal constant for ES6 module scripts
    325     * loaded through script elements or an import statement (static import) or
    326     * an import expression (dynamic import).
    327     * It also indicates the load for dynamic import in workers.
    328     * For static import in module workers,
    329     * please check TYPE_INTERNAL_WORKER_STATIC_MODULE.
    330     *
    331     * This will be mapped to TYPE_SCRIPT before being passed
    332     * to content policy implementations.
    333     */
    334    TYPE_INTERNAL_MODULE = 45,
    335 
    336    /**
    337     * Indicates an internal constant for *preloaded* ES6 module scripts
    338     * loaded through script elements or an import statement.
    339     *
    340     * This will be mapped to TYPE_SCRIPT before being passed
    341     * to content policy implementations.
    342     */
    343    TYPE_INTERNAL_MODULE_PRELOAD = 46,
    344 
    345    /**
    346     * Indicates a DTD loaded by an XML document the URI of which could
    347     * not be mapped to a known local DTD.
    348     */
    349    TYPE_INTERNAL_DTD = 47,
    350 
    351    /**
    352     * Indicates a TYPE_INTERNAL_DTD which will not be blocked no matter
    353     * what principal is being loaded from.
    354     */
    355    TYPE_INTERNAL_FORCE_ALLOWED_DTD = 48,
    356 
    357    /**
    358     * Indicates an internal constant for scripts loaded through an
    359     * audioWorklet.
    360     *
    361     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    362     * implementations.
    363     */
    364    TYPE_INTERNAL_AUDIOWORKLET = 49,
    365 
    366    /**
    367     * Indicates an internal constant for scripts loaded through an
    368     * paintWorklet.
    369     *
    370     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    371     * implementations.
    372     */
    373    TYPE_INTERNAL_PAINTWORKLET = 50,
    374 
    375    /**
    376     * Same as TYPE_FONT but indicates this is a <link rel=preload as=font>
    377     * preload initiated load.
    378     */
    379    TYPE_INTERNAL_FONT_PRELOAD = 51,
    380 
    381    /**
    382     * Indicates the load of a (Firefox-internal) script through ChromeUtils
    383     *
    384     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    385     * implementations.
    386    */
    387    TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT = 52,
    388 
    389    /**
    390     * Indicates the load of a script through FrameMessageManager
    391     *
    392     * This will be mapped to TYPE_SCRIPT before being passed to content policy
    393     * implementations.
    394    */
    395    TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT = 53,
    396 
    397    /**
    398     * Indicates an internal constant for *preloaded* fetch
    399     * loaded through link elements.
    400     *
    401     * This will be mapped to TYPE_FETCH before being passed
    402     * to content policy implementations.
    403     */
    404    TYPE_INTERNAL_FETCH_PRELOAD = 54,
    405 
    406    /**
    407     * Indicates a font loaded via @font-face rule in an UA style sheet.
    408     * (CSP does not apply.)
    409     */
    410    TYPE_UA_FONT = 55,
    411 
    412    /**
    413     * Indicates the establishment of a TCP or TLS connection via an
    414     * http/https proxy that will be used for webrtc media. When no web proxy
    415     * is involved, webrtc uses lower level sockets that are not subject to
    416     * any sort of content policy.
    417     */
    418    TYPE_PROXIED_WEBRTC_MEDIA = 56,
    419 
    420    /**
    421     * Indicates the load of data via the Federated Credential Management API
    422     * with data destined for a browser context.
    423     */
    424     TYPE_WEB_IDENTITY = 57,
    425 
    426    /**
    427     * Indicates the load of a static module on workers.
    428     */
    429    TYPE_INTERNAL_WORKER_STATIC_MODULE = 58,
    430 
    431    /**
    432     * Indicates Webtransport request
    433     */
    434    TYPE_WEB_TRANSPORT = 59,
    435 
    436    /**
    437     * Indicates an internal constant for a synchronous XMLHttpRequest.
    438     *
    439     * This will be mapped to TYPE_XMLHTTPREQUEST.
    440     */
    441    TYPE_INTERNAL_XMLHTTPREQUEST_SYNC = 60,
    442 
    443    /**
    444     * This is a request triggered by Document::RequestExternalResource.
    445     * It is presumably something like an SVG <use> or CSS filter:.
    446     * For simplicity treat this like TYPE_OTHER outside CSP.
    447     */
    448    TYPE_INTERNAL_EXTERNAL_RESOURCE = 61,
    449 
    450    /**
    451     * Indicates a JSON module loaded through an import statement.
    452     */
    453    TYPE_JSON = 62,
    454 
    455    /**
    456     * Same as TYPE_JSON but indicates an internal constant for a preloaded
    457     * JSON module loaded through an import statement.
    458     *
    459     * This will be mapped to TYPE_JSON before being passed to content policy
    460     * implementations.
    461     */
    462    TYPE_INTERNAL_JSON_PRELOAD = 63,
    463 
    464    /**
    465     * Used to indicate the end of this list, not a content policy. If you want
    466     * to add a new content policy type, place it before this sentinel value
    467     * TYPE_END, have it use TYPE_END's current value, and increment TYPE_END by
    468     * one. (TYPE_END should always have the highest numerical value.)
    469     */
    470    TYPE_END = 64,
    471 
    472    /* When adding new content types, please update
    473     * NS_CP_ContentTypeName, nsCSPContext, CSP_ContentTypeToDirective,
    474     * DoContentSecurityChecks, all nsIContentPolicy implementations, the
    475     * static_assert in dom/cache/DBSchema.cpp, ChannelWrapper.webidl,
    476     * ChannelWrapper.cpp, PermissionManager.cpp,
    477     * IPCMessageUtilsSpecializations.h, and other things that are not
    478     * listed here that are related to nsIContentPolicy. */
    479  };
    480 
    481  //////////////////////////////////////////////////////////////////////
    482 
    483  /**
    484   * Returned from shouldLoad or shouldProcess if the load or process request
    485   * is rejected based on details of the request.
    486   */
    487  const short REJECT_REQUEST = -1;
    488 
    489  /**
    490   * Returned from shouldLoad or shouldProcess if the load/process is rejected
    491   * based solely on its type (of the above flags).
    492   *
    493   * NOTE that it is not meant to stop future requests for this type--only the
    494   * current request.
    495   */
    496  const short REJECT_TYPE = -2;
    497 
    498  /**
    499   * Returned from shouldLoad or shouldProcess if the load/process is rejected
    500   * based on the server it is hosted on or requested from (aContentLocation or
    501   * aRequestOrigin), e.g., if you block an IMAGE because it is served from
    502   * goatse.cx (even if you don't necessarily block other types from that
    503   * server/domain).
    504   *
    505   * NOTE that it is not meant to stop future requests for this server--only the
    506   * current request.
    507   */
    508  const short REJECT_SERVER = -3;
    509 
    510  /**
    511   * Returned from shouldLoad or shouldProcess if the load/process is rejected
    512   * based on some other criteria. Mozilla callers will handle this like
    513   * REJECT_REQUEST; third-party implementors may, for example, use this to
    514   * direct their own callers to consult the extra parameter for additional
    515   * details.
    516   */
    517  const short REJECT_OTHER = -4;
    518 
    519  /**
    520   * Returned from shouldLoad or shouldProcess if the load/process is forbiddden
    521   * based on enterprise policy.
    522   */
    523  const short REJECT_POLICY = -5;
    524 
    525  /**
    526   * Returned from shouldLoad or shouldProcess if the load or process request
    527   * is not rejected.
    528   */
    529  const short ACCEPT = 1;
    530 
    531  /**
    532   * Should the resource at this location be loaded?
    533   * ShouldLoad will be called before loading the resource at aContentLocation
    534   * to determine whether to start the load at all.
    535   *
    536   * @param aContentLocation  the location of the content being checked; must
    537   *                          not be null
    538   *
    539   * @param aLoadInfo         the loadinfo of the channel being evaluated.
    540   *
    541   * @return ACCEPT or REJECT_*
    542   *
    543   * @note shouldLoad can be called while the DOM and layout of the document
    544   * involved is in an inconsistent state.  This means that implementors of
    545   * this method MUST NOT do any of the following:
    546   * 1)  Modify the DOM in any way (e.g. setting attributes is a no-no).
    547   * 2)  Query any DOM properties that depend on layout (e.g. offset*
    548   *     properties).
    549   * 3)  Query any DOM properties that depend on style (e.g. computed style).
    550   * 4)  Query any DOM properties that depend on the current state of the DOM
    551   *     outside the "context" node (e.g. lengths of node lists).
    552   * 5)  [JavaScript implementations only] Access properties of any sort on any
    553   *     object without using XPCNativeWrapper (either explicitly or
    554   *     implicitly).  Due to various DOM0 things, this leads to item 4.
    555   * If you do any of these things in your shouldLoad implementation, expect
    556   * unpredictable behavior, possibly including crashes, content not showing
    557   * up, content showing up doubled, etc.  If you need to do any of the things
    558   * above, do them off timeout or event.
    559   */
    560  short shouldLoad(in nsIURI      aContentLocation,
    561                   in nsILoadInfo aLoadInfo);
    562 
    563  /**
    564   * Should the resource be processed?
    565   * ShouldProcess will be called once all the information passed to it has
    566   * been determined about the resource, typically after part of the resource
    567   * has been loaded.
    568   *
    569   * @param aContentLocation  OPTIONAL; the location of the resource being
    570   *                          requested: MAY be, e.g., a post-redirection URI
    571   *                          for the resource.
    572   *
    573   * @param aLoadInfo         the loadinfo of the channel being evaluated.
    574   *
    575   * @return ACCEPT or REJECT_*
    576   *
    577   * @note shouldProcess can be called while the DOM and layout of the document
    578   * involved is in an inconsistent state.  See the note on shouldLoad to see
    579   * what this means for implementors of this method.
    580   */
    581  short shouldProcess(in nsIURI      aContentLocation,
    582                      in nsILoadInfo aLoadInfo);
    583 };
    584 
    585 typedef nsIContentPolicy_nsContentPolicyType nsContentPolicyType;
    586 
    587 %{C++
    588 enum class ExtContentPolicyType : uint8_t {
    589  /**
    590   * The type of ExtContentPolicy::TYPE_*
    591   */
    592  TYPE_INVALID = nsIContentPolicy::TYPE_INVALID,
    593  TYPE_OTHER = nsIContentPolicy::TYPE_OTHER,
    594  TYPE_SCRIPT = nsIContentPolicy::TYPE_SCRIPT,
    595  TYPE_IMAGE = nsIContentPolicy::TYPE_IMAGE,
    596  TYPE_STYLESHEET = nsIContentPolicy::TYPE_STYLESHEET,
    597  TYPE_OBJECT = nsIContentPolicy::TYPE_OBJECT,
    598  TYPE_DOCUMENT = nsIContentPolicy::TYPE_DOCUMENT,
    599  TYPE_SUBDOCUMENT = nsIContentPolicy::TYPE_SUBDOCUMENT,
    600  TYPE_PING = nsIContentPolicy::TYPE_PING,
    601  TYPE_XMLHTTPREQUEST = nsIContentPolicy::TYPE_XMLHTTPREQUEST,
    602  TYPE_DTD = nsIContentPolicy::TYPE_DTD,
    603  TYPE_FONT = nsIContentPolicy::TYPE_FONT,
    604  TYPE_MEDIA = nsIContentPolicy::TYPE_MEDIA,
    605  TYPE_WEBSOCKET = nsIContentPolicy::TYPE_WEBSOCKET,
    606  TYPE_CSP_REPORT = nsIContentPolicy::TYPE_CSP_REPORT,
    607  TYPE_XSLT = nsIContentPolicy::TYPE_XSLT,
    608  TYPE_BEACON = nsIContentPolicy::TYPE_BEACON,
    609  TYPE_FETCH = nsIContentPolicy::TYPE_FETCH,
    610  TYPE_IMAGESET = nsIContentPolicy::TYPE_IMAGESET,
    611  TYPE_WEB_MANIFEST = nsIContentPolicy::TYPE_WEB_MANIFEST,
    612  TYPE_SAVEAS_DOWNLOAD = nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD,
    613  TYPE_SPECULATIVE = nsIContentPolicy::TYPE_SPECULATIVE,
    614  TYPE_UA_FONT = nsIContentPolicy::TYPE_UA_FONT,
    615  TYPE_PROXIED_WEBRTC_MEDIA = nsIContentPolicy::TYPE_PROXIED_WEBRTC_MEDIA,
    616  TYPE_WEB_IDENTITY = nsIContentPolicy::TYPE_WEB_IDENTITY,
    617  TYPE_WEB_TRANSPORT = nsIContentPolicy::TYPE_WEB_TRANSPORT,
    618  TYPE_JSON = nsIContentPolicy::TYPE_JSON,
    619 };
    620 
    621 typedef ExtContentPolicyType ExtContentPolicy;
    622 %}