View source Improve this doc

$sceDelegateProvider

service in module ng

Description

The $sceDelegateProvider provider allows developers to configure the $sceDelegate service. This allows one to get/set the whitelists and blacklists used to ensure that the URLs used for sourcing Angular templates are safe. Refer $sceDelegateProvider.resourceUrlWhitelist and $sceDelegateProvider.resourceUrlBlacklist

For the general details about this service in Angular, read the main page for Strict Contextual Escaping (SCE).

Example: Consider the following case.

Here is what a secure configuration for this scenario might look like:

  1. angular.module('myApp', []).config(function($sceDelegateProvider) {
  2. $sceDelegateProvider.resourceUrlWhitelist([
  3. // Allow same origin resource loads.
  4. 'self',
  5. // Allow loading from our assets domain. Notice the difference between * and **.
  6. 'http://srv*.assets.example.com/**']);
  7.  
  8. // The blacklist overrides the whitelist so the open redirect here is blocked.
  9. $sceDelegateProvider.resourceUrlBlacklist([
  10. 'http://myapp.example.com/clickThru**']);
  11. });

Methods

  • resourceUrlBlacklist(blacklist)

Sets/Gets the blacklist of trusted resource URLs.

Parameters

ParamTypeDetailsblacklist (optional) Array

When provided, replaces the resourceUrlBlacklist with the value provided. This must be an array or null. A snapshot of this array is used so further changes to the array are ignored.

Follow this link for a description of the items allowed in this array.

The typical usage for the blacklist is to block open redirects served by your domain as these would otherwise be trusted but actually return content from the redirected domain.

Finally, the blacklist overrides the whitelist and has the final say.

Returns

Array

the currently set blacklist array.

The default value when no whitelist has been explicitly set is the empty array (i.e. there is no blacklist.)

  • resourceUrlWhitelist(whitelist)

Sets/Gets the whitelist of trusted resource URLs.

Parameters

ParamTypeDetailswhitelist (optional) Array

When provided, replaces the resourceUrlWhitelist with the value provided. This must be an array or null. A snapshot of this array is used so further changes to the array are ignored.

Follow this link for a description of the items allowed in this array.

Note: an empty whitelist array will block all URLs!

Returns

Array

the currently set whitelist array.

The default value when no whitelist has been explicitly set is ['self'] allowing only same origin resource requests.