@angular/platform-browser 5.2.1 → 5.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v5.2.1
2
+ * @license Angular v5.2.5
3
3
  * (c) 2010-2018 Google, Inc. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -2779,6 +2779,176 @@ KeyEventsPlugin.ctorParameters = () => [
2779
2779
  { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT$1,] },] },
2780
2780
  ];
2781
2781
 
2782
+ /**
2783
+ * @fileoverview added by tsickle
2784
+ * @suppress {checkTypes} checked by tsc
2785
+ */
2786
+ /**
2787
+ * @license
2788
+ * Copyright Google Inc. All Rights Reserved.
2789
+ *
2790
+ * Use of this source code is governed by an MIT-style license that can be
2791
+ * found in the LICENSE file at https://angular.io/license
2792
+ */
2793
+ /**
2794
+ * This helper class is used to get hold of an inert tree of DOM elements containing dirty HTML
2795
+ * that needs sanitizing.
2796
+ * Depending upon browser support we must use one of three strategies for doing this.
2797
+ * Support: Safari 10.x -> XHR strategy
2798
+ * Support: Firefox -> DomParser strategy
2799
+ * Default: InertDocument strategy
2800
+ */
2801
+ class InertBodyHelper {
2802
+ /**
2803
+ * @param {?} defaultDoc
2804
+ * @param {?} DOM
2805
+ */
2806
+ constructor(defaultDoc, DOM) {
2807
+ this.defaultDoc = defaultDoc;
2808
+ this.DOM = DOM;
2809
+ const /** @type {?} */ inertDocument = this.DOM.createHtmlDocument();
2810
+ this.inertBodyElement = inertDocument.body;
2811
+ if (this.inertBodyElement == null) {
2812
+ // usually there should be only one body element in the document, but IE doesn't have any, so
2813
+ // we need to create one.
2814
+ const /** @type {?} */ inertHtml = this.DOM.createElement('html', inertDocument);
2815
+ this.inertBodyElement = this.DOM.createElement('body', inertDocument);
2816
+ this.DOM.appendChild(inertHtml, this.inertBodyElement);
2817
+ this.DOM.appendChild(inertDocument, inertHtml);
2818
+ }
2819
+ this.DOM.setInnerHTML(this.inertBodyElement, '<svg><g onload="this.parentNode.remove()"></g></svg>');
2820
+ if (this.inertBodyElement.querySelector && !this.inertBodyElement.querySelector('svg')) {
2821
+ // We just hit the Safari 10.1 bug - which allows JS to run inside the SVG G element
2822
+ // so use the XHR strategy.
2823
+ this.getInertBodyElement = this.getInertBodyElement_XHR;
2824
+ return;
2825
+ }
2826
+ this.DOM.setInnerHTML(this.inertBodyElement, '<svg><p><style><img src="</style><img src=x onerror=alert(1)//">');
2827
+ if (this.inertBodyElement.querySelector && this.inertBodyElement.querySelector('svg img')) {
2828
+ // We just hit the Firefox bug - which prevents the inner img JS from being sanitized
2829
+ // so use the DOMParser strategy, if it is available.
2830
+ // If the DOMParser is not available then we are not in Firefox (Server/WebWorker?) so we
2831
+ // fall through to the default strategy below.
2832
+ if (isDOMParserAvailable()) {
2833
+ this.getInertBodyElement = this.getInertBodyElement_DOMParser;
2834
+ return;
2835
+ }
2836
+ }
2837
+ // None of the bugs were hit so it is safe for us to use the default InertDocument strategy
2838
+ this.getInertBodyElement = this.getInertBodyElement_InertDocument;
2839
+ }
2840
+ /**
2841
+ * Use XHR to create and fill an inert body element (on Safari 10.1)
2842
+ * See
2843
+ * https://github.com/cure53/DOMPurify/blob/a992d3a75031cb8bb032e5ea8399ba972bdf9a65/src/purify.js#L439-L449
2844
+ * @param {?} html
2845
+ * @return {?}
2846
+ */
2847
+ getInertBodyElement_XHR(html) {
2848
+ // We add these extra elements to ensure that the rest of the content is parsed as expected
2849
+ // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the
2850
+ // `<head>` tag.
2851
+ html = '<body><remove></remove>' + html + '</body>';
2852
+ try {
2853
+ html = encodeURI(html);
2854
+ }
2855
+ catch (/** @type {?} */ e) {
2856
+ return null;
2857
+ }
2858
+ const /** @type {?} */ xhr = new XMLHttpRequest();
2859
+ xhr.responseType = 'document';
2860
+ xhr.open('GET', 'data:text/html;charset=utf-8,' + html, false);
2861
+ xhr.send(null);
2862
+ const /** @type {?} */ body = xhr.response.body;
2863
+ body.removeChild(/** @type {?} */ ((body.firstChild)));
2864
+ return body;
2865
+ }
2866
+ /**
2867
+ * Use DOMParser to create and fill an inert body element (on Firefox)
2868
+ * See https://github.com/cure53/DOMPurify/releases/tag/0.6.7
2869
+ *
2870
+ * @param {?} html
2871
+ * @return {?}
2872
+ */
2873
+ getInertBodyElement_DOMParser(html) {
2874
+ // We add these extra elements to ensure that the rest of the content is parsed as expected
2875
+ // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the
2876
+ // `<head>` tag.
2877
+ html = '<body><remove></remove>' + html + '</body>';
2878
+ try {
2879
+ const /** @type {?} */ body = /** @type {?} */ (new (/** @type {?} */ (window))
2880
+ .DOMParser()
2881
+ .parseFromString(html, 'text/html')
2882
+ .body);
2883
+ body.removeChild(/** @type {?} */ ((body.firstChild)));
2884
+ return body;
2885
+ }
2886
+ catch (/** @type {?} */ e) {
2887
+ return null;
2888
+ }
2889
+ }
2890
+ /**
2891
+ * Use an HTML5 `template` element, if supported, or an inert body element created via
2892
+ * `createHtmlDocument` to create and fill an inert DOM element.
2893
+ * This is the default sane strategy to use if the browser does not require one of the specialised
2894
+ * strategies above.
2895
+ * @param {?} html
2896
+ * @return {?}
2897
+ */
2898
+ getInertBodyElement_InertDocument(html) {
2899
+ // Prefer using <template> element if supported.
2900
+ const /** @type {?} */ templateEl = this.DOM.createElement('template');
2901
+ if ('content' in templateEl) {
2902
+ this.DOM.setInnerHTML(templateEl, html);
2903
+ return templateEl;
2904
+ }
2905
+ this.DOM.setInnerHTML(this.inertBodyElement, html);
2906
+ // Support: IE 9-11 only
2907
+ // strip custom-namespaced attributes on IE<=11
2908
+ if (this.defaultDoc.documentMode) {
2909
+ this.stripCustomNsAttrs(this.inertBodyElement);
2910
+ }
2911
+ return this.inertBodyElement;
2912
+ }
2913
+ /**
2914
+ * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1'
2915
+ * attribute to declare ns1 namespace and prefixes the attribute with 'ns1' (e.g.
2916
+ * 'ns1:xlink:foo').
2917
+ *
2918
+ * This is undesirable since we don't want to allow any of these custom attributes. This method
2919
+ * strips them all.
2920
+ * @param {?} el
2921
+ * @return {?}
2922
+ */
2923
+ stripCustomNsAttrs(el) {
2924
+ this.DOM.attributeMap(el).forEach((_, attrName) => {
2925
+ if (attrName === 'xmlns:ns1' || attrName.indexOf('ns1:') === 0) {
2926
+ this.DOM.removeAttribute(el, attrName);
2927
+ }
2928
+ });
2929
+ for (const /** @type {?} */ n of this.DOM.childNodesAsList(el)) {
2930
+ if (this.DOM.isElementNode(n))
2931
+ this.stripCustomNsAttrs(/** @type {?} */ (n));
2932
+ }
2933
+ }
2934
+ }
2935
+ /**
2936
+ * We need to determine whether the DOMParser exists in the global context.
2937
+ * The try-catch is because, on some browsers, trying to access this property
2938
+ * on window can actually throw an error.
2939
+ *
2940
+ * @suppress {uselessCode}
2941
+ * @return {?}
2942
+ */
2943
+ function isDOMParserAvailable() {
2944
+ try {
2945
+ return !!(/** @type {?} */ (window)).DOMParser;
2946
+ }
2947
+ catch (/** @type {?} */ e) {
2948
+ return false;
2949
+ }
2950
+ }
2951
+
2782
2952
  /**
2783
2953
  * @fileoverview added by tsickle
2784
2954
  * @suppress {checkTypes} checked by tsc
@@ -2854,38 +3024,6 @@ function sanitizeSrcset(srcset) {
2854
3024
  * Use of this source code is governed by an MIT-style license that can be
2855
3025
  * found in the LICENSE file at https://angular.io/license
2856
3026
  */
2857
- /**
2858
- * A <body> element that can be safely used to parse untrusted HTML. Lazily initialized below.
2859
- */
2860
- let inertElement = null;
2861
- /**
2862
- * Lazily initialized to make sure the DOM adapter gets set before use.
2863
- */
2864
- let DOM = /** @type {?} */ ((null));
2865
- /**
2866
- * Returns an HTML element that is guaranteed to not execute code when creating elements in it.
2867
- * @return {?}
2868
- */
2869
- function getInertElement() {
2870
- if (inertElement)
2871
- return inertElement;
2872
- DOM = getDOM();
2873
- // Prefer using <template> element if supported.
2874
- const /** @type {?} */ templateEl = DOM.createElement('template');
2875
- if ('content' in templateEl)
2876
- return templateEl;
2877
- const /** @type {?} */ doc = DOM.createHtmlDocument();
2878
- inertElement = DOM.querySelector(doc, 'body');
2879
- if (inertElement == null) {
2880
- // usually there should be only one body element in the document, but IE doesn't have any, so we
2881
- // need to create one.
2882
- const /** @type {?} */ html = DOM.createElement('html', doc);
2883
- inertElement = DOM.createElement('body', doc);
2884
- DOM.appendChild(html, inertElement);
2885
- DOM.appendChild(doc, html);
2886
- }
2887
- return inertElement;
2888
- }
2889
3027
  /**
2890
3028
  * @param {?} tags
2891
3029
  * @return {?}
@@ -2954,6 +3092,7 @@ class SanitizingHtmlSerializer {
2954
3092
  constructor() {
2955
3093
  this.sanitizedSomething = false;
2956
3094
  this.buf = [];
3095
+ this.DOM = getDOM();
2957
3096
  }
2958
3097
  /**
2959
3098
  * @param {?} el
@@ -2963,33 +3102,33 @@ class SanitizingHtmlSerializer {
2963
3102
  // This cannot use a TreeWalker, as it has to run on Angular's various DOM adapters.
2964
3103
  // However this code never accesses properties off of `document` before deleting its contents
2965
3104
  // again, so it shouldn't be vulnerable to DOM clobbering.
2966
- let /** @type {?} */ current = /** @type {?} */ ((el.firstChild));
3105
+ let /** @type {?} */ current = /** @type {?} */ ((this.DOM.firstChild(el)));
2967
3106
  while (current) {
2968
- if (DOM.isElementNode(current)) {
3107
+ if (this.DOM.isElementNode(current)) {
2969
3108
  this.startElement(/** @type {?} */ (current));
2970
3109
  }
2971
- else if (DOM.isTextNode(current)) {
2972
- this.chars(/** @type {?} */ ((DOM.nodeValue(current))));
3110
+ else if (this.DOM.isTextNode(current)) {
3111
+ this.chars(/** @type {?} */ ((this.DOM.nodeValue(current))));
2973
3112
  }
2974
3113
  else {
2975
3114
  // Strip non-element, non-text nodes.
2976
3115
  this.sanitizedSomething = true;
2977
3116
  }
2978
- if (DOM.firstChild(current)) {
2979
- current = /** @type {?} */ ((DOM.firstChild(current)));
3117
+ if (this.DOM.firstChild(current)) {
3118
+ current = /** @type {?} */ ((this.DOM.firstChild(current)));
2980
3119
  continue;
2981
3120
  }
2982
3121
  while (current) {
2983
3122
  // Leaving the element. Walk up and to the right, closing tags as we go.
2984
- if (DOM.isElementNode(current)) {
3123
+ if (this.DOM.isElementNode(current)) {
2985
3124
  this.endElement(/** @type {?} */ (current));
2986
3125
  }
2987
- let /** @type {?} */ next = checkClobberedElement(current, /** @type {?} */ ((DOM.nextSibling(current))));
3126
+ let /** @type {?} */ next = this.checkClobberedElement(current, /** @type {?} */ ((this.DOM.nextSibling(current))));
2988
3127
  if (next) {
2989
3128
  current = next;
2990
3129
  break;
2991
3130
  }
2992
- current = checkClobberedElement(current, /** @type {?} */ ((DOM.parentElement(current))));
3131
+ current = this.checkClobberedElement(current, /** @type {?} */ ((this.DOM.parentElement(current))));
2993
3132
  }
2994
3133
  }
2995
3134
  return this.buf.join('');
@@ -2999,14 +3138,14 @@ class SanitizingHtmlSerializer {
2999
3138
  * @return {?}
3000
3139
  */
3001
3140
  startElement(element) {
3002
- const /** @type {?} */ tagName = DOM.nodeName(element).toLowerCase();
3141
+ const /** @type {?} */ tagName = this.DOM.nodeName(element).toLowerCase();
3003
3142
  if (!VALID_ELEMENTS.hasOwnProperty(tagName)) {
3004
3143
  this.sanitizedSomething = true;
3005
3144
  return;
3006
3145
  }
3007
3146
  this.buf.push('<');
3008
3147
  this.buf.push(tagName);
3009
- DOM.attributeMap(element).forEach((value, attrName) => {
3148
+ this.DOM.attributeMap(element).forEach((value, attrName) => {
3010
3149
  const /** @type {?} */ lower = attrName.toLowerCase();
3011
3150
  if (!VALID_ATTRS.hasOwnProperty(lower)) {
3012
3151
  this.sanitizedSomething = true;
@@ -3030,7 +3169,7 @@ class SanitizingHtmlSerializer {
3030
3169
  * @return {?}
3031
3170
  */
3032
3171
  endElement(current) {
3033
- const /** @type {?} */ tagName = DOM.nodeName(current).toLowerCase();
3172
+ const /** @type {?} */ tagName = this.DOM.nodeName(current).toLowerCase();
3034
3173
  if (VALID_ELEMENTS.hasOwnProperty(tagName) && !VOID_ELEMENTS.hasOwnProperty(tagName)) {
3035
3174
  this.buf.push('</');
3036
3175
  this.buf.push(tagName);
@@ -3042,17 +3181,17 @@ class SanitizingHtmlSerializer {
3042
3181
  * @return {?}
3043
3182
  */
3044
3183
  chars(chars) { this.buf.push(encodeEntities(chars)); }
3045
- }
3046
- /**
3047
- * @param {?} node
3048
- * @param {?} nextNode
3049
- * @return {?}
3050
- */
3051
- function checkClobberedElement(node, nextNode) {
3052
- if (nextNode && DOM.contains(node, nextNode)) {
3053
- throw new Error(`Failed to sanitize html because the element is clobbered: ${DOM.getOuterHTML(node)}`);
3184
+ /**
3185
+ * @param {?} node
3186
+ * @param {?} nextNode
3187
+ * @return {?}
3188
+ */
3189
+ checkClobberedElement(node, nextNode) {
3190
+ if (nextNode && this.DOM.contains(node, nextNode)) {
3191
+ throw new Error(`Failed to sanitize html because the element is clobbered: ${this.DOM.getOuterHTML(node)}`);
3192
+ }
3193
+ return nextNode;
3054
3194
  }
3055
- return nextNode;
3056
3195
  }
3057
3196
  // Regular Expressions for parsing tags and attributes
3058
3197
  const SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
@@ -3076,26 +3215,7 @@ function encodeEntities(value) {
3076
3215
  .replace(/</g, '&lt;')
3077
3216
  .replace(/>/g, '&gt;');
3078
3217
  }
3079
- /**
3080
- * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1'
3081
- * attribute to declare ns1 namespace and prefixes the attribute with 'ns1' (e.g. 'ns1:xlink:foo').
3082
- *
3083
- * This is undesirable since we don't want to allow any of these custom attributes. This method
3084
- * strips them all.
3085
- * @param {?} el
3086
- * @return {?}
3087
- */
3088
- function stripCustomNsAttrs(el) {
3089
- DOM.attributeMap(el).forEach((_, attrName) => {
3090
- if (attrName === 'xmlns:ns1' || attrName.indexOf('ns1:') === 0) {
3091
- DOM.removeAttribute(el, attrName);
3092
- }
3093
- });
3094
- for (const /** @type {?} */ n of DOM.childNodesAsList(el)) {
3095
- if (DOM.isElementNode(n))
3096
- stripCustomNsAttrs(/** @type {?} */ (n));
3097
- }
3098
- }
3218
+ let inertBodyHelper;
3099
3219
  /**
3100
3220
  * Sanitizes the given unsafe, untrusted HTML fragment, and returns HTML text that is safe to add to
3101
3221
  * the DOM in a browser environment.
@@ -3104,10 +3224,13 @@ function stripCustomNsAttrs(el) {
3104
3224
  * @return {?}
3105
3225
  */
3106
3226
  function sanitizeHtml(defaultDoc, unsafeHtmlInput) {
3227
+ const /** @type {?} */ DOM = getDOM();
3228
+ let /** @type {?} */ inertBodyElement = null;
3107
3229
  try {
3108
- const /** @type {?} */ containerEl = getInertElement();
3230
+ inertBodyHelper = inertBodyHelper || new InertBodyHelper(defaultDoc, DOM);
3109
3231
  // Make sure unsafeHtml is actually a string (TypeScript types are not enforced at runtime).
3110
3232
  let /** @type {?} */ unsafeHtml = unsafeHtmlInput ? String(unsafeHtmlInput) : '';
3233
+ inertBodyElement = inertBodyHelper.getInertBodyElement(unsafeHtml);
3111
3234
  // mXSS protection. Repeatedly parse the document to make sure it stabilizes, so that a browser
3112
3235
  // trying to auto-correct incorrect HTML cannot cause formerly inert HTML to become dangerous.
3113
3236
  let /** @type {?} */ mXSSAttempts = 5;
@@ -3118,29 +3241,24 @@ function sanitizeHtml(defaultDoc, unsafeHtmlInput) {
3118
3241
  }
3119
3242
  mXSSAttempts--;
3120
3243
  unsafeHtml = parsedHtml;
3121
- DOM.setInnerHTML(containerEl, unsafeHtml);
3122
- if (defaultDoc.documentMode) {
3123
- // strip custom-namespaced attributes on IE<=11
3124
- stripCustomNsAttrs(containerEl);
3125
- }
3126
- parsedHtml = DOM.getInnerHTML(containerEl);
3244
+ parsedHtml = DOM.getInnerHTML(inertBodyElement);
3245
+ inertBodyElement = inertBodyHelper.getInertBodyElement(unsafeHtml);
3127
3246
  } while (unsafeHtml !== parsedHtml);
3128
3247
  const /** @type {?} */ sanitizer = new SanitizingHtmlSerializer();
3129
- const /** @type {?} */ safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(containerEl) || containerEl);
3130
- // Clear out the body element.
3131
- const /** @type {?} */ parent = DOM.getTemplateContent(containerEl) || containerEl;
3132
- for (const /** @type {?} */ child of DOM.childNodesAsList(parent)) {
3133
- DOM.removeChild(parent, child);
3134
- }
3248
+ const /** @type {?} */ safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(inertBodyElement) || inertBodyElement);
3135
3249
  if (isDevMode() && sanitizer.sanitizedSomething) {
3136
3250
  DOM.log('WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).');
3137
3251
  }
3138
3252
  return safeHtml;
3139
3253
  }
3140
- catch (/** @type {?} */ e) {
3254
+ finally {
3141
3255
  // In case anything goes wrong, clear out inertElement to reset the entire DOM structure.
3142
- inertElement = null;
3143
- throw e;
3256
+ if (inertBodyElement) {
3257
+ const /** @type {?} */ parent = DOM.getTemplateContent(inertBodyElement) || inertBodyElement;
3258
+ for (const /** @type {?} */ child of DOM.childNodesAsList(parent)) {
3259
+ DOM.removeChild(parent, child);
3260
+ }
3261
+ }
3144
3262
  }
3145
3263
  }
3146
3264
 
@@ -3815,7 +3933,9 @@ class TransferState {
3815
3933
  * @param {?} defaultValue
3816
3934
  * @return {?}
3817
3935
  */
3818
- get(key, defaultValue) { return /** @type {?} */ (this.store[key]) || defaultValue; }
3936
+ get(key, defaultValue) {
3937
+ return this.store[key] !== undefined ? /** @type {?} */ (this.store[key]) : defaultValue;
3938
+ }
3819
3939
  /**
3820
3940
  * Set the value corresponding to a key.
3821
3941
  * @template T
@@ -3990,7 +4110,7 @@ class By {
3990
4110
  /**
3991
4111
  * \@stable
3992
4112
  */
3993
- const VERSION = new Version('5.2.1');
4113
+ const VERSION = new Version('5.2.5');
3994
4114
 
3995
4115
  /**
3996
4116
  * @fileoverview added by tsickle