|
1 | 1 | /**
|
2 |
| - * @license AngularJS v1.7.9 |
3 |
| - * (c) 2010-2018 Google, Inc. http://angularjs.org |
| 2 | + * @license AngularJS v1.8.2 |
| 3 | + * (c) 2010-2020 Google LLC. http://angularjs.org |
4 | 4 | * License: MIT
|
5 | 5 | */
|
6 | 6 | (function(window, angular) {'use strict';
|
@@ -46,12 +46,12 @@ var htmlSanitizeWriter;
|
46 | 46 | * @description
|
47 | 47 | * Sanitizes an html string by stripping all potentially dangerous tokens.
|
48 | 48 | *
|
49 |
| - * The input is sanitized by parsing the HTML into tokens. All safe tokens (from a whitelist) are |
| 49 | + * The input is sanitized by parsing the HTML into tokens. All safe tokens (from a trusted URI list) are |
50 | 50 | * then serialized back to a properly escaped HTML string. This means that no unsafe input can make
|
51 | 51 | * it into the returned string.
|
52 | 52 | *
|
53 |
| - * The whitelist for URL sanitization of attribute values is configured using the functions |
54 |
| - * `aHrefSanitizationWhitelist` and `imgSrcSanitizationWhitelist` of {@link $compileProvider}. |
| 53 | + * The trusted URIs for URL sanitization of attribute values is configured using the functions |
| 54 | + * `aHrefSanitizationTrustedUrlList` and `imgSrcSanitizationTrustedUrlList` of {@link $compileProvider}. |
55 | 55 | *
|
56 | 56 | * The input may also contain SVG markup if this is enabled via {@link $sanitizeProvider}.
|
57 | 57 | *
|
@@ -282,8 +282,8 @@ function $SanitizeProvider() {
|
282 | 282 | * **Note**:
|
283 | 283 | * The new attributes will not be treated as URI attributes, which means their values will not be
|
284 | 284 | * sanitized as URIs using `$compileProvider`'s
|
285 |
| - * {@link ng.$compileProvider#aHrefSanitizationWhitelist aHrefSanitizationWhitelist} and |
286 |
| - * {@link ng.$compileProvider#imgSrcSanitizationWhitelist imgSrcSanitizationWhitelist}. |
| 285 | + * {@link ng.$compileProvider#aHrefSanitizationTrustedUrlList aHrefSanitizationTrustedUrlList} and |
| 286 | + * {@link ng.$compileProvider#imgSrcSanitizationTrustedUrlList imgSrcSanitizationTrustedUrlList}. |
287 | 287 | *
|
288 | 288 | * <div class="alert alert-info">
|
289 | 289 | * This method must be called during the {@link angular.Module#config config} phase. Once the
|
@@ -426,50 +426,28 @@ function $SanitizeProvider() {
|
426 | 426 | }
|
427 | 427 |
|
428 | 428 | /**
|
429 |
| - * Create an inert document that contains the dirty HTML that needs sanitizing |
430 |
| - * Depending upon browser support we use one of three strategies for doing this. |
431 |
| - * Support: Safari 10.x -> XHR strategy |
432 |
| - * Support: Firefox -> DomParser strategy |
| 429 | + * Create an inert document that contains the dirty HTML that needs sanitizing. |
| 430 | + * We use the DOMParser API by default and fall back to createHTMLDocument if DOMParser is not |
| 431 | + * available. |
433 | 432 | */
|
434 | 433 | var getInertBodyElement /* function(html: string): HTMLBodyElement */ = (function(window, document) {
|
435 |
| - var inertDocument; |
436 |
| - if (document && document.implementation) { |
437 |
| - inertDocument = document.implementation.createHTMLDocument('inert'); |
438 |
| - } else { |
439 |
| - throw $sanitizeMinErr('noinert', 'Can\'t create an inert html document'); |
| 434 | + if (isDOMParserAvailable()) { |
| 435 | + return getInertBodyElement_DOMParser; |
440 | 436 | }
|
441 |
| - var inertBodyElement = (inertDocument.documentElement || inertDocument.getDocumentElement()).querySelector('body'); |
442 | 437 |
|
443 |
| - // Check for the Safari 10.1 bug - which allows JS to run inside the SVG G element |
444 |
| - inertBodyElement.innerHTML = '<svg><g onload="this.parentNode.remove()"></g></svg>'; |
445 |
| - if (!inertBodyElement.querySelector('svg')) { |
446 |
| - return getInertBodyElement_XHR; |
447 |
| - } else { |
448 |
| - // Check for the Firefox bug - which prevents the inner img JS from being sanitized |
449 |
| - inertBodyElement.innerHTML = '<svg><p><style><img src="</style><img src=x onerror=alert(1)//">'; |
450 |
| - if (inertBodyElement.querySelector('svg img')) { |
451 |
| - return getInertBodyElement_DOMParser; |
452 |
| - } else { |
453 |
| - return getInertBodyElement_InertDocument; |
454 |
| - } |
| 438 | + if (!document || !document.implementation) { |
| 439 | + throw $sanitizeMinErr('noinert', 'Can\'t create an inert html document'); |
455 | 440 | }
|
| 441 | + var inertDocument = document.implementation.createHTMLDocument('inert'); |
| 442 | + var inertBodyElement = (inertDocument.documentElement || inertDocument.getDocumentElement()).querySelector('body'); |
| 443 | + return getInertBodyElement_InertDocument; |
456 | 444 |
|
457 |
| - function getInertBodyElement_XHR(html) { |
458 |
| - // We add this dummy element to ensure that the rest of the content is parsed as expected |
459 |
| - // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the `<head>` tag. |
460 |
| - html = '<remove></remove>' + html; |
| 445 | + function isDOMParserAvailable() { |
461 | 446 | try {
|
462 |
| - html = encodeURI(html); |
| 447 | + return !!getInertBodyElement_DOMParser(''); |
463 | 448 | } catch (e) {
|
464 |
| - return undefined; |
| 449 | + return false; |
465 | 450 | }
|
466 |
| - var xhr = new window.XMLHttpRequest(); |
467 |
| - xhr.responseType = 'document'; |
468 |
| - xhr.open('GET', 'data:text/html;charset=utf-8,' + html, false); |
469 |
| - xhr.send(null); |
470 |
| - var body = xhr.response.body; |
471 |
| - body.firstChild.remove(); |
472 |
| - return body; |
473 | 451 | }
|
474 | 452 |
|
475 | 453 | function getInertBodyElement_DOMParser(html) {
|
@@ -711,7 +689,7 @@ function sanitizeText(chars) {
|
711 | 689 | // define ngSanitize module and register $sanitize service
|
712 | 690 | angular.module('ngSanitize', [])
|
713 | 691 | .provider('$sanitize', $SanitizeProvider)
|
714 |
| - .info({ angularVersion: '1.7.9' }); |
| 692 | + .info({ angularVersion: '1.8.2' }); |
715 | 693 |
|
716 | 694 | /**
|
717 | 695 | * @ngdoc filter
|
|
0 commit comments