From a206e2675c351c3cdcde3402978126774c1c5df9 Mon Sep 17 00:00:00 2001
From: Joey Perrott
+ * @param {Array=} bannedResourceUrlList When provided, replaces the `bannedResourceUrlList` 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 {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items * allowed in this array.
- * The typical usage for the blacklist is to **block + * The typical usage for the `bannedResourceUrlList` is to **block * [open redirects](http://cwe.mitre.org/data/definitions/601.html)** 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.
+ * Finally, **the banned resource URL list overrides the trusted resource URL list** and has
+ * the final say.
*
- * @return {Array} The currently set blacklist array.
+ * @return {Array} The currently set `bannedResourceUrlList` array.
*
* @description
- * Sets/Gets the blacklist of trusted resource URLs.
+ * Sets/Gets the `bannedResourceUrlList` of trusted resource URLs.
*
- * The **default value** when no whitelist has been explicitly set is the empty array (i.e. there
- * is no blacklist.)
+ * The **default value** when no trusted resource URL list has been explicitly set is the empty
+ * array (i.e. there is no `bannedResourceUrlList`.)
*/
- this.resourceUrlBlacklist = function(value) {
+ this.bannedResourceUrlList = function(value) {
if (arguments.length) {
- resourceUrlBlacklist = adjustMatchers(value);
+ bannedResourceUrlList = adjustMatchers(value);
}
- return resourceUrlBlacklist;
+ return bannedResourceUrlList;
};
+ /**
+ * @ngdoc method
+ * @name $sceDelegateProvider#resourceUrlBlacklist
+ * @kind function
+ *
+ * @deprecated
+ * sinceVersion="1.8.1"
+ *
+ * This function is deprecated. Use {@link $sceDelegateProvider#bannedResourceUrlList
+ * bannedResourceUrlList} instead.
+ */
+ Object.defineProperty(this, 'resourceUrlBlacklist', {
+ get: function() {
+ return this.bannedResourceUrlList;
+ },
+ set: function(value) {
+ this.bannedResourceUrlList = value;
+ }
+ });
+
this.$get = ['$injector', '$$sanitizeUri', function($injector, $$sanitizeUri) {
var htmlSanitizer = function htmlSanitizer(html) {
@@ -270,17 +293,17 @@ function $SceDelegateProvider() {
function isResourceUrlAllowedByPolicy(url) {
var parsedUrl = urlResolve(url.toString());
var i, n, allowed = false;
- // Ensure that at least one item from the whitelist allows this url.
- for (i = 0, n = resourceUrlWhitelist.length; i < n; i++) {
- if (matchUrl(resourceUrlWhitelist[i], parsedUrl)) {
+ // Ensure that at least one item from the trusted resource URL list allows this url.
+ for (i = 0, n = trustedResourceUrlList.length; i < n; i++) {
+ if (matchUrl(trustedResourceUrlList[i], parsedUrl)) {
allowed = true;
break;
}
}
if (allowed) {
- // Ensure that no item from the blacklist blocked this url.
- for (i = 0, n = resourceUrlBlacklist.length; i < n; i++) {
- if (matchUrl(resourceUrlBlacklist[i], parsedUrl)) {
+ // Ensure that no item from the banned resource URL list has blocked this url.
+ for (i = 0, n = bannedResourceUrlList.length; i < n; i++) {
+ if (matchUrl(bannedResourceUrlList[i], parsedUrl)) {
allowed = false;
break;
}
@@ -401,9 +424,9 @@ function $SceDelegateProvider() {
* The contexts that can be sanitized are $sce.MEDIA_URL, $sce.URL and $sce.HTML. The first two are available
* by default, and the third one relies on the `$sanitize` service (which may be loaded through
* the `ngSanitize` module). Furthermore, for $sce.RESOURCE_URL context, a plain string may be
- * accepted if the resource url policy defined by {@link ng.$sceDelegateProvider#resourceUrlWhitelist
- * `$sceDelegateProvider.resourceUrlWhitelist`} and {@link ng.$sceDelegateProvider#resourceUrlBlacklist
- * `$sceDelegateProvider.resourceUrlBlacklist`} accepts that resource.
+ * accepted if the resource url policy defined by {@link ng.$sceDelegateProvider#trustedResourceUrlList
+ * `$sceDelegateProvider.trustedResourceUrlList`} and {@link ng.$sceDelegateProvider#bannedResourceUrlList
+ * `$sceDelegateProvider.bannedResourceUrlList`} accepts that resource.
*
* This function will throw if the safe type isn't appropriate for this context, or if the
* value given cannot be accepted in the context (which might be caused by sanitization not
@@ -497,9 +520,9 @@ function $SceDelegateProvider() {
*
* To systematically block XSS security bugs, AngularJS treats all values as untrusted by default in
* HTML or sensitive URL bindings. When binding untrusted values, AngularJS will automatically
- * run security checks on them (sanitizations, whitelists, depending on context), or throw when it
- * cannot guarantee the security of the result. That behavior depends strongly on contexts: HTML
- * can be sanitized, but template URLs cannot, for instance.
+ * run security checks on them (sanitizations, trusted URL resource, depending on context), or throw
+ * when it cannot guarantee the security of the result. That behavior depends strongly on contexts:
+ * HTML can be sanitized, but template URLs cannot, for instance.
*
* To illustrate this, consider the `ng-bind-html` directive. It renders its value directly as HTML:
* we call that the *context*. When given an untrusted input, AngularJS will attempt to sanitize it
@@ -578,8 +601,8 @@ function $SceDelegateProvider() {
* By default, AngularJS only loads templates from the same domain and protocol as the application
* document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
* $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or
- * protocols, you may either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist
- * them} or {@link ng.$sce#trustAsResourceUrl wrap it} into a trusted value.
+ * protocols, you may either add them to the {@link ng.$sceDelegateProvider#trustedResourceUrlList
+ * trustedResourceUrlList} or {@link ng.$sce#trustAsResourceUrl wrap them} into trusted values.
*
* *Please note*:
* The browser's
@@ -607,8 +630,8 @@ function $SceDelegateProvider() {
* templates in `ng-include` from your application's domain without having to even know about SCE.
* It blocks loading templates from other domains or loading templates over http from an https
* served document. You can change these by setting your own custom {@link
- * ng.$sceDelegateProvider#resourceUrlWhitelist whitelists} and {@link
- * ng.$sceDelegateProvider#resourceUrlBlacklist blacklists} for matching such URLs.
+ * ng.$sceDelegateProvider#trustedResourceUrlList trusted resource URL list} and {@link
+ * ng.$sceDelegateProvider#bannedResourceUrlList banned resource URL list} for matching such URLs.
*
* This significantly reduces the overhead. It is far easier to pay the small overhead and have an
* application that's secure and can be audited to verify that with much more ease than bolting
@@ -623,7 +646,7 @@ function $SceDelegateProvider() {
* | `$sce.CSS` | For CSS that's safe to source into the application. Currently unused. Feel free to use it in your own directives. |
* | `$sce.MEDIA_URL` | For URLs that are safe to render as media. Is automatically converted from string by sanitizing when needed. |
* | `$sce.URL` | For URLs that are safe to follow as links. Is automatically converted from string by sanitizing when needed. Note that `$sce.URL` makes a stronger statement about the URL than `$sce.MEDIA_URL` does and therefore contexts requiring values trusted for `$sce.URL` can be used anywhere that values trusted for `$sce.MEDIA_URL` are required.|
- * | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contents are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.)
Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` or `$sce.MEDIA_URL` do and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` or `$sce.MEDIA_URL` are required.
The {@link $sceDelegateProvider#resourceUrlWhitelist $sceDelegateProvider#resourceUrlWhitelist()} and {@link $sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider#resourceUrlBlacklist()} can be used to restrict trusted origins for `RESOURCE_URL` |
+ * | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contents are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.)
Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` or `$sce.MEDIA_URL` do and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` or `$sce.MEDIA_URL` are required.
The {@link $sceDelegateProvider#trustedResourceUrlList $sceDelegateProvider#trustedResourceUrlList()} and {@link $sceDelegateProvider#bannedResourceUrlList $sceDelegateProvider#bannedResourceUrlList()} can be used to restrict trusted origins for `RESOURCE_URL` |
* | `$sce.JS` | For JavaScript that is safe to execute in your application's context. Currently unused. Feel free to use it in your own directives. |
*
*
@@ -641,7 +664,7 @@ function $SceDelegateProvider() {
* There are no CSS or JS context bindings in AngularJS currently, so their corresponding `$sce.trustAs`
* functions aren't useful yet. This might evolve.
*
- * ### Format of items in {@link ng.$sceDelegateProvider#resourceUrlWhitelist resourceUrlWhitelist}/{@link ng.$sceDelegateProvider#resourceUrlBlacklist Blacklist}
+ * ### Format of items in {@link ng.$sceDelegateProvider#trustedResourceUrlList trustedResourceUrlList}/{@link ng.$sceDelegateProvider#bannedResourceUrlList bannedResourceUrlList}
*
* Each element in these arrays must be one of the following:
*
@@ -655,7 +678,7 @@ function $SceDelegateProvider() {
* match themselves.
* - `*`: matches zero or more occurrences of any character other than one of the following 6
* characters: '`:`', '`/`', '`.`', '`?`', '`&`' and '`;`'. It's a useful wildcard for use
- * in a whitelist.
+ * for matching resource URL lists.
* - `**`: matches zero or more occurrences of *any* character. As such, it's not
* appropriate for use in a scheme, domain, etc. as it would match too much. (e.g.
* http://**.example.com/ would match http://evil.com/?ignore=.example.com/ and that might
diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js
index 065d93ac439..d0c994670b4 100644
--- a/test/ng/httpSpec.js
+++ b/test/ng/httpSpec.js
@@ -288,8 +288,8 @@ describe('$http', function() {
var $httpBackend, $http, $rootScope, $sce;
beforeEach(module(function($sceDelegateProvider) {
- // Setup a special whitelisted url that we can use in testing JSONP requests
- $sceDelegateProvider.resourceUrlWhitelist(['http://special.whitelisted.resource.com/**']);
+ // Setup a special trusted url that we can use in testing JSONP requests
+ $sceDelegateProvider.trustedResourceUrlList(['http://special.trusted.resource.com/**']);
}));
beforeEach(inject(['$httpBackend', '$http', '$rootScope', '$sce', function($hb, $h, $rs, $sc) {
diff --git a/test/ng/sceSpecs.js b/test/ng/sceSpecs.js
index fb169925c9f..a852b17ceda 100644
--- a/test/ng/sceSpecs.js
+++ b/test/ng/sceSpecs.js
@@ -309,11 +309,11 @@ describe('SCE', function() {
function runTest(cfg, testFn) {
return function() {
module(function($sceDelegateProvider) {
- if (isDefined(cfg.whiteList)) {
- $sceDelegateProvider.resourceUrlWhitelist(cfg.whiteList);
+ if (isDefined(cfg.trustedUrls)) {
+ $sceDelegateProvider.trustedResourceUrlList(cfg.trustedUrls);
}
- if (isDefined(cfg.blackList)) {
- $sceDelegateProvider.resourceUrlBlacklist(cfg.blackList);
+ if (isDefined(cfg.bannedUrls)) {
+ $sceDelegateProvider.bannedResourceUrlList(cfg.bannedUrls);
}
});
inject(testFn);
@@ -324,10 +324,10 @@ describe('SCE', function() {
expect($sce.getTrustedResourceUrl('foo/bar')).toEqual('foo/bar');
}));
- it('should reject everything when whitelist is empty', runTest(
+ it('should reject everything when trusted resource URL list is empty', runTest(
{
- whiteList: [],
- blackList: []
+ trustedUrls: [],
+ bannedUrls: []
}, function($sce) {
expect(function() { $sce.getTrustedResourceUrl('#'); }).toThrowMinErr(
'$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: #');
@@ -336,8 +336,8 @@ describe('SCE', function() {
it('should match against normalized urls', runTest(
{
- whiteList: [/^foo$/],
- blackList: []
+ trustedUrls: [/^foo$/],
+ bannedUrls: []
}, function($sce) {
expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrowMinErr(
'$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo');
@@ -346,7 +346,7 @@ describe('SCE', function() {
it('should not accept unknown matcher type', function() {
expect(function() {
- runTest({whiteList: [{}]}, null)();
+ runTest({trustedUrls: [{}]}, null)();
}).toThrowMinErr('$injector', 'modulerr', new RegExp(
/Failed to instantiate module function ?\(\$sceDelegateProvider\) due to:\n/.source +
/[^[]*\[\$sce:imatcher] Matchers may only be "self", string patterns or RegExp objects/.source));
@@ -370,8 +370,8 @@ describe('SCE', function() {
describe('regex matcher', function() {
it('should support custom regex', runTest(
{
- whiteList: [/^http:\/\/example\.com\/.*/],
- blackList: []
+ trustedUrls: [/^http:\/\/example\.com\/.*/],
+ bannedUrls: []
}, function($sce) {
expect($sce.getTrustedResourceUrl('http://example.com/foo')).toEqual('http://example.com/foo');
// must match entire regex
@@ -385,8 +385,8 @@ describe('SCE', function() {
it('should match entire regex', runTest(
{
- whiteList: [/https?:\/\/example\.com\/foo/],
- blackList: []
+ trustedUrls: [/https?:\/\/example\.com\/foo/],
+ bannedUrls: []
}, function($sce) {
expect($sce.getTrustedResourceUrl('http://example.com/foo')).toEqual('http://example.com/foo');
expect($sce.getTrustedResourceUrl('https://example.com/foo')).toEqual('https://example.com/foo');
@@ -405,8 +405,8 @@ describe('SCE', function() {
describe('string matchers', function() {
it('should support strings as matchers', runTest(
{
- whiteList: ['http://example.com/foo'],
- blackList: []
+ trustedUrls: ['http://example.com/foo'],
+ bannedUrls: []
}, function($sce) {
expect($sce.getTrustedResourceUrl('http://example.com/foo')).toEqual('http://example.com/foo');
// "." is not a special character like in a regex.
@@ -423,8 +423,8 @@ describe('SCE', function() {
it('should support the * wildcard', runTest(
{
- whiteList: ['http://example.com/foo*'],
- blackList: []
+ trustedUrls: ['http://example.com/foo*'],
+ bannedUrls: []
}, function($sce) {
expect($sce.getTrustedResourceUrl('http://example.com/foo')).toEqual('http://example.com/foo');
// The * wildcard should match extra characters.
@@ -452,8 +452,8 @@ describe('SCE', function() {
it('should support the ** wildcard', runTest(
{
- whiteList: ['http://example.com/foo**'],
- blackList: []
+ trustedUrls: ['http://example.com/foo**'],
+ bannedUrls: []
}, function($sce) {
expect($sce.getTrustedResourceUrl('http://example.com/foo')).toEqual('http://example.com/foo');
// The ** wildcard should match extra characters.
@@ -465,7 +465,7 @@ describe('SCE', function() {
it('should not accept *** in the string', function() {
expect(function() {
- runTest({whiteList: ['http://***']}, null)();
+ runTest({trustedUrls: ['http://***']}, null)();
}).toThrowMinErr('$injector', 'modulerr', new RegExp(
/Failed to instantiate module function ?\(\$sceDelegateProvider\) due to:\n/.source +
/[^[]*\[\$sce:iwcard] Illegal sequence \*\*\* in string matcher\. {2}String: http:\/\/\*\*\*/.source));
@@ -473,19 +473,19 @@ describe('SCE', function() {
});
describe('"self" matcher', function() {
- it('should support the special string "self" in whitelist', runTest(
+ it('should support the special string "self" in trusted resource URL list', runTest(
{
- whiteList: ['self'],
- blackList: []
+ trustedUrls: ['self'],
+ bannedUrls: []
}, function($sce) {
expect($sce.getTrustedResourceUrl('foo')).toEqual('foo');
}
));
- it('should support the special string "self" in blacklist', runTest(
+ it('should support the special string "self" in baneed resource URL list', runTest(
{
- whiteList: [/.*/],
- blackList: ['self']
+ trustedUrls: [/.*/],
+ bannedUrls: ['self']
}, function($sce) {
expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrowMinErr(
'$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo');
@@ -494,7 +494,7 @@ describe('SCE', function() {
describe('when the document base URL has changed', function() {
var baseElem;
- var cfg = {whitelist: ['self'], blacklist: []};
+ var cfg = {trustedUrls: ['self'], bannedUrls: []};
beforeEach(function() {
baseElem = window.document.createElement('BASE');
@@ -526,10 +526,10 @@ describe('SCE', function() {
});
});
- it('should have blacklist override the whitelist', runTest(
+ it('should have the banned resource URL list override the trusted resource URL list', runTest(
{
- whiteList: ['self'],
- blackList: ['self']
+ trustedUrls: ['self'],
+ bannedUrls: ['self']
}, function($sce) {
expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrowMinErr(
'$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo');
@@ -538,8 +538,8 @@ describe('SCE', function() {
it('should support multiple items in both lists', runTest(
{
- whiteList: [/^http:\/\/example.com\/1$/, /^http:\/\/example.com\/2$/, /^http:\/\/example.com\/3$/, 'self'],
- blackList: [/^http:\/\/example.com\/3$/, /.*\/open_redirect/]
+ trustedUrls: [/^http:\/\/example.com\/1$/, /^http:\/\/example.com\/2$/, /^http:\/\/example.com\/3$/, 'self'],
+ bannedUrls: [/^http:\/\/example.com\/3$/, /.*\/open_redirect/]
}, function($sce) {
expect($sce.getTrustedResourceUrl('same_domain')).toEqual('same_domain');
expect($sce.getTrustedResourceUrl('http://example.com/1')).toEqual('http://example.com/1');
@@ -553,12 +553,12 @@ describe('SCE', function() {
});
describe('URL-context sanitization', function() {
- it('should sanitize values that are not whitelisted', inject(function($sce) {
+ it('should sanitize values that are not found in the trusted resource URL list', inject(function($sce) {
expect($sce.getTrustedMediaUrl('javascript:foo')).toEqual('unsafe:javascript:foo');
expect($sce.getTrustedUrl('javascript:foo')).toEqual('unsafe:javascript:foo');
}));
- it('should not sanitize values that are whitelisted', inject(function($sce) {
+ it('should not sanitize values that are found in the trusted resource URL list', inject(function($sce) {
expect($sce.getTrustedMediaUrl('http://example.com')).toEqual('http://example.com');
expect($sce.getTrustedUrl('http://example.com')).toEqual('http://example.com');
}));
@@ -620,4 +620,3 @@ describe('SCE', function() {
});
});
});
-
diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js
index cdf755f42e1..fa31d412465 100644
--- a/test/ngRoute/routeSpec.js
+++ b/test/ngRoute/routeSpec.js
@@ -803,7 +803,7 @@ describe('$route', function() {
it('should load cross domain templates that are trusted', function() {
module(function($routeProvider, $sceDelegateProvider) {
$routeProvider.when('/foo', { templateUrl: 'http://example.com/foo.html' });
- $sceDelegateProvider.resourceUrlWhitelist([/^http:\/\/example\.com\/foo\.html$/]);
+ $sceDelegateProvider.trustedResourceUrlList([/^http:\/\/example\.com\/foo\.html$/]);
});
inject(function($route, $location, $rootScope) {