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

Commit c953af6

Browse files
josephperrottpetebacondarwin
authored andcommitted
refactor(httpProvider): remove usages of whitelist and blacklist
Changes xsrfWhitelistedOrigins to xsrfTrustedOrigins updating references to use this new symbol. For the purposes of backward compatibility, the previous symbol is aliased to the new symbol.
1 parent a206e26 commit c953af6

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

Diff for: docs/content/guide/migration.ngdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -2647,8 +2647,8 @@ $scope.findTemplate = function(templateName) {
26472647
};
26482648
```
26492649

2650-
To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the resource
2651-
whitelist in the `config()` function:
2650+
To migrate, either cache the result of `trustAsResourceUrl()`, or put the template url in the trusted resource
2651+
URL list in the `config()` function:
26522652

26532653
After:
26542654

Diff for: src/ng/http.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ function $HttpProvider() {
388388

389389
/**
390390
* @ngdoc property
391-
* @name $httpProvider#xsrfWhitelistedOrigins
391+
* @name $httpProvider#xsrfTrustedOrigins
392392
* @description
393393
*
394394
* Array containing URLs whose origins are trusted to receive the XSRF token. See the
@@ -402,7 +402,7 @@ function $HttpProvider() {
402402
* Examples: `http://example.com`, `https://api.example.com:9876`
403403
*
404404
* <div class="alert alert-warning">
405-
* It is not possible to whitelist specific URLs/paths. The `path`, `query` and `fragment` parts
405+
* It is not possible to trust specific URLs/paths. The `path`, `query` and `fragment` parts
406406
* of a URL will be ignored. For example, `https://foo.com/path/bar?query=baz#fragment` will be
407407
* treated as `https://foo.com`, meaning that **all** requests to URLs starting with
408408
* `https://foo.com/` will include the XSRF token.
@@ -413,9 +413,9 @@ function $HttpProvider() {
413413
* ```js
414414
* // App served from `https://example.com/`.
415415
* angular.
416-
* module('xsrfWhitelistedOriginsExample', []).
416+
* module('xsrfTrustedOriginsExample', []).
417417
* config(['$httpProvider', function($httpProvider) {
418-
* $httpProvider.xsrfWhitelistedOrigins.push('https://api.example.com');
418+
* $httpProvider.xsrfTrustedOrigins.push('https://api.example.com');
419419
* }]).
420420
* run(['$http', function($http) {
421421
* // The XSRF token will be sent.
@@ -426,7 +426,7 @@ function $HttpProvider() {
426426
* }]);
427427
* ```
428428
*/
429-
var xsrfWhitelistedOrigins = this.xsrfWhitelistedOrigins = [];
429+
var xsrfTrustedOrigins = this.xsrfWhitelistedOrigins = this.xsrfTrustedOrigins = [];
430430

431431
this.$get = ['$browser', '$httpBackend', '$$cookieReader', '$cacheFactory', '$rootScope', '$q', '$injector', '$sce',
432432
function($browser, $httpBackend, $$cookieReader, $cacheFactory, $rootScope, $q, $injector, $sce) {
@@ -454,7 +454,7 @@ function $HttpProvider() {
454454
/**
455455
* A function to check request URLs against a list of allowed origins.
456456
*/
457-
var urlIsAllowedOrigin = urlIsAllowedOriginFactory(xsrfWhitelistedOrigins);
457+
var urlIsAllowedOrigin = urlIsAllowedOriginFactory(xsrfTrustedOrigins);
458458

459459
/**
460460
* @ngdoc service
@@ -828,16 +828,16 @@ function $HttpProvider() {
828828
* The header will &mdash; by default &mdash; **not** be set for cross-domain requests. This
829829
* prevents unauthorized servers (e.g. malicious or compromised 3rd-party APIs) from gaining
830830
* access to your users' XSRF tokens and exposing them to Cross Site Request Forgery. If you
831-
* want to, you can whitelist additional origins to also receive the XSRF token, by adding them
832-
* to {@link ng.$httpProvider#xsrfWhitelistedOrigins xsrfWhitelistedOrigins}. This might be
831+
* want to, you can trust additional origins to also receive the XSRF token, by adding them
832+
* to {@link ng.$httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}. This might be
833833
* useful, for example, if your application, served from `example.com`, needs to access your API
834834
* at `api.example.com`.
835-
* See {@link ng.$httpProvider#xsrfWhitelistedOrigins $httpProvider.xsrfWhitelistedOrigins} for
835+
* See {@link ng.$httpProvider#xsrfTrustedOrigins $httpProvider.xsrfTrustedOrigins} for
836836
* more details.
837837
*
838838
* <div class="alert alert-danger">
839839
* **Warning**<br />
840-
* Only whitelist origins that you have control over and make sure you understand the
840+
* Only trusted origins that you have control over and make sure you understand the
841841
* implications of doing so.
842842
* </div>
843843
*
@@ -964,7 +964,7 @@ function $HttpProvider() {
964964
<file name="script.js">
965965
angular.module('httpExample', [])
966966
.config(['$sceDelegateProvider', function($sceDelegateProvider) {
967-
// We must whitelist the JSONP endpoint that we are using to show that we trust it
967+
// We must add the JSONP endpoint that we are using to the trusted list to show that we trust it
968968
$sceDelegateProvider.trustedResourceUrlList([
969969
'self',
970970
'https://angularjs.org/**'
@@ -1222,7 +1222,7 @@ function $HttpProvider() {
12221222
*
12231223
* Note that, since JSONP requests are sensitive because the response is given full access to the browser,
12241224
* the url must be declared, via {@link $sce} as a trusted resource URL.
1225-
* You can trust a URL by adding it to the whitelist via
1225+
* You can trust a URL by adding it to the trusted resource URL list via
12261226
* {@link $sceDelegateProvider#trustedResourceUrlList `$sceDelegateProvider.trustedResourceUrlList`} or
12271227
* by explicitly trusting the URL via {@link $sce#trustAsResourceUrl `$sce.trustAsResourceUrl(url)`}.
12281228
*

Diff for: test/ng/httpSpec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2213,9 +2213,9 @@ describe('$http', function() {
22132213
var $httpBackend;
22142214

22152215
beforeEach(module(function($httpProvider) {
2216-
$httpProvider.xsrfWhitelistedOrigins.push(
2217-
'https://whitelisted.example.com',
2218-
'https://whitelisted2.example.com:1337/ignored/path');
2216+
$httpProvider.xsrfTrustedOrigins.push(
2217+
'https://trusted.example.com',
2218+
'https://trusted2.example.com:1337/ignored/path');
22192219
}));
22202220

22212221
beforeEach(inject(function(_$http_, _$httpBackend_) {
@@ -2312,8 +2312,8 @@ describe('$http', function() {
23122312
}
23132313
var requestUrls = [
23142314
'https://api.example.com/path',
2315-
'http://whitelisted.example.com',
2316-
'https://whitelisted2.example.com:1338'
2315+
'http://trusted.example.com',
2316+
'https://trusted2.example.com:1338'
23172317
];
23182318

23192319
mockedCookies['XSRF-TOKEN'] = 'secret';
@@ -2326,15 +2326,15 @@ describe('$http', function() {
23262326
});
23272327

23282328

2329-
it('should set an XSRF header for cross-domain requests to whitelisted origins',
2329+
it('should set an XSRF header for cross-domain requests to trusted origins',
23302330
inject(function($browser) {
23312331
function checkHeaders(headers) {
23322332
return headers['X-XSRF-TOKEN'] === 'secret';
23332333
}
23342334
var currentUrl = 'https://example.com/path';
23352335
var requestUrls = [
2336-
'https://whitelisted.example.com/path',
2337-
'https://whitelisted2.example.com:1337/path'
2336+
'https://trusted.example.com/path',
2337+
'https://trusted2.example.com:1337/path'
23382338
];
23392339

23402340
$browser.url(currentUrl);

0 commit comments

Comments
 (0)