Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3dd42ce

Browse files
josephperrottpetebacondarwin
authored andcommitted
refactor(misc): remove usages of whitelist and blacklist
Remove miscellaneous usages and references to usages of whitelist and blacklist throughout the repository.
1 parent 7673810 commit 3dd42ce

16 files changed

+169
-106
lines changed

.eslintrc-todo.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// Stylistic issues
1616
"block-spacing": ["error", "always"],
1717
"comma-spacing": "error",
18-
"id-blacklist": ["error", "event"],
18+
"id-denylist": ["error", "event"],
1919
"indent": ["error", 2],
2020
"key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "minimum" }],
2121
"object-curly-spacing": ["error", "never"],

docs/config/processors/versions-data.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ module.exports = function generateVersionDocProcessor(gitData) {
1313
return {
1414
$runAfter: ['generatePagesDataProcessor'],
1515
$runBefore: ['rendering-docs'],
16-
// the blacklist is to remove rogue builds that are in the npm repository but not on code.angularjs.org
17-
blacklist: ['1.3.4-build.3588'],
16+
// Remove rogue builds that are in the npm repository but not on code.angularjs.org
17+
ignoredBuilds: ['1.3.4-build.3588'],
1818
$process: function(docs) {
1919

20-
var blacklist = this.blacklist;
20+
var ignoredBuilds = this.ignoredBuilds;
2121
var currentVersion = require('../../../build/version.json');
2222
var output = exec('yarn info angular versions --json', { silent: true }).stdout.split('\n')[0];
2323
var allVersions = processAllVersionsResponse(JSON.parse(output).data);
@@ -57,7 +57,7 @@ module.exports = function generateVersionDocProcessor(gitData) {
5757

5858
versions = versions
5959
.filter(function(versionStr) {
60-
return blacklist.indexOf(versionStr) === -1;
60+
return ignoredBuilds.indexOf(versionStr) === -1;
6161
})
6262
.map(function(versionStr) {
6363
return semver.parse(versionStr);

docs/content/guide/accessibility.ngdoc

+3-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ The default CSS for `ngHide`, the inverse method to `ngShow`, makes ngAria redun
327327

328328
<h2><span id="ngclick">ngClick</span> and <span id="ngdblclick">ngDblclick</span></h2>
329329
If `ng-click` or `ng-dblclick` is encountered, ngAria will add `tabindex="0"` to any element not in
330-
a node blacklist:
330+
the list of built in aria nodes:
331331

332332
* Button
333333
* Anchor
@@ -337,7 +337,8 @@ a node blacklist:
337337
* Details/Summary
338338

339339
To fix widespread accessibility problems with `ng-click` on `div` elements, ngAria will
340-
dynamically bind a keypress event by default as long as the element isn't in the node blacklist.
340+
dynamically bind a keypress event by default as long as the element isn't in a node from the list of
341+
built in aria nodes.
341342
You can turn this functionality on or off with the `bindKeypress` configuration option.
342343

343344
ngAria will also add the `button` role to communicate to users of assistive technologies. This can

docs/content/guide/migration.ngdoc

+16-14
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,16 @@ statement.
276276
**Due to [6ccbfa](https://github.com/angular/angular.js/commit/6ccbfa65d60a3dc396d0cf6da21b993ad74653fd)**,
277277
the `xlink:href` security context for SVG's `a` and `image` elements has been lowered.
278278

279-
In the unlikely case that an app relied on `RESOURCE_URL` whitelisting for the
279+
In the unlikely case that an app relied on `RESOURCE_URL` trusted list for the
280280
purpose of binding to the `xlink:href` property of SVG's `<a>` or `<image>`
281281
elements and if the values do not pass the regular URL sanitization, they will
282282
break.
283283

284284
To fix this you need to ensure that the values used for binding to the affected
285-
`xlink:href` contexts are considered safe URLs, e.g. by whitelisting them in
286-
`$compileProvider`'s `aHrefSanitizationTrustedUri` (for `<a>` elements) or
287-
`imgSrcSanitizationTrustedUri` (for `<image>` elements).
285+
`xlink:href` contexts are considered safe URLs, e.g. by trusting them in
286+
`$compileProvider`'s `aHrefSanitizationWhitelist` (called `aHrefSanitizationTrustedUrlList` form
287+
1.8.1 onwards) (for `<a>` elements) or `imgSrcSanitizationWhitelist` (called
288+
`imgSrcSanitizationTrustedUrlList` from 1.8.1 onwards) (for `<image>` elements).
288289

289290
<hr />
290291

@@ -1309,7 +1310,7 @@ running at `https://docs.angularjs.org` then the following will fail:
13091310

13101311
By default, only URLs with the same domain and protocol as the application document are considered
13111312
safe in the `RESOURCE_URL` context. To use URLs from other domains and/or protocols, you may either
1312-
whitelist them or wrap them into a trusted value by calling `$sce.trustAsResourceUrl(url)`.
1313+
add them to the trusted source URL list or wrap them into a trusted value by calling `$sce.trustAsResourceUrl(url)`.
13131314

13141315
<hr />
13151316
<minor />
@@ -1387,12 +1388,12 @@ $http.json('other/trusted/url', {jsonpCallbackParam: 'cb'});
13871388
all JSONP requests now require the URL to be trusted as a resource URL. There are two approaches to
13881389
trust a URL:
13891390

1390-
1. **Setting trusted resource URLs with the `$sceDelegateProvider.trustedResourceUrlList()` method.**
1391+
1. **Setting trusted resource URLs with the `$sceDelegateProvider.resourceUrlWhitelist()` (called `trustedResourceUrlList()` from 1.8.1 onwards) method.**
13911392
You configure this list in a module configuration block:
13921393

13931394
```js
13941395
appModule.config(['$sceDelegateProvider', function($sceDelegateProvider) {
1395-
$sceDelegateProvider.trustedResourceUrlList([
1396+
$sceDelegateProvider.resourceUrlWhitelist([
13961397
// Allow same origin resource loads.
13971398
'self',
13981399
// Allow JSONP calls that match this pattern
@@ -2207,7 +2208,7 @@ service does not have access to the resource in order to sanitize it.
22072208
Similarly, due to [234053fc](https://github.com/angular/angular.js/commit/234053fc9ad90e0d05be7e8359c6af66be94c094),
22082209
the `$sanitize` service will now also remove instances of the `usemap` attribute from any elements
22092210
passed to it. This attribute is used to reference another element by `name` or `id`. Since the
2210-
`name` and `id` attributes are already blacklisted, a sanitized `usemap` attribute could only
2211+
`name` and `id` attributes are already banned, a sanitized `usemap` attribute could only
22112212
reference unsanitized content, which is a security risk.
22122213

22132214
Due to [98c2db7f](https://github.com/angular/angular.js/commit/98c2db7f9c2d078a408576e722407d518c7ee10a),
@@ -2662,11 +2663,12 @@ $scope.findTemplate = function(templateName) {
26622663
return templateCache[templateName];
26632664
};
26642665

2665-
// Alternatively, use `$sceDelegateProvider.trustedResourceUrlList()`, which means you don't
2666+
// Alternatively, use `$sceDelegateProvider..resourceUrlWhitelist()` (called
2667+
// `trustedResourceUrlList()` from 1.8.1 onwards), which means you don't
26662668
// have to use `$sce.trustAsResourceUrl()` at all:
26672669

26682670
angular.module('myApp', []).config(function($sceDelegateProvider) {
2669-
$sceDelegateProvider.trustedResourceUrlList(['self', 'https://example.com/templates/**'])
2671+
$sceDelegateProvider.resourceUrlWhitelist(['self', 'https://example.com/templates/**'])
26702672
});
26712673
```
26722674

@@ -3353,7 +3355,7 @@ below should still apply, but you may want to consult the
33533355
<li>{@link guide/migration#directive-priority Directive priority}</li>
33543356
<li>{@link guide/migration#ngscenario ngScenario}</li>
33553357
<li>{@link guide/migration#nginclude-and-ngview-replace-its-entire-element-on-update ngInclude and ngView replace its entire element on update}</li>
3356-
<li>{@link guide/migration#urls-are-now-sanitized-against-a-whitelist URLs are now sanitized against a whitelist}</li>
3358+
<li>{@link guide/migration#urls-are-now-sanitized-against-a-trusted-uri-matcher URLs are now sanitized against a trusted URI matcher}</li>
33573359
<li>{@link guide/migration#isolate-scope-only-exposed-to-directives-with-scope-property Isolate scope only exposed to directives with <code>scope</code> property}</li>
33583360
<li>{@link guide/migration#change-to-interpolation-priority Change to interpolation priority}</li>
33593361
<li>{@link guide/migration#underscore-prefixed-suffixed-properties-are-non-bindable Underscore-prefixed/suffixed properties are non-bindable}</li>
@@ -3843,10 +3845,10 @@ See [7d69d52a](https://github.com/angular/angular.js/commit/7d69d52acff8578e0f7d
38433845
[aa2133ad](https://github.com/angular/angular.js/commit/aa2133ad818d2e5c27cbd3933061797096356c8a).
38443846

38453847

3846-
### URLs are now sanitized against a whitelist
3848+
### URLs are now sanitized against a trusted URI matcher
38473849

3848-
A whitelist configured via `$compileProvider` can be used to configure what URLs are considered safe.
3849-
By default all common protocol prefixes are whitelisted including `data:` URIs with mime types `image/*`.
3850+
A trusted URI matcher configured via `$compileProvider` can be used to configure what URLs are considered safe.
3851+
By default all common protocol prefixes are trusted including `data:` URIs with mime types `image/*`.
38503852
This change shouldn't impact apps that don't contain malicious image links.
38513853

38523854
See [1adf29af](https://github.com/angular/angular.js/commit/1adf29af13890d61286840177607edd552a9df97),

src/ng/compile.js

+52-12
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16981698

16991699
/**
17001700
* @ngdoc method
1701-
* @name $compileProvider#aHrefSanitizationTrustedUri
1701+
* @name $compileProvider#aHrefSanitizationTrustedUrlList
17021702
* @kind function
17031703
*
17041704
* @description
@@ -1708,28 +1708,48 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
17081708
* The sanitization is a security measure aimed at preventing XSS attacks via html links.
17091709
*
17101710
* Any url about to be assigned to a[href] via data-binding is first normalized and turned into
1711-
* an absolute url. Afterwards, the url is matched against the `aHrefSanitizationTrustedUri`
1711+
* an absolute url. Afterwards, the url is matched against the `aHrefSanitizationTrustedUrlList`
17121712
* regular expression. If a match is found, the original url is written into the dom. Otherwise,
17131713
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
17141714
*
17151715
* @param {RegExp=} regexp New regexp to trust urls with.
17161716
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
17171717
* chaining otherwise.
17181718
*/
1719-
this.aHrefSanitizationTrustedUri = function(regexp) {
1719+
this.aHrefSanitizationTrustedUrlList = function(regexp) {
17201720
if (isDefined(regexp)) {
1721-
$$sanitizeUriProvider.aHrefSanitizationTrustedUri(regexp);
1721+
$$sanitizeUriProvider.aHrefSanitizationTrustedUrlList(regexp);
17221722
return this;
17231723
} else {
1724-
return $$sanitizeUriProvider.aHrefSanitizationTrustedUri();
1724+
return $$sanitizeUriProvider.aHrefSanitizationTrustedUrlList();
17251725
}
17261726
};
1727-
this.aHrefSanitizationWhitelist = this.aHrefSanitizationTrustedUri;
17281727

17291728

17301729
/**
17311730
* @ngdoc method
1732-
* @name $compileProvider#imgSrcSanitizationTrustedUri
1731+
* @name $compileProvider#aHrefSanitizationWhitelist
1732+
* @kind function
1733+
*
1734+
* @deprecated
1735+
* sinceVersion="1.8.1"
1736+
*
1737+
* This function is deprecated. Use {@link $compileProvider#aHrefSanitizationTrustedUrlList
1738+
* aHrefSanitizationTrustedUrlList} instead.
1739+
*/
1740+
Object.defineProperty(this, 'aHrefSanitizationWhitelist', {
1741+
get: function() {
1742+
return this.aHrefSanitizationTrustedUrlList;
1743+
},
1744+
set: function(regexp) {
1745+
this.aHrefSanitizationTrustedUrlList = regexp;
1746+
}
1747+
});
1748+
1749+
1750+
/**
1751+
* @ngdoc method
1752+
* @name $compileProvider#imgSrcSanitizationTrustedUrlList
17331753
* @kind function
17341754
*
17351755
* @description
@@ -1739,23 +1759,43 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
17391759
* The sanitization is a security measure aimed at prevent XSS attacks via html links.
17401760
*
17411761
* Any url about to be assigned to img[src] via data-binding is first normalized and turned into
1742-
* an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationTrustedUri`
1762+
* an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationTrustedUrlList`
17431763
* regular expression. If a match is found, the original url is written into the dom. Otherwise,
17441764
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
17451765
*
17461766
* @param {RegExp=} regexp New regexp to trust urls with.
17471767
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
17481768
* chaining otherwise.
17491769
*/
1750-
this.imgSrcSanitizationTrustedUri = function(regexp) {
1770+
this.imgSrcSanitizationTrustedUrlList = function(regexp) {
17511771
if (isDefined(regexp)) {
1752-
$$sanitizeUriProvider.imgSrcSanitizationTrustedUri(regexp);
1772+
$$sanitizeUriProvider.imgSrcSanitizationTrustedUrlList(regexp);
17531773
return this;
17541774
} else {
1755-
return $$sanitizeUriProvider.imgSrcSanitizationTrustedUri();
1775+
return $$sanitizeUriProvider.imgSrcSanitizationTrustedUrlList();
17561776
}
17571777
};
1758-
this.imgSrcSanitizationWhitelist = this.imgSrcSanitizationTrustedUri;
1778+
1779+
1780+
/**
1781+
* @ngdoc method
1782+
* @name $compileProvider#imgSrcSanitizationWhitelist
1783+
* @kind function
1784+
*
1785+
* @deprecated
1786+
* sinceVersion="1.8.1"
1787+
*
1788+
* This function is deprecated. Use {@link $compileProvider#imgSrcSanitizationTrustedUrlList
1789+
* imgSrcSanitizationTrustedUrlList} instead.
1790+
*/
1791+
Object.defineProperty(this, 'imgSrcSanitizationWhitelist', {
1792+
get: function() {
1793+
return this.imgSrcSanitizationTrustedUrlList;
1794+
},
1795+
set: function(regexp) {
1796+
this.imgSrcSanitizationTrustedUrlList = regexp;
1797+
}
1798+
});
17591799

17601800
/**
17611801
* @ngdoc method

src/ng/http.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,27 @@ function $HttpProvider() {
426426
* }]);
427427
* ```
428428
*/
429-
var xsrfTrustedOrigins = this.xsrfWhitelistedOrigins = this.xsrfTrustedOrigins = [];
429+
var xsrfTrustedOrigins = this.xsrfTrustedOrigins = [];
430+
431+
/**
432+
* @ngdoc property
433+
* @name $httpProvider#xsrfWhitelistedOrigins
434+
* @description
435+
*
436+
* @deprecated
437+
* sinceVersion="1.8.1"
438+
*
439+
* This function is deprecated. Use {@link $httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}
440+
* instead.
441+
*/
442+
Object.defineProperty(this, 'xsrfWhitelistedOrigins', {
443+
get: function() {
444+
return this.xsrfTrustedOrigins;
445+
},
446+
set: function(origins) {
447+
this.xsrfTrustedOrigins = origins;
448+
}
449+
});
430450

431451
this.$get = ['$browser', '$httpBackend', '$$cookieReader', '$cacheFactory', '$rootScope', '$q', '$injector', '$sce',
432452
function($browser, $httpBackend, $$cookieReader, $cacheFactory, $rootScope, $q, $injector, $sce) {

src/ng/sanitizeUri.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
function $$SanitizeUriProvider() {
99

10-
var aHrefSanitizationTrustedUri = /^\s*(https?|s?ftp|mailto|tel|file):/,
11-
imgSrcSanitizationTrustedUri = /^\s*((https?|ftp|file|blob):|data:image\/)/;
10+
var aHrefSanitizationTrustedUrlList = /^\s*(https?|s?ftp|mailto|tel|file):/,
11+
imgSrcSanitizationTrustedUrlList = /^\s*((https?|ftp|file|blob):|data:image\/)/;
1212

1313
/**
1414
* @description
@@ -21,7 +21,7 @@ function $$SanitizeUriProvider() {
2121
* the $sce.URL security context. When interpolation occurs a call is made to `$sce.trustAsUrl(url)`
2222
* which in turn may call `$$sanitizeUri(url, isMedia)` to sanitize the potentially malicious URL.
2323
*
24-
* If the URL matches the `aHrefSanitizationTrustedUri` regular expression, it is returned unchanged.
24+
* If the URL matches the `aHrefSanitizationTrustedUrlList` regular expression, it is returned unchanged.
2525
*
2626
* If there is no match the URL is returned prefixed with `'unsafe:'` to ensure that when it is written
2727
* to the DOM it is inactive and potentially malicious code will not be executed.
@@ -30,12 +30,12 @@ function $$SanitizeUriProvider() {
3030
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
3131
* chaining otherwise.
3232
*/
33-
this.aHrefSanitizationTrustedUri = function(regexp) {
33+
this.aHrefSanitizationTrustedUrlList = function(regexp) {
3434
if (isDefined(regexp)) {
35-
aHrefSanitizationTrustedUri = regexp;
35+
aHrefSanitizationTrustedUrlList = regexp;
3636
return this;
3737
}
38-
return aHrefSanitizationTrustedUri;
38+
return aHrefSanitizationTrustedUrlList;
3939
};
4040

4141

@@ -61,18 +61,18 @@ function $$SanitizeUriProvider() {
6161
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
6262
* chaining otherwise.
6363
*/
64-
this.imgSrcSanitizationTrustedUri = function(regexp) {
64+
this.imgSrcSanitizationTrustedUrlList = function(regexp) {
6565
if (isDefined(regexp)) {
66-
imgSrcSanitizationTrustedUri = regexp;
66+
imgSrcSanitizationTrustedUrlList = regexp;
6767
return this;
6868
}
69-
return imgSrcSanitizationTrustedUri;
69+
return imgSrcSanitizationTrustedUrlList;
7070
};
7171

7272
this.$get = function() {
7373
return function sanitizeUri(uri, isMediaUrl) {
7474
// if (!uri) return uri;
75-
var regex = isMediaUrl ? imgSrcSanitizationTrustedUri : aHrefSanitizationTrustedUri;
75+
var regex = isMediaUrl ? imgSrcSanitizationTrustedUrlList : aHrefSanitizationTrustedUrlList;
7676
var normalizedVal = urlResolve(uri && uri.trim()).href;
7777
if (normalizedVal !== '' && !normalizedVal.match(regex)) {
7878
return 'unsafe:' + normalizedVal;

src/ng/templateRequest.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ function $TemplateRequestProvider() {
7373
handleRequestFn.totalPendingRequests++;
7474

7575
// We consider the template cache holds only trusted templates, so
76-
// there's no need to go through whitelisting again for keys that already
77-
// are included in there. This also makes AngularJS accept any script
78-
// directive, no matter its name. However, we still need to unwrap trusted
79-
// types.
76+
// there's no need to go through adding the template again to the trusted
77+
// resources for keys that already are included in there. This also makes
78+
// AngularJS accept any script directive, no matter its name. However, we
79+
// still need to unwrap trusted types.
8080
if (!isString(tpl) || isUndefined($templateCache.get(tpl))) {
8181
tpl = $sce.getTrustedResourceUrl(tpl);
8282
}

src/ng/urlUtils.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,20 @@ function urlIsSameOriginAsBaseUrl(requestUrl) {
125125
}
126126

127127
/**
128-
* Create a function that can check a URL's origin against a list of allowed/whitelisted origins.
128+
* Create a function that can check a URL's origin against a list of allowed/trusted origins.
129129
* The current location's origin is implicitly trusted.
130130
*
131-
* @param {string[]} whitelistedOriginUrls - A list of URLs (strings), whose origins are trusted.
131+
* @param {string[]} trustedOriginUrls - A list of URLs (strings), whose origins are trusted.
132132
*
133133
* @returns {Function} - A function that receives a URL (string or parsed URL object) and returns
134134
* whether it is of an allowed origin.
135135
*/
136-
function urlIsAllowedOriginFactory(whitelistedOriginUrls) {
137-
var parsedAllowedOriginUrls = [originUrl].concat(whitelistedOriginUrls.map(urlResolve));
136+
function urlIsAllowedOriginFactory(trustedOriginUrls) {
137+
var parsedAllowedOriginUrls = [originUrl].concat(trustedOriginUrls.map(urlResolve));
138138

139139
/**
140140
* Check whether the specified URL (string or parsed URL object) has an origin that is allowed
141-
* based on a list of whitelisted-origin URLs. The current location's origin is implicitly
141+
* based on a list of trusted-origin URLs. The current location's origin is implicitly
142142
* trusted.
143143
*
144144
* @param {string|Object} requestUrl - The URL to be checked (provided as a string that will be

0 commit comments

Comments
 (0)