arcgis-html-sanitizer.js 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157
  1. /*!
  2. * @esri/arcgis-html-sanitizer - v2.10.0 - Tue Mar 15 2022 16:38:25 GMT-0400 (Eastern Daylight Time)
  3. * Copyright (c) 2022 - Environmental Systems Research Institute, Inc.
  4. * Apache-2.0
  5. *
  6. * js-xss
  7. * Copyright (c) 2012-2017 Zongmin Lei(雷宗民) <leizongmin@gmail.com>
  8. * http://ucdok.com
  9. * MIT License, see https://github.com/leizongmin/js-xss/blob/master/LICENSE for details
  10. *
  11. * Lodash/isPlainObject
  12. * Copyright (c) JS Foundation and other contributors <https://js.foundation/>
  13. * MIT License, see https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/LICENSE for details
  14. */
  15. (function (global, factory) {
  16. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  17. typeof define === 'function' && define.amd ? define(factory) :
  18. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Sanitizer = factory());
  19. })(this, (function () { 'use strict';
  20. /**
  21. * lodash (Custom Build) <https://lodash.com/>
  22. * Build: `lodash modularize exports="npm" -o ./`
  23. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  24. * Released under MIT license <https://lodash.com/license>
  25. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  26. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  27. */
  28. /** `Object#toString` result references. */
  29. var objectTag = '[object Object]';
  30. /**
  31. * Checks if `value` is a host object in IE < 9.
  32. *
  33. * @private
  34. * @param {*} value The value to check.
  35. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  36. */
  37. function isHostObject(value) {
  38. // Many host objects are `Object` objects that can coerce to strings
  39. // despite having improperly defined `toString` methods.
  40. var result = false;
  41. if (value != null && typeof value.toString != 'function') {
  42. try {
  43. result = !!(value + '');
  44. } catch (e) {}
  45. }
  46. return result;
  47. }
  48. /**
  49. * Creates a unary function that invokes `func` with its argument transformed.
  50. *
  51. * @private
  52. * @param {Function} func The function to wrap.
  53. * @param {Function} transform The argument transform.
  54. * @returns {Function} Returns the new function.
  55. */
  56. function overArg(func, transform) {
  57. return function(arg) {
  58. return func(transform(arg));
  59. };
  60. }
  61. /** Used for built-in method references. */
  62. var funcProto = Function.prototype,
  63. objectProto = Object.prototype;
  64. /** Used to resolve the decompiled source of functions. */
  65. var funcToString = funcProto.toString;
  66. /** Used to check objects for own properties. */
  67. var hasOwnProperty = objectProto.hasOwnProperty;
  68. /** Used to infer the `Object` constructor. */
  69. var objectCtorString = funcToString.call(Object);
  70. /**
  71. * Used to resolve the
  72. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  73. * of values.
  74. */
  75. var objectToString = objectProto.toString;
  76. /** Built-in value references. */
  77. var getPrototype = overArg(Object.getPrototypeOf, Object);
  78. /**
  79. * Checks if `value` is object-like. A value is object-like if it's not `null`
  80. * and has a `typeof` result of "object".
  81. *
  82. * @static
  83. * @memberOf _
  84. * @since 4.0.0
  85. * @category Lang
  86. * @param {*} value The value to check.
  87. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  88. * @example
  89. *
  90. * _.isObjectLike({});
  91. * // => true
  92. *
  93. * _.isObjectLike([1, 2, 3]);
  94. * // => true
  95. *
  96. * _.isObjectLike(_.noop);
  97. * // => false
  98. *
  99. * _.isObjectLike(null);
  100. * // => false
  101. */
  102. function isObjectLike(value) {
  103. return !!value && typeof value == 'object';
  104. }
  105. /**
  106. * Checks if `value` is a plain object, that is, an object created by the
  107. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  108. *
  109. * @static
  110. * @memberOf _
  111. * @since 0.8.0
  112. * @category Lang
  113. * @param {*} value The value to check.
  114. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  115. * @example
  116. *
  117. * function Foo() {
  118. * this.a = 1;
  119. * }
  120. *
  121. * _.isPlainObject(new Foo);
  122. * // => false
  123. *
  124. * _.isPlainObject([1, 2, 3]);
  125. * // => false
  126. *
  127. * _.isPlainObject({ 'x': 0, 'y': 0 });
  128. * // => true
  129. *
  130. * _.isPlainObject(Object.create(null));
  131. * // => true
  132. */
  133. function isPlainObject(value) {
  134. if (!isObjectLike(value) ||
  135. objectToString.call(value) != objectTag || isHostObject(value)) {
  136. return false;
  137. }
  138. var proto = getPrototype(value);
  139. if (proto === null) {
  140. return true;
  141. }
  142. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  143. return (typeof Ctor == 'function' &&
  144. Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
  145. }
  146. var lodash_isplainobject = isPlainObject;
  147. var lib$1 = {exports: {}};
  148. var _default$1 = {};
  149. var lib = {exports: {}};
  150. var _default = {};
  151. /**
  152. * cssfilter
  153. *
  154. * @author 老雷<leizongmin@gmail.com>
  155. */
  156. function getDefaultWhiteList$1 () {
  157. // 白名单值说明:
  158. // true: 允许该属性
  159. // Function: function (val) { } 返回true表示允许该属性,其他值均表示不允许
  160. // RegExp: regexp.test(val) 返回true表示允许该属性,其他值均表示不允许
  161. // 除上面列出的值外均表示不允许
  162. var whiteList = {};
  163. whiteList['align-content'] = false; // default: auto
  164. whiteList['align-items'] = false; // default: auto
  165. whiteList['align-self'] = false; // default: auto
  166. whiteList['alignment-adjust'] = false; // default: auto
  167. whiteList['alignment-baseline'] = false; // default: baseline
  168. whiteList['all'] = false; // default: depending on individual properties
  169. whiteList['anchor-point'] = false; // default: none
  170. whiteList['animation'] = false; // default: depending on individual properties
  171. whiteList['animation-delay'] = false; // default: 0
  172. whiteList['animation-direction'] = false; // default: normal
  173. whiteList['animation-duration'] = false; // default: 0
  174. whiteList['animation-fill-mode'] = false; // default: none
  175. whiteList['animation-iteration-count'] = false; // default: 1
  176. whiteList['animation-name'] = false; // default: none
  177. whiteList['animation-play-state'] = false; // default: running
  178. whiteList['animation-timing-function'] = false; // default: ease
  179. whiteList['azimuth'] = false; // default: center
  180. whiteList['backface-visibility'] = false; // default: visible
  181. whiteList['background'] = true; // default: depending on individual properties
  182. whiteList['background-attachment'] = true; // default: scroll
  183. whiteList['background-clip'] = true; // default: border-box
  184. whiteList['background-color'] = true; // default: transparent
  185. whiteList['background-image'] = true; // default: none
  186. whiteList['background-origin'] = true; // default: padding-box
  187. whiteList['background-position'] = true; // default: 0% 0%
  188. whiteList['background-repeat'] = true; // default: repeat
  189. whiteList['background-size'] = true; // default: auto
  190. whiteList['baseline-shift'] = false; // default: baseline
  191. whiteList['binding'] = false; // default: none
  192. whiteList['bleed'] = false; // default: 6pt
  193. whiteList['bookmark-label'] = false; // default: content()
  194. whiteList['bookmark-level'] = false; // default: none
  195. whiteList['bookmark-state'] = false; // default: open
  196. whiteList['border'] = true; // default: depending on individual properties
  197. whiteList['border-bottom'] = true; // default: depending on individual properties
  198. whiteList['border-bottom-color'] = true; // default: current color
  199. whiteList['border-bottom-left-radius'] = true; // default: 0
  200. whiteList['border-bottom-right-radius'] = true; // default: 0
  201. whiteList['border-bottom-style'] = true; // default: none
  202. whiteList['border-bottom-width'] = true; // default: medium
  203. whiteList['border-collapse'] = true; // default: separate
  204. whiteList['border-color'] = true; // default: depending on individual properties
  205. whiteList['border-image'] = true; // default: none
  206. whiteList['border-image-outset'] = true; // default: 0
  207. whiteList['border-image-repeat'] = true; // default: stretch
  208. whiteList['border-image-slice'] = true; // default: 100%
  209. whiteList['border-image-source'] = true; // default: none
  210. whiteList['border-image-width'] = true; // default: 1
  211. whiteList['border-left'] = true; // default: depending on individual properties
  212. whiteList['border-left-color'] = true; // default: current color
  213. whiteList['border-left-style'] = true; // default: none
  214. whiteList['border-left-width'] = true; // default: medium
  215. whiteList['border-radius'] = true; // default: 0
  216. whiteList['border-right'] = true; // default: depending on individual properties
  217. whiteList['border-right-color'] = true; // default: current color
  218. whiteList['border-right-style'] = true; // default: none
  219. whiteList['border-right-width'] = true; // default: medium
  220. whiteList['border-spacing'] = true; // default: 0
  221. whiteList['border-style'] = true; // default: depending on individual properties
  222. whiteList['border-top'] = true; // default: depending on individual properties
  223. whiteList['border-top-color'] = true; // default: current color
  224. whiteList['border-top-left-radius'] = true; // default: 0
  225. whiteList['border-top-right-radius'] = true; // default: 0
  226. whiteList['border-top-style'] = true; // default: none
  227. whiteList['border-top-width'] = true; // default: medium
  228. whiteList['border-width'] = true; // default: depending on individual properties
  229. whiteList['bottom'] = false; // default: auto
  230. whiteList['box-decoration-break'] = true; // default: slice
  231. whiteList['box-shadow'] = true; // default: none
  232. whiteList['box-sizing'] = true; // default: content-box
  233. whiteList['box-snap'] = true; // default: none
  234. whiteList['box-suppress'] = true; // default: show
  235. whiteList['break-after'] = true; // default: auto
  236. whiteList['break-before'] = true; // default: auto
  237. whiteList['break-inside'] = true; // default: auto
  238. whiteList['caption-side'] = false; // default: top
  239. whiteList['chains'] = false; // default: none
  240. whiteList['clear'] = true; // default: none
  241. whiteList['clip'] = false; // default: auto
  242. whiteList['clip-path'] = false; // default: none
  243. whiteList['clip-rule'] = false; // default: nonzero
  244. whiteList['color'] = true; // default: implementation dependent
  245. whiteList['color-interpolation-filters'] = true; // default: auto
  246. whiteList['column-count'] = false; // default: auto
  247. whiteList['column-fill'] = false; // default: balance
  248. whiteList['column-gap'] = false; // default: normal
  249. whiteList['column-rule'] = false; // default: depending on individual properties
  250. whiteList['column-rule-color'] = false; // default: current color
  251. whiteList['column-rule-style'] = false; // default: medium
  252. whiteList['column-rule-width'] = false; // default: medium
  253. whiteList['column-span'] = false; // default: none
  254. whiteList['column-width'] = false; // default: auto
  255. whiteList['columns'] = false; // default: depending on individual properties
  256. whiteList['contain'] = false; // default: none
  257. whiteList['content'] = false; // default: normal
  258. whiteList['counter-increment'] = false; // default: none
  259. whiteList['counter-reset'] = false; // default: none
  260. whiteList['counter-set'] = false; // default: none
  261. whiteList['crop'] = false; // default: auto
  262. whiteList['cue'] = false; // default: depending on individual properties
  263. whiteList['cue-after'] = false; // default: none
  264. whiteList['cue-before'] = false; // default: none
  265. whiteList['cursor'] = false; // default: auto
  266. whiteList['direction'] = false; // default: ltr
  267. whiteList['display'] = true; // default: depending on individual properties
  268. whiteList['display-inside'] = true; // default: auto
  269. whiteList['display-list'] = true; // default: none
  270. whiteList['display-outside'] = true; // default: inline-level
  271. whiteList['dominant-baseline'] = false; // default: auto
  272. whiteList['elevation'] = false; // default: level
  273. whiteList['empty-cells'] = false; // default: show
  274. whiteList['filter'] = false; // default: none
  275. whiteList['flex'] = false; // default: depending on individual properties
  276. whiteList['flex-basis'] = false; // default: auto
  277. whiteList['flex-direction'] = false; // default: row
  278. whiteList['flex-flow'] = false; // default: depending on individual properties
  279. whiteList['flex-grow'] = false; // default: 0
  280. whiteList['flex-shrink'] = false; // default: 1
  281. whiteList['flex-wrap'] = false; // default: nowrap
  282. whiteList['float'] = false; // default: none
  283. whiteList['float-offset'] = false; // default: 0 0
  284. whiteList['flood-color'] = false; // default: black
  285. whiteList['flood-opacity'] = false; // default: 1
  286. whiteList['flow-from'] = false; // default: none
  287. whiteList['flow-into'] = false; // default: none
  288. whiteList['font'] = true; // default: depending on individual properties
  289. whiteList['font-family'] = true; // default: implementation dependent
  290. whiteList['font-feature-settings'] = true; // default: normal
  291. whiteList['font-kerning'] = true; // default: auto
  292. whiteList['font-language-override'] = true; // default: normal
  293. whiteList['font-size'] = true; // default: medium
  294. whiteList['font-size-adjust'] = true; // default: none
  295. whiteList['font-stretch'] = true; // default: normal
  296. whiteList['font-style'] = true; // default: normal
  297. whiteList['font-synthesis'] = true; // default: weight style
  298. whiteList['font-variant'] = true; // default: normal
  299. whiteList['font-variant-alternates'] = true; // default: normal
  300. whiteList['font-variant-caps'] = true; // default: normal
  301. whiteList['font-variant-east-asian'] = true; // default: normal
  302. whiteList['font-variant-ligatures'] = true; // default: normal
  303. whiteList['font-variant-numeric'] = true; // default: normal
  304. whiteList['font-variant-position'] = true; // default: normal
  305. whiteList['font-weight'] = true; // default: normal
  306. whiteList['grid'] = false; // default: depending on individual properties
  307. whiteList['grid-area'] = false; // default: depending on individual properties
  308. whiteList['grid-auto-columns'] = false; // default: auto
  309. whiteList['grid-auto-flow'] = false; // default: none
  310. whiteList['grid-auto-rows'] = false; // default: auto
  311. whiteList['grid-column'] = false; // default: depending on individual properties
  312. whiteList['grid-column-end'] = false; // default: auto
  313. whiteList['grid-column-start'] = false; // default: auto
  314. whiteList['grid-row'] = false; // default: depending on individual properties
  315. whiteList['grid-row-end'] = false; // default: auto
  316. whiteList['grid-row-start'] = false; // default: auto
  317. whiteList['grid-template'] = false; // default: depending on individual properties
  318. whiteList['grid-template-areas'] = false; // default: none
  319. whiteList['grid-template-columns'] = false; // default: none
  320. whiteList['grid-template-rows'] = false; // default: none
  321. whiteList['hanging-punctuation'] = false; // default: none
  322. whiteList['height'] = true; // default: auto
  323. whiteList['hyphens'] = false; // default: manual
  324. whiteList['icon'] = false; // default: auto
  325. whiteList['image-orientation'] = false; // default: auto
  326. whiteList['image-resolution'] = false; // default: normal
  327. whiteList['ime-mode'] = false; // default: auto
  328. whiteList['initial-letters'] = false; // default: normal
  329. whiteList['inline-box-align'] = false; // default: last
  330. whiteList['justify-content'] = false; // default: auto
  331. whiteList['justify-items'] = false; // default: auto
  332. whiteList['justify-self'] = false; // default: auto
  333. whiteList['left'] = false; // default: auto
  334. whiteList['letter-spacing'] = true; // default: normal
  335. whiteList['lighting-color'] = true; // default: white
  336. whiteList['line-box-contain'] = false; // default: block inline replaced
  337. whiteList['line-break'] = false; // default: auto
  338. whiteList['line-grid'] = false; // default: match-parent
  339. whiteList['line-height'] = false; // default: normal
  340. whiteList['line-snap'] = false; // default: none
  341. whiteList['line-stacking'] = false; // default: depending on individual properties
  342. whiteList['line-stacking-ruby'] = false; // default: exclude-ruby
  343. whiteList['line-stacking-shift'] = false; // default: consider-shifts
  344. whiteList['line-stacking-strategy'] = false; // default: inline-line-height
  345. whiteList['list-style'] = true; // default: depending on individual properties
  346. whiteList['list-style-image'] = true; // default: none
  347. whiteList['list-style-position'] = true; // default: outside
  348. whiteList['list-style-type'] = true; // default: disc
  349. whiteList['margin'] = true; // default: depending on individual properties
  350. whiteList['margin-bottom'] = true; // default: 0
  351. whiteList['margin-left'] = true; // default: 0
  352. whiteList['margin-right'] = true; // default: 0
  353. whiteList['margin-top'] = true; // default: 0
  354. whiteList['marker-offset'] = false; // default: auto
  355. whiteList['marker-side'] = false; // default: list-item
  356. whiteList['marks'] = false; // default: none
  357. whiteList['mask'] = false; // default: border-box
  358. whiteList['mask-box'] = false; // default: see individual properties
  359. whiteList['mask-box-outset'] = false; // default: 0
  360. whiteList['mask-box-repeat'] = false; // default: stretch
  361. whiteList['mask-box-slice'] = false; // default: 0 fill
  362. whiteList['mask-box-source'] = false; // default: none
  363. whiteList['mask-box-width'] = false; // default: auto
  364. whiteList['mask-clip'] = false; // default: border-box
  365. whiteList['mask-image'] = false; // default: none
  366. whiteList['mask-origin'] = false; // default: border-box
  367. whiteList['mask-position'] = false; // default: center
  368. whiteList['mask-repeat'] = false; // default: no-repeat
  369. whiteList['mask-size'] = false; // default: border-box
  370. whiteList['mask-source-type'] = false; // default: auto
  371. whiteList['mask-type'] = false; // default: luminance
  372. whiteList['max-height'] = true; // default: none
  373. whiteList['max-lines'] = false; // default: none
  374. whiteList['max-width'] = true; // default: none
  375. whiteList['min-height'] = true; // default: 0
  376. whiteList['min-width'] = true; // default: 0
  377. whiteList['move-to'] = false; // default: normal
  378. whiteList['nav-down'] = false; // default: auto
  379. whiteList['nav-index'] = false; // default: auto
  380. whiteList['nav-left'] = false; // default: auto
  381. whiteList['nav-right'] = false; // default: auto
  382. whiteList['nav-up'] = false; // default: auto
  383. whiteList['object-fit'] = false; // default: fill
  384. whiteList['object-position'] = false; // default: 50% 50%
  385. whiteList['opacity'] = false; // default: 1
  386. whiteList['order'] = false; // default: 0
  387. whiteList['orphans'] = false; // default: 2
  388. whiteList['outline'] = false; // default: depending on individual properties
  389. whiteList['outline-color'] = false; // default: invert
  390. whiteList['outline-offset'] = false; // default: 0
  391. whiteList['outline-style'] = false; // default: none
  392. whiteList['outline-width'] = false; // default: medium
  393. whiteList['overflow'] = false; // default: depending on individual properties
  394. whiteList['overflow-wrap'] = false; // default: normal
  395. whiteList['overflow-x'] = false; // default: visible
  396. whiteList['overflow-y'] = false; // default: visible
  397. whiteList['padding'] = true; // default: depending on individual properties
  398. whiteList['padding-bottom'] = true; // default: 0
  399. whiteList['padding-left'] = true; // default: 0
  400. whiteList['padding-right'] = true; // default: 0
  401. whiteList['padding-top'] = true; // default: 0
  402. whiteList['page'] = false; // default: auto
  403. whiteList['page-break-after'] = false; // default: auto
  404. whiteList['page-break-before'] = false; // default: auto
  405. whiteList['page-break-inside'] = false; // default: auto
  406. whiteList['page-policy'] = false; // default: start
  407. whiteList['pause'] = false; // default: implementation dependent
  408. whiteList['pause-after'] = false; // default: implementation dependent
  409. whiteList['pause-before'] = false; // default: implementation dependent
  410. whiteList['perspective'] = false; // default: none
  411. whiteList['perspective-origin'] = false; // default: 50% 50%
  412. whiteList['pitch'] = false; // default: medium
  413. whiteList['pitch-range'] = false; // default: 50
  414. whiteList['play-during'] = false; // default: auto
  415. whiteList['position'] = false; // default: static
  416. whiteList['presentation-level'] = false; // default: 0
  417. whiteList['quotes'] = false; // default: text
  418. whiteList['region-fragment'] = false; // default: auto
  419. whiteList['resize'] = false; // default: none
  420. whiteList['rest'] = false; // default: depending on individual properties
  421. whiteList['rest-after'] = false; // default: none
  422. whiteList['rest-before'] = false; // default: none
  423. whiteList['richness'] = false; // default: 50
  424. whiteList['right'] = false; // default: auto
  425. whiteList['rotation'] = false; // default: 0
  426. whiteList['rotation-point'] = false; // default: 50% 50%
  427. whiteList['ruby-align'] = false; // default: auto
  428. whiteList['ruby-merge'] = false; // default: separate
  429. whiteList['ruby-position'] = false; // default: before
  430. whiteList['shape-image-threshold'] = false; // default: 0.0
  431. whiteList['shape-outside'] = false; // default: none
  432. whiteList['shape-margin'] = false; // default: 0
  433. whiteList['size'] = false; // default: auto
  434. whiteList['speak'] = false; // default: auto
  435. whiteList['speak-as'] = false; // default: normal
  436. whiteList['speak-header'] = false; // default: once
  437. whiteList['speak-numeral'] = false; // default: continuous
  438. whiteList['speak-punctuation'] = false; // default: none
  439. whiteList['speech-rate'] = false; // default: medium
  440. whiteList['stress'] = false; // default: 50
  441. whiteList['string-set'] = false; // default: none
  442. whiteList['tab-size'] = false; // default: 8
  443. whiteList['table-layout'] = false; // default: auto
  444. whiteList['text-align'] = true; // default: start
  445. whiteList['text-align-last'] = true; // default: auto
  446. whiteList['text-combine-upright'] = true; // default: none
  447. whiteList['text-decoration'] = true; // default: none
  448. whiteList['text-decoration-color'] = true; // default: currentColor
  449. whiteList['text-decoration-line'] = true; // default: none
  450. whiteList['text-decoration-skip'] = true; // default: objects
  451. whiteList['text-decoration-style'] = true; // default: solid
  452. whiteList['text-emphasis'] = true; // default: depending on individual properties
  453. whiteList['text-emphasis-color'] = true; // default: currentColor
  454. whiteList['text-emphasis-position'] = true; // default: over right
  455. whiteList['text-emphasis-style'] = true; // default: none
  456. whiteList['text-height'] = true; // default: auto
  457. whiteList['text-indent'] = true; // default: 0
  458. whiteList['text-justify'] = true; // default: auto
  459. whiteList['text-orientation'] = true; // default: mixed
  460. whiteList['text-overflow'] = true; // default: clip
  461. whiteList['text-shadow'] = true; // default: none
  462. whiteList['text-space-collapse'] = true; // default: collapse
  463. whiteList['text-transform'] = true; // default: none
  464. whiteList['text-underline-position'] = true; // default: auto
  465. whiteList['text-wrap'] = true; // default: normal
  466. whiteList['top'] = false; // default: auto
  467. whiteList['transform'] = false; // default: none
  468. whiteList['transform-origin'] = false; // default: 50% 50% 0
  469. whiteList['transform-style'] = false; // default: flat
  470. whiteList['transition'] = false; // default: depending on individual properties
  471. whiteList['transition-delay'] = false; // default: 0s
  472. whiteList['transition-duration'] = false; // default: 0s
  473. whiteList['transition-property'] = false; // default: all
  474. whiteList['transition-timing-function'] = false; // default: ease
  475. whiteList['unicode-bidi'] = false; // default: normal
  476. whiteList['vertical-align'] = false; // default: baseline
  477. whiteList['visibility'] = false; // default: visible
  478. whiteList['voice-balance'] = false; // default: center
  479. whiteList['voice-duration'] = false; // default: auto
  480. whiteList['voice-family'] = false; // default: implementation dependent
  481. whiteList['voice-pitch'] = false; // default: medium
  482. whiteList['voice-range'] = false; // default: medium
  483. whiteList['voice-rate'] = false; // default: normal
  484. whiteList['voice-stress'] = false; // default: normal
  485. whiteList['voice-volume'] = false; // default: medium
  486. whiteList['volume'] = false; // default: medium
  487. whiteList['white-space'] = false; // default: normal
  488. whiteList['widows'] = false; // default: 2
  489. whiteList['width'] = true; // default: auto
  490. whiteList['will-change'] = false; // default: auto
  491. whiteList['word-break'] = true; // default: normal
  492. whiteList['word-spacing'] = true; // default: normal
  493. whiteList['word-wrap'] = true; // default: normal
  494. whiteList['wrap-flow'] = false; // default: auto
  495. whiteList['wrap-through'] = false; // default: wrap
  496. whiteList['writing-mode'] = false; // default: horizontal-tb
  497. whiteList['z-index'] = false; // default: auto
  498. return whiteList;
  499. }
  500. /**
  501. * 匹配到白名单上的一个属性时
  502. *
  503. * @param {String} name
  504. * @param {String} value
  505. * @param {Object} options
  506. * @return {String}
  507. */
  508. function onAttr (name, value, options) {
  509. // do nothing
  510. }
  511. /**
  512. * 匹配到不在白名单上的一个属性时
  513. *
  514. * @param {String} name
  515. * @param {String} value
  516. * @param {Object} options
  517. * @return {String}
  518. */
  519. function onIgnoreAttr (name, value, options) {
  520. // do nothing
  521. }
  522. var REGEXP_URL_JAVASCRIPT = /javascript\s*\:/img;
  523. /**
  524. * 过滤属性值
  525. *
  526. * @param {String} name
  527. * @param {String} value
  528. * @return {String}
  529. */
  530. function safeAttrValue$1(name, value) {
  531. if (REGEXP_URL_JAVASCRIPT.test(value)) return '';
  532. return value;
  533. }
  534. _default.whiteList = getDefaultWhiteList$1();
  535. _default.getDefaultWhiteList = getDefaultWhiteList$1;
  536. _default.onAttr = onAttr;
  537. _default.onIgnoreAttr = onIgnoreAttr;
  538. _default.safeAttrValue = safeAttrValue$1;
  539. var util$1 = {
  540. indexOf: function (arr, item) {
  541. var i, j;
  542. if (Array.prototype.indexOf) {
  543. return arr.indexOf(item);
  544. }
  545. for (i = 0, j = arr.length; i < j; i++) {
  546. if (arr[i] === item) {
  547. return i;
  548. }
  549. }
  550. return -1;
  551. },
  552. forEach: function (arr, fn, scope) {
  553. var i, j;
  554. if (Array.prototype.forEach) {
  555. return arr.forEach(fn, scope);
  556. }
  557. for (i = 0, j = arr.length; i < j; i++) {
  558. fn.call(scope, arr[i], i, arr);
  559. }
  560. },
  561. trim: function (str) {
  562. if (String.prototype.trim) {
  563. return str.trim();
  564. }
  565. return str.replace(/(^\s*)|(\s*$)/g, '');
  566. },
  567. trimRight: function (str) {
  568. if (String.prototype.trimRight) {
  569. return str.trimRight();
  570. }
  571. return str.replace(/(\s*$)/g, '');
  572. }
  573. };
  574. /**
  575. * cssfilter
  576. *
  577. * @author 老雷<leizongmin@gmail.com>
  578. */
  579. var _$3 = util$1;
  580. /**
  581. * 解析style
  582. *
  583. * @param {String} css
  584. * @param {Function} onAttr 处理属性的函数
  585. * 参数格式: function (sourcePosition, position, name, value, source)
  586. * @return {String}
  587. */
  588. function parseStyle$1 (css, onAttr) {
  589. css = _$3.trimRight(css);
  590. if (css[css.length - 1] !== ';') css += ';';
  591. var cssLength = css.length;
  592. var isParenthesisOpen = false;
  593. var lastPos = 0;
  594. var i = 0;
  595. var retCSS = '';
  596. function addNewAttr () {
  597. // 如果没有正常的闭合圆括号,则直接忽略当前属性
  598. if (!isParenthesisOpen) {
  599. var source = _$3.trim(css.slice(lastPos, i));
  600. var j = source.indexOf(':');
  601. if (j !== -1) {
  602. var name = _$3.trim(source.slice(0, j));
  603. var value = _$3.trim(source.slice(j + 1));
  604. // 必须有属性名称
  605. if (name) {
  606. var ret = onAttr(lastPos, retCSS.length, name, value, source);
  607. if (ret) retCSS += ret + '; ';
  608. }
  609. }
  610. }
  611. lastPos = i + 1;
  612. }
  613. for (; i < cssLength; i++) {
  614. var c = css[i];
  615. if (c === '/' && css[i + 1] === '*') {
  616. // 备注开始
  617. var j = css.indexOf('*/', i + 2);
  618. // 如果没有正常的备注结束,则后面的部分全部跳过
  619. if (j === -1) break;
  620. // 直接将当前位置调到备注结尾,并且初始化状态
  621. i = j + 1;
  622. lastPos = i + 1;
  623. isParenthesisOpen = false;
  624. } else if (c === '(') {
  625. isParenthesisOpen = true;
  626. } else if (c === ')') {
  627. isParenthesisOpen = false;
  628. } else if (c === ';') {
  629. if (isParenthesisOpen) ; else {
  630. addNewAttr();
  631. }
  632. } else if (c === '\n') {
  633. addNewAttr();
  634. }
  635. }
  636. return _$3.trim(retCSS);
  637. }
  638. var parser$2 = parseStyle$1;
  639. /**
  640. * cssfilter
  641. *
  642. * @author 老雷<leizongmin@gmail.com>
  643. */
  644. var DEFAULT$1 = _default;
  645. var parseStyle = parser$2;
  646. /**
  647. * 返回值是否为空
  648. *
  649. * @param {Object} obj
  650. * @return {Boolean}
  651. */
  652. function isNull$1 (obj) {
  653. return (obj === undefined || obj === null);
  654. }
  655. /**
  656. * 浅拷贝对象
  657. *
  658. * @param {Object} obj
  659. * @return {Object}
  660. */
  661. function shallowCopyObject$1 (obj) {
  662. var ret = {};
  663. for (var i in obj) {
  664. ret[i] = obj[i];
  665. }
  666. return ret;
  667. }
  668. /**
  669. * 创建CSS过滤器
  670. *
  671. * @param {Object} options
  672. * - {Object} whiteList
  673. * - {Function} onAttr
  674. * - {Function} onIgnoreAttr
  675. * - {Function} safeAttrValue
  676. */
  677. function FilterCSS$2 (options) {
  678. options = shallowCopyObject$1(options || {});
  679. options.whiteList = options.whiteList || DEFAULT$1.whiteList;
  680. options.onAttr = options.onAttr || DEFAULT$1.onAttr;
  681. options.onIgnoreAttr = options.onIgnoreAttr || DEFAULT$1.onIgnoreAttr;
  682. options.safeAttrValue = options.safeAttrValue || DEFAULT$1.safeAttrValue;
  683. this.options = options;
  684. }
  685. FilterCSS$2.prototype.process = function (css) {
  686. // 兼容各种奇葩输入
  687. css = css || '';
  688. css = css.toString();
  689. if (!css) return '';
  690. var me = this;
  691. var options = me.options;
  692. var whiteList = options.whiteList;
  693. var onAttr = options.onAttr;
  694. var onIgnoreAttr = options.onIgnoreAttr;
  695. var safeAttrValue = options.safeAttrValue;
  696. var retCSS = parseStyle(css, function (sourcePosition, position, name, value, source) {
  697. var check = whiteList[name];
  698. var isWhite = false;
  699. if (check === true) isWhite = check;
  700. else if (typeof check === 'function') isWhite = check(value);
  701. else if (check instanceof RegExp) isWhite = check.test(value);
  702. if (isWhite !== true) isWhite = false;
  703. // 如果过滤后 value 为空则直接忽略
  704. value = safeAttrValue(name, value);
  705. if (!value) return;
  706. var opts = {
  707. position: position,
  708. sourcePosition: sourcePosition,
  709. source: source,
  710. isWhite: isWhite
  711. };
  712. if (isWhite) {
  713. var ret = onAttr(name, value, opts);
  714. if (isNull$1(ret)) {
  715. return name + ':' + value;
  716. } else {
  717. return ret;
  718. }
  719. } else {
  720. var ret = onIgnoreAttr(name, value, opts);
  721. if (!isNull$1(ret)) {
  722. return ret;
  723. }
  724. }
  725. });
  726. return retCSS;
  727. };
  728. var css = FilterCSS$2;
  729. /**
  730. * cssfilter
  731. *
  732. * @author 老雷<leizongmin@gmail.com>
  733. */
  734. (function (module, exports) {
  735. var DEFAULT = _default;
  736. var FilterCSS = css;
  737. /**
  738. * XSS过滤
  739. *
  740. * @param {String} css 要过滤的CSS代码
  741. * @param {Object} options 选项:whiteList, onAttr, onIgnoreAttr
  742. * @return {String}
  743. */
  744. function filterCSS (html, options) {
  745. var xss = new FilterCSS(options);
  746. return xss.process(html);
  747. }
  748. // 输出
  749. exports = module.exports = filterCSS;
  750. exports.FilterCSS = FilterCSS;
  751. for (var i in DEFAULT) exports[i] = DEFAULT[i];
  752. }(lib, lib.exports));
  753. var util = {
  754. indexOf: function (arr, item) {
  755. var i, j;
  756. if (Array.prototype.indexOf) {
  757. return arr.indexOf(item);
  758. }
  759. for (i = 0, j = arr.length; i < j; i++) {
  760. if (arr[i] === item) {
  761. return i;
  762. }
  763. }
  764. return -1;
  765. },
  766. forEach: function (arr, fn, scope) {
  767. var i, j;
  768. if (Array.prototype.forEach) {
  769. return arr.forEach(fn, scope);
  770. }
  771. for (i = 0, j = arr.length; i < j; i++) {
  772. fn.call(scope, arr[i], i, arr);
  773. }
  774. },
  775. trim: function (str) {
  776. if (String.prototype.trim) {
  777. return str.trim();
  778. }
  779. return str.replace(/(^\s*)|(\s*$)/g, "");
  780. },
  781. spaceIndex: function (str) {
  782. var reg = /\s|\n|\t/;
  783. var match = reg.exec(str);
  784. return match ? match.index : -1;
  785. },
  786. };
  787. /**
  788. * default settings
  789. *
  790. * @author Zongmin Lei<leizongmin@gmail.com>
  791. */
  792. var FilterCSS$1 = lib.exports.FilterCSS;
  793. var getDefaultCSSWhiteList = lib.exports.getDefaultWhiteList;
  794. var _$2 = util;
  795. function getDefaultWhiteList() {
  796. return {
  797. a: ["target", "href", "title"],
  798. abbr: ["title"],
  799. address: [],
  800. area: ["shape", "coords", "href", "alt"],
  801. article: [],
  802. aside: [],
  803. audio: [
  804. "autoplay",
  805. "controls",
  806. "crossorigin",
  807. "loop",
  808. "muted",
  809. "preload",
  810. "src",
  811. ],
  812. b: [],
  813. bdi: ["dir"],
  814. bdo: ["dir"],
  815. big: [],
  816. blockquote: ["cite"],
  817. br: [],
  818. caption: [],
  819. center: [],
  820. cite: [],
  821. code: [],
  822. col: ["align", "valign", "span", "width"],
  823. colgroup: ["align", "valign", "span", "width"],
  824. dd: [],
  825. del: ["datetime"],
  826. details: ["open"],
  827. div: [],
  828. dl: [],
  829. dt: [],
  830. em: [],
  831. figcaption: [],
  832. figure: [],
  833. font: ["color", "size", "face"],
  834. footer: [],
  835. h1: [],
  836. h2: [],
  837. h3: [],
  838. h4: [],
  839. h5: [],
  840. h6: [],
  841. header: [],
  842. hr: [],
  843. i: [],
  844. img: ["src", "alt", "title", "width", "height"],
  845. ins: ["datetime"],
  846. li: [],
  847. mark: [],
  848. nav: [],
  849. ol: [],
  850. p: [],
  851. pre: [],
  852. s: [],
  853. section: [],
  854. small: [],
  855. span: [],
  856. sub: [],
  857. summary: [],
  858. sup: [],
  859. strong: [],
  860. strike: [],
  861. table: ["width", "border", "align", "valign"],
  862. tbody: ["align", "valign"],
  863. td: ["width", "rowspan", "colspan", "align", "valign"],
  864. tfoot: ["align", "valign"],
  865. th: ["width", "rowspan", "colspan", "align", "valign"],
  866. thead: ["align", "valign"],
  867. tr: ["rowspan", "align", "valign"],
  868. tt: [],
  869. u: [],
  870. ul: [],
  871. video: [
  872. "autoplay",
  873. "controls",
  874. "crossorigin",
  875. "loop",
  876. "muted",
  877. "playsinline",
  878. "poster",
  879. "preload",
  880. "src",
  881. "height",
  882. "width",
  883. ],
  884. };
  885. }
  886. var defaultCSSFilter = new FilterCSS$1();
  887. /**
  888. * default onTag function
  889. *
  890. * @param {String} tag
  891. * @param {String} html
  892. * @param {Object} options
  893. * @return {String}
  894. */
  895. function onTag(tag, html, options) {
  896. // do nothing
  897. }
  898. /**
  899. * default onIgnoreTag function
  900. *
  901. * @param {String} tag
  902. * @param {String} html
  903. * @param {Object} options
  904. * @return {String}
  905. */
  906. function onIgnoreTag(tag, html, options) {
  907. // do nothing
  908. }
  909. /**
  910. * default onTagAttr function
  911. *
  912. * @param {String} tag
  913. * @param {String} name
  914. * @param {String} value
  915. * @return {String}
  916. */
  917. function onTagAttr(tag, name, value) {
  918. // do nothing
  919. }
  920. /**
  921. * default onIgnoreTagAttr function
  922. *
  923. * @param {String} tag
  924. * @param {String} name
  925. * @param {String} value
  926. * @return {String}
  927. */
  928. function onIgnoreTagAttr(tag, name, value) {
  929. // do nothing
  930. }
  931. /**
  932. * default escapeHtml function
  933. *
  934. * @param {String} html
  935. */
  936. function escapeHtml(html) {
  937. return html.replace(REGEXP_LT, "&lt;").replace(REGEXP_GT, "&gt;");
  938. }
  939. /**
  940. * default safeAttrValue function
  941. *
  942. * @param {String} tag
  943. * @param {String} name
  944. * @param {String} value
  945. * @param {Object} cssFilter
  946. * @return {String}
  947. */
  948. function safeAttrValue(tag, name, value, cssFilter) {
  949. // unescape attribute value firstly
  950. value = friendlyAttrValue(value);
  951. if (name === "href" || name === "src") {
  952. // filter `href` and `src` attribute
  953. // only allow the value that starts with `http://` | `https://` | `mailto:` | `/` | `#`
  954. value = _$2.trim(value);
  955. if (value === "#") return "#";
  956. if (
  957. !(
  958. value.substr(0, 7) === "http://" ||
  959. value.substr(0, 8) === "https://" ||
  960. value.substr(0, 7) === "mailto:" ||
  961. value.substr(0, 4) === "tel:" ||
  962. value.substr(0, 11) === "data:image/" ||
  963. value.substr(0, 6) === "ftp://" ||
  964. value.substr(0, 2) === "./" ||
  965. value.substr(0, 3) === "../" ||
  966. value[0] === "#" ||
  967. value[0] === "/"
  968. )
  969. ) {
  970. return "";
  971. }
  972. } else if (name === "background") {
  973. // filter `background` attribute (maybe no use)
  974. // `javascript:`
  975. REGEXP_DEFAULT_ON_TAG_ATTR_4.lastIndex = 0;
  976. if (REGEXP_DEFAULT_ON_TAG_ATTR_4.test(value)) {
  977. return "";
  978. }
  979. } else if (name === "style") {
  980. // `expression()`
  981. REGEXP_DEFAULT_ON_TAG_ATTR_7.lastIndex = 0;
  982. if (REGEXP_DEFAULT_ON_TAG_ATTR_7.test(value)) {
  983. return "";
  984. }
  985. // `url()`
  986. REGEXP_DEFAULT_ON_TAG_ATTR_8.lastIndex = 0;
  987. if (REGEXP_DEFAULT_ON_TAG_ATTR_8.test(value)) {
  988. REGEXP_DEFAULT_ON_TAG_ATTR_4.lastIndex = 0;
  989. if (REGEXP_DEFAULT_ON_TAG_ATTR_4.test(value)) {
  990. return "";
  991. }
  992. }
  993. if (cssFilter !== false) {
  994. cssFilter = cssFilter || defaultCSSFilter;
  995. value = cssFilter.process(value);
  996. }
  997. }
  998. // escape `<>"` before returns
  999. value = escapeAttrValue(value);
  1000. return value;
  1001. }
  1002. // RegExp list
  1003. var REGEXP_LT = /</g;
  1004. var REGEXP_GT = />/g;
  1005. var REGEXP_QUOTE = /"/g;
  1006. var REGEXP_QUOTE_2 = /&quot;/g;
  1007. var REGEXP_ATTR_VALUE_1 = /&#([a-zA-Z0-9]*);?/gim;
  1008. var REGEXP_ATTR_VALUE_COLON = /&colon;?/gim;
  1009. var REGEXP_ATTR_VALUE_NEWLINE = /&newline;?/gim;
  1010. var REGEXP_DEFAULT_ON_TAG_ATTR_4 =
  1011. /((j\s*a\s*v\s*a|v\s*b|l\s*i\s*v\s*e)\s*s\s*c\s*r\s*i\s*p\s*t\s*|m\s*o\s*c\s*h\s*a)\:/gi;
  1012. var REGEXP_DEFAULT_ON_TAG_ATTR_7 =
  1013. /e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*\(.*/gi;
  1014. var REGEXP_DEFAULT_ON_TAG_ATTR_8 = /u\s*r\s*l\s*\(.*/gi;
  1015. /**
  1016. * escape double quote
  1017. *
  1018. * @param {String} str
  1019. * @return {String} str
  1020. */
  1021. function escapeQuote(str) {
  1022. return str.replace(REGEXP_QUOTE, "&quot;");
  1023. }
  1024. /**
  1025. * unescape double quote
  1026. *
  1027. * @param {String} str
  1028. * @return {String} str
  1029. */
  1030. function unescapeQuote(str) {
  1031. return str.replace(REGEXP_QUOTE_2, '"');
  1032. }
  1033. /**
  1034. * escape html entities
  1035. *
  1036. * @param {String} str
  1037. * @return {String}
  1038. */
  1039. function escapeHtmlEntities(str) {
  1040. return str.replace(REGEXP_ATTR_VALUE_1, function replaceUnicode(str, code) {
  1041. return code[0] === "x" || code[0] === "X"
  1042. ? String.fromCharCode(parseInt(code.substr(1), 16))
  1043. : String.fromCharCode(parseInt(code, 10));
  1044. });
  1045. }
  1046. /**
  1047. * escape html5 new danger entities
  1048. *
  1049. * @param {String} str
  1050. * @return {String}
  1051. */
  1052. function escapeDangerHtml5Entities(str) {
  1053. return str
  1054. .replace(REGEXP_ATTR_VALUE_COLON, ":")
  1055. .replace(REGEXP_ATTR_VALUE_NEWLINE, " ");
  1056. }
  1057. /**
  1058. * clear nonprintable characters
  1059. *
  1060. * @param {String} str
  1061. * @return {String}
  1062. */
  1063. function clearNonPrintableCharacter(str) {
  1064. var str2 = "";
  1065. for (var i = 0, len = str.length; i < len; i++) {
  1066. str2 += str.charCodeAt(i) < 32 ? " " : str.charAt(i);
  1067. }
  1068. return _$2.trim(str2);
  1069. }
  1070. /**
  1071. * get friendly attribute value
  1072. *
  1073. * @param {String} str
  1074. * @return {String}
  1075. */
  1076. function friendlyAttrValue(str) {
  1077. str = unescapeQuote(str);
  1078. str = escapeHtmlEntities(str);
  1079. str = escapeDangerHtml5Entities(str);
  1080. str = clearNonPrintableCharacter(str);
  1081. return str;
  1082. }
  1083. /**
  1084. * unescape attribute value
  1085. *
  1086. * @param {String} str
  1087. * @return {String}
  1088. */
  1089. function escapeAttrValue(str) {
  1090. str = escapeQuote(str);
  1091. str = escapeHtml(str);
  1092. return str;
  1093. }
  1094. /**
  1095. * `onIgnoreTag` function for removing all the tags that are not in whitelist
  1096. */
  1097. function onIgnoreTagStripAll() {
  1098. return "";
  1099. }
  1100. /**
  1101. * remove tag body
  1102. * specify a `tags` list, if the tag is not in the `tags` list then process by the specify function (optional)
  1103. *
  1104. * @param {array} tags
  1105. * @param {function} next
  1106. */
  1107. function StripTagBody(tags, next) {
  1108. if (typeof next !== "function") {
  1109. next = function () {};
  1110. }
  1111. var isRemoveAllTag = !Array.isArray(tags);
  1112. function isRemoveTag(tag) {
  1113. if (isRemoveAllTag) return true;
  1114. return _$2.indexOf(tags, tag) !== -1;
  1115. }
  1116. var removeList = [];
  1117. var posStart = false;
  1118. return {
  1119. onIgnoreTag: function (tag, html, options) {
  1120. if (isRemoveTag(tag)) {
  1121. if (options.isClosing) {
  1122. var ret = "[/removed]";
  1123. var end = options.position + ret.length;
  1124. removeList.push([
  1125. posStart !== false ? posStart : options.position,
  1126. end,
  1127. ]);
  1128. posStart = false;
  1129. return ret;
  1130. } else {
  1131. if (!posStart) {
  1132. posStart = options.position;
  1133. }
  1134. return "[removed]";
  1135. }
  1136. } else {
  1137. return next(tag, html, options);
  1138. }
  1139. },
  1140. remove: function (html) {
  1141. var rethtml = "";
  1142. var lastPos = 0;
  1143. _$2.forEach(removeList, function (pos) {
  1144. rethtml += html.slice(lastPos, pos[0]);
  1145. lastPos = pos[1];
  1146. });
  1147. rethtml += html.slice(lastPos);
  1148. return rethtml;
  1149. },
  1150. };
  1151. }
  1152. /**
  1153. * remove html comments
  1154. *
  1155. * @param {String} html
  1156. * @return {String}
  1157. */
  1158. function stripCommentTag(html) {
  1159. var retHtml = "";
  1160. var lastPos = 0;
  1161. while (lastPos < html.length) {
  1162. var i = html.indexOf("<!--", lastPos);
  1163. if (i === -1) {
  1164. retHtml += html.slice(lastPos);
  1165. break;
  1166. }
  1167. retHtml += html.slice(lastPos, i);
  1168. var j = html.indexOf("-->", i);
  1169. if (j === -1) {
  1170. break;
  1171. }
  1172. lastPos = j + 3;
  1173. }
  1174. return retHtml;
  1175. }
  1176. /**
  1177. * remove invisible characters
  1178. *
  1179. * @param {String} html
  1180. * @return {String}
  1181. */
  1182. function stripBlankChar(html) {
  1183. var chars = html.split("");
  1184. chars = chars.filter(function (char) {
  1185. var c = char.charCodeAt(0);
  1186. if (c === 127) return false;
  1187. if (c <= 31) {
  1188. if (c === 10 || c === 13) return true;
  1189. return false;
  1190. }
  1191. return true;
  1192. });
  1193. return chars.join("");
  1194. }
  1195. _default$1.whiteList = getDefaultWhiteList();
  1196. _default$1.getDefaultWhiteList = getDefaultWhiteList;
  1197. _default$1.onTag = onTag;
  1198. _default$1.onIgnoreTag = onIgnoreTag;
  1199. _default$1.onTagAttr = onTagAttr;
  1200. _default$1.onIgnoreTagAttr = onIgnoreTagAttr;
  1201. _default$1.safeAttrValue = safeAttrValue;
  1202. _default$1.escapeHtml = escapeHtml;
  1203. _default$1.escapeQuote = escapeQuote;
  1204. _default$1.unescapeQuote = unescapeQuote;
  1205. _default$1.escapeHtmlEntities = escapeHtmlEntities;
  1206. _default$1.escapeDangerHtml5Entities = escapeDangerHtml5Entities;
  1207. _default$1.clearNonPrintableCharacter = clearNonPrintableCharacter;
  1208. _default$1.friendlyAttrValue = friendlyAttrValue;
  1209. _default$1.escapeAttrValue = escapeAttrValue;
  1210. _default$1.onIgnoreTagStripAll = onIgnoreTagStripAll;
  1211. _default$1.StripTagBody = StripTagBody;
  1212. _default$1.stripCommentTag = stripCommentTag;
  1213. _default$1.stripBlankChar = stripBlankChar;
  1214. _default$1.cssFilter = defaultCSSFilter;
  1215. _default$1.getDefaultCSSWhiteList = getDefaultCSSWhiteList;
  1216. var parser$1 = {};
  1217. /**
  1218. * Simple HTML Parser
  1219. *
  1220. * @author Zongmin Lei<leizongmin@gmail.com>
  1221. */
  1222. var _$1 = util;
  1223. /**
  1224. * get tag name
  1225. *
  1226. * @param {String} html e.g. '<a hef="#">'
  1227. * @return {String}
  1228. */
  1229. function getTagName(html) {
  1230. var i = _$1.spaceIndex(html);
  1231. if (i === -1) {
  1232. var tagName = html.slice(1, -1);
  1233. } else {
  1234. var tagName = html.slice(1, i + 1);
  1235. }
  1236. tagName = _$1.trim(tagName).toLowerCase();
  1237. if (tagName.slice(0, 1) === "/") tagName = tagName.slice(1);
  1238. if (tagName.slice(-1) === "/") tagName = tagName.slice(0, -1);
  1239. return tagName;
  1240. }
  1241. /**
  1242. * is close tag?
  1243. *
  1244. * @param {String} html 如:'<a hef="#">'
  1245. * @return {Boolean}
  1246. */
  1247. function isClosing(html) {
  1248. return html.slice(0, 2) === "</";
  1249. }
  1250. /**
  1251. * parse input html and returns processed html
  1252. *
  1253. * @param {String} html
  1254. * @param {Function} onTag e.g. function (sourcePosition, position, tag, html, isClosing)
  1255. * @param {Function} escapeHtml
  1256. * @return {String}
  1257. */
  1258. function parseTag$1(html, onTag, escapeHtml) {
  1259. var rethtml = "";
  1260. var lastPos = 0;
  1261. var tagStart = false;
  1262. var quoteStart = false;
  1263. var currentPos = 0;
  1264. var len = html.length;
  1265. var currentTagName = "";
  1266. var currentHtml = "";
  1267. chariterator: for (currentPos = 0; currentPos < len; currentPos++) {
  1268. var c = html.charAt(currentPos);
  1269. if (tagStart === false) {
  1270. if (c === "<") {
  1271. tagStart = currentPos;
  1272. continue;
  1273. }
  1274. } else {
  1275. if (quoteStart === false) {
  1276. if (c === "<") {
  1277. rethtml += escapeHtml(html.slice(lastPos, currentPos));
  1278. tagStart = currentPos;
  1279. lastPos = currentPos;
  1280. continue;
  1281. }
  1282. if (c === ">") {
  1283. rethtml += escapeHtml(html.slice(lastPos, tagStart));
  1284. currentHtml = html.slice(tagStart, currentPos + 1);
  1285. currentTagName = getTagName(currentHtml);
  1286. rethtml += onTag(
  1287. tagStart,
  1288. rethtml.length,
  1289. currentTagName,
  1290. currentHtml,
  1291. isClosing(currentHtml)
  1292. );
  1293. lastPos = currentPos + 1;
  1294. tagStart = false;
  1295. continue;
  1296. }
  1297. if (c === '"' || c === "'") {
  1298. var i = 1;
  1299. var ic = html.charAt(currentPos - i);
  1300. while (ic.trim() === "" || ic === "=") {
  1301. if (ic === "=") {
  1302. quoteStart = c;
  1303. continue chariterator;
  1304. }
  1305. ic = html.charAt(currentPos - ++i);
  1306. }
  1307. }
  1308. } else {
  1309. if (c === quoteStart) {
  1310. quoteStart = false;
  1311. continue;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. if (lastPos < html.length) {
  1317. rethtml += escapeHtml(html.substr(lastPos));
  1318. }
  1319. return rethtml;
  1320. }
  1321. var REGEXP_ILLEGAL_ATTR_NAME = /[^a-zA-Z0-9_:\.\-]/gim;
  1322. /**
  1323. * parse input attributes and returns processed attributes
  1324. *
  1325. * @param {String} html e.g. `href="#" target="_blank"`
  1326. * @param {Function} onAttr e.g. `function (name, value)`
  1327. * @return {String}
  1328. */
  1329. function parseAttr$1(html, onAttr) {
  1330. var lastPos = 0;
  1331. var retAttrs = [];
  1332. var tmpName = false;
  1333. var len = html.length;
  1334. function addAttr(name, value) {
  1335. name = _$1.trim(name);
  1336. name = name.replace(REGEXP_ILLEGAL_ATTR_NAME, "").toLowerCase();
  1337. if (name.length < 1) return;
  1338. var ret = onAttr(name, value || "");
  1339. if (ret) retAttrs.push(ret);
  1340. }
  1341. // 逐个分析字符
  1342. for (var i = 0; i < len; i++) {
  1343. var c = html.charAt(i);
  1344. var v, j;
  1345. if (tmpName === false && c === "=") {
  1346. tmpName = html.slice(lastPos, i);
  1347. lastPos = i + 1;
  1348. continue;
  1349. }
  1350. if (tmpName !== false) {
  1351. if (
  1352. i === lastPos &&
  1353. (c === '"' || c === "'") &&
  1354. html.charAt(i - 1) === "="
  1355. ) {
  1356. j = html.indexOf(c, i + 1);
  1357. if (j === -1) {
  1358. break;
  1359. } else {
  1360. v = _$1.trim(html.slice(lastPos + 1, j));
  1361. addAttr(tmpName, v);
  1362. tmpName = false;
  1363. i = j;
  1364. lastPos = i + 1;
  1365. continue;
  1366. }
  1367. }
  1368. }
  1369. if (/\s|\n|\t/.test(c)) {
  1370. html = html.replace(/\s|\n|\t/g, " ");
  1371. if (tmpName === false) {
  1372. j = findNextEqual(html, i);
  1373. if (j === -1) {
  1374. v = _$1.trim(html.slice(lastPos, i));
  1375. addAttr(v);
  1376. tmpName = false;
  1377. lastPos = i + 1;
  1378. continue;
  1379. } else {
  1380. i = j - 1;
  1381. continue;
  1382. }
  1383. } else {
  1384. j = findBeforeEqual(html, i - 1);
  1385. if (j === -1) {
  1386. v = _$1.trim(html.slice(lastPos, i));
  1387. v = stripQuoteWrap(v);
  1388. addAttr(tmpName, v);
  1389. tmpName = false;
  1390. lastPos = i + 1;
  1391. continue;
  1392. } else {
  1393. continue;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. if (lastPos < html.length) {
  1399. if (tmpName === false) {
  1400. addAttr(html.slice(lastPos));
  1401. } else {
  1402. addAttr(tmpName, stripQuoteWrap(_$1.trim(html.slice(lastPos))));
  1403. }
  1404. }
  1405. return _$1.trim(retAttrs.join(" "));
  1406. }
  1407. function findNextEqual(str, i) {
  1408. for (; i < str.length; i++) {
  1409. var c = str[i];
  1410. if (c === " ") continue;
  1411. if (c === "=") return i;
  1412. return -1;
  1413. }
  1414. }
  1415. function findBeforeEqual(str, i) {
  1416. for (; i > 0; i--) {
  1417. var c = str[i];
  1418. if (c === " ") continue;
  1419. if (c === "=") return i;
  1420. return -1;
  1421. }
  1422. }
  1423. function isQuoteWrapString(text) {
  1424. if (
  1425. (text[0] === '"' && text[text.length - 1] === '"') ||
  1426. (text[0] === "'" && text[text.length - 1] === "'")
  1427. ) {
  1428. return true;
  1429. } else {
  1430. return false;
  1431. }
  1432. }
  1433. function stripQuoteWrap(text) {
  1434. if (isQuoteWrapString(text)) {
  1435. return text.substr(1, text.length - 2);
  1436. } else {
  1437. return text;
  1438. }
  1439. }
  1440. parser$1.parseTag = parseTag$1;
  1441. parser$1.parseAttr = parseAttr$1;
  1442. /**
  1443. * filter xss
  1444. *
  1445. * @author Zongmin Lei<leizongmin@gmail.com>
  1446. */
  1447. var FilterCSS = lib.exports.FilterCSS;
  1448. var DEFAULT = _default$1;
  1449. var parser = parser$1;
  1450. var parseTag = parser.parseTag;
  1451. var parseAttr = parser.parseAttr;
  1452. var _ = util;
  1453. /**
  1454. * returns `true` if the input value is `undefined` or `null`
  1455. *
  1456. * @param {Object} obj
  1457. * @return {Boolean}
  1458. */
  1459. function isNull(obj) {
  1460. return obj === undefined || obj === null;
  1461. }
  1462. /**
  1463. * get attributes for a tag
  1464. *
  1465. * @param {String} html
  1466. * @return {Object}
  1467. * - {String} html
  1468. * - {Boolean} closing
  1469. */
  1470. function getAttrs(html) {
  1471. var i = _.spaceIndex(html);
  1472. if (i === -1) {
  1473. return {
  1474. html: "",
  1475. closing: html[html.length - 2] === "/",
  1476. };
  1477. }
  1478. html = _.trim(html.slice(i + 1, -1));
  1479. var isClosing = html[html.length - 1] === "/";
  1480. if (isClosing) html = _.trim(html.slice(0, -1));
  1481. return {
  1482. html: html,
  1483. closing: isClosing,
  1484. };
  1485. }
  1486. /**
  1487. * shallow copy
  1488. *
  1489. * @param {Object} obj
  1490. * @return {Object}
  1491. */
  1492. function shallowCopyObject(obj) {
  1493. var ret = {};
  1494. for (var i in obj) {
  1495. ret[i] = obj[i];
  1496. }
  1497. return ret;
  1498. }
  1499. /**
  1500. * FilterXSS class
  1501. *
  1502. * @param {Object} options
  1503. * whiteList (or allowList), onTag, onTagAttr, onIgnoreTag,
  1504. * onIgnoreTagAttr, safeAttrValue, escapeHtml
  1505. * stripIgnoreTagBody, allowCommentTag, stripBlankChar
  1506. * css{whiteList, onAttr, onIgnoreAttr} `css=false` means don't use `cssfilter`
  1507. */
  1508. function FilterXSS(options) {
  1509. options = shallowCopyObject(options || {});
  1510. if (options.stripIgnoreTag) {
  1511. if (options.onIgnoreTag) {
  1512. console.error(
  1513. 'Notes: cannot use these two options "stripIgnoreTag" and "onIgnoreTag" at the same time'
  1514. );
  1515. }
  1516. options.onIgnoreTag = DEFAULT.onIgnoreTagStripAll;
  1517. }
  1518. options.whiteList = options.whiteList || options.allowList || DEFAULT.whiteList;
  1519. options.onTag = options.onTag || DEFAULT.onTag;
  1520. options.onTagAttr = options.onTagAttr || DEFAULT.onTagAttr;
  1521. options.onIgnoreTag = options.onIgnoreTag || DEFAULT.onIgnoreTag;
  1522. options.onIgnoreTagAttr = options.onIgnoreTagAttr || DEFAULT.onIgnoreTagAttr;
  1523. options.safeAttrValue = options.safeAttrValue || DEFAULT.safeAttrValue;
  1524. options.escapeHtml = options.escapeHtml || DEFAULT.escapeHtml;
  1525. this.options = options;
  1526. if (options.css === false) {
  1527. this.cssFilter = false;
  1528. } else {
  1529. options.css = options.css || {};
  1530. this.cssFilter = new FilterCSS(options.css);
  1531. }
  1532. }
  1533. /**
  1534. * start process and returns result
  1535. *
  1536. * @param {String} html
  1537. * @return {String}
  1538. */
  1539. FilterXSS.prototype.process = function (html) {
  1540. // compatible with the input
  1541. html = html || "";
  1542. html = html.toString();
  1543. if (!html) return "";
  1544. var me = this;
  1545. var options = me.options;
  1546. var whiteList = options.whiteList;
  1547. var onTag = options.onTag;
  1548. var onIgnoreTag = options.onIgnoreTag;
  1549. var onTagAttr = options.onTagAttr;
  1550. var onIgnoreTagAttr = options.onIgnoreTagAttr;
  1551. var safeAttrValue = options.safeAttrValue;
  1552. var escapeHtml = options.escapeHtml;
  1553. var cssFilter = me.cssFilter;
  1554. // remove invisible characters
  1555. if (options.stripBlankChar) {
  1556. html = DEFAULT.stripBlankChar(html);
  1557. }
  1558. // remove html comments
  1559. if (!options.allowCommentTag) {
  1560. html = DEFAULT.stripCommentTag(html);
  1561. }
  1562. // if enable stripIgnoreTagBody
  1563. var stripIgnoreTagBody = false;
  1564. if (options.stripIgnoreTagBody) {
  1565. var stripIgnoreTagBody = DEFAULT.StripTagBody(
  1566. options.stripIgnoreTagBody,
  1567. onIgnoreTag
  1568. );
  1569. onIgnoreTag = stripIgnoreTagBody.onIgnoreTag;
  1570. }
  1571. var retHtml = parseTag(
  1572. html,
  1573. function (sourcePosition, position, tag, html, isClosing) {
  1574. var info = {
  1575. sourcePosition: sourcePosition,
  1576. position: position,
  1577. isClosing: isClosing,
  1578. isWhite: whiteList.hasOwnProperty(tag),
  1579. };
  1580. // call `onTag()`
  1581. var ret = onTag(tag, html, info);
  1582. if (!isNull(ret)) return ret;
  1583. if (info.isWhite) {
  1584. if (info.isClosing) {
  1585. return "</" + tag + ">";
  1586. }
  1587. var attrs = getAttrs(html);
  1588. var whiteAttrList = whiteList[tag];
  1589. var attrsHtml = parseAttr(attrs.html, function (name, value) {
  1590. // call `onTagAttr()`
  1591. var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1;
  1592. var ret = onTagAttr(tag, name, value, isWhiteAttr);
  1593. if (!isNull(ret)) return ret;
  1594. if (isWhiteAttr) {
  1595. // call `safeAttrValue()`
  1596. value = safeAttrValue(tag, name, value, cssFilter);
  1597. if (value) {
  1598. return name + '="' + value + '"';
  1599. } else {
  1600. return name;
  1601. }
  1602. } else {
  1603. // call `onIgnoreTagAttr()`
  1604. var ret = onIgnoreTagAttr(tag, name, value, isWhiteAttr);
  1605. if (!isNull(ret)) return ret;
  1606. return;
  1607. }
  1608. });
  1609. // build new tag html
  1610. var html = "<" + tag;
  1611. if (attrsHtml) html += " " + attrsHtml;
  1612. if (attrs.closing) html += " /";
  1613. html += ">";
  1614. return html;
  1615. } else {
  1616. // call `onIgnoreTag()`
  1617. var ret = onIgnoreTag(tag, html, info);
  1618. if (!isNull(ret)) return ret;
  1619. return escapeHtml(html);
  1620. }
  1621. },
  1622. escapeHtml
  1623. );
  1624. // if enable stripIgnoreTagBody
  1625. if (stripIgnoreTagBody) {
  1626. retHtml = stripIgnoreTagBody.remove(retHtml);
  1627. }
  1628. return retHtml;
  1629. };
  1630. var xss = FilterXSS;
  1631. /**
  1632. * xss
  1633. *
  1634. * @author Zongmin Lei<leizongmin@gmail.com>
  1635. */
  1636. (function (module, exports) {
  1637. var DEFAULT = _default$1;
  1638. var parser = parser$1;
  1639. var FilterXSS = xss;
  1640. /**
  1641. * filter xss function
  1642. *
  1643. * @param {String} html
  1644. * @param {Object} options { whiteList, onTag, onTagAttr, onIgnoreTag, onIgnoreTagAttr, safeAttrValue, escapeHtml }
  1645. * @return {String}
  1646. */
  1647. function filterXSS(html, options) {
  1648. var xss = new FilterXSS(options);
  1649. return xss.process(html);
  1650. }
  1651. exports = module.exports = filterXSS;
  1652. exports.filterXSS = filterXSS;
  1653. exports.FilterXSS = FilterXSS;
  1654. for (var i in DEFAULT) exports[i] = DEFAULT[i];
  1655. for (var i in parser) exports[i] = parser[i];
  1656. // using `xss` on the WebWorker, output `filterXSS` to the globals
  1657. function isWorkerEnv() {
  1658. return (
  1659. typeof self !== "undefined" &&
  1660. typeof DedicatedWorkerGlobalScope !== "undefined" &&
  1661. self instanceof DedicatedWorkerGlobalScope
  1662. );
  1663. }
  1664. if (isWorkerEnv()) {
  1665. self.filterXSS = module.exports;
  1666. }
  1667. }(lib$1, lib$1.exports));
  1668. /* Copyright (c) 2020 Environmental Systems Research Institute, Inc.
  1669. * Apache-2.0
  1670. *
  1671. * js-xss
  1672. * Copyright (c) 2012-2018 Zongmin Lei(雷宗民) <leizongmin@gmail.com>
  1673. * http://ucdok.com
  1674. * The MIT License, see
  1675. * https://github.com/leizongmin/js-xss/blob/master/LICENSE for details
  1676. *
  1677. * Lodash/isPlainObject
  1678. * Copyright (c) JS Foundation and other contributors <https://js.foundation/>
  1679. * MIT License, see https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/LICENSE for details
  1680. * */
  1681. /**
  1682. * The Sanitizer Class
  1683. *
  1684. * @export
  1685. * @class Sanitizer
  1686. */
  1687. var Sanitizer = /** @class */ (function () {
  1688. function Sanitizer(filterOptions, extendDefaults) {
  1689. var _this = this;
  1690. // Supported HTML Spec: https://doc.arcgis.com/en/arcgis-online/reference/supported-html.htm
  1691. this.arcgisWhiteList = {
  1692. a: ["href", "style", "target"],
  1693. abbr: ["title"],
  1694. audio: ["autoplay", "controls", "loop", "muted", "preload"],
  1695. b: [],
  1696. br: [],
  1697. dd: ["style"],
  1698. div: ["align", "style"],
  1699. dl: ["style"],
  1700. dt: ["style"],
  1701. em: [],
  1702. figcaption: ["style"],
  1703. figure: ["style"],
  1704. font: ["color", "face", "size", "style"],
  1705. h1: ["style"],
  1706. h2: ["style"],
  1707. h3: ["style"],
  1708. h4: ["style"],
  1709. h5: ["style"],
  1710. h6: ["style"],
  1711. hr: [],
  1712. i: [],
  1713. img: ["alt", "border", "height", "src", "style", "width"],
  1714. li: [],
  1715. ol: [],
  1716. p: ["style"],
  1717. source: ["media", "src", "type"],
  1718. span: ["style"],
  1719. strong: [],
  1720. sub: ["style"],
  1721. sup: ["style"],
  1722. table: ["border", "cellpadding", "cellspacing", "height", "style", "width"],
  1723. tbody: [],
  1724. tr: ["align", "height", "style", "valign"],
  1725. td: [
  1726. "align",
  1727. "colspan",
  1728. "height",
  1729. "nowrap",
  1730. "rowspan",
  1731. "style",
  1732. "valign",
  1733. "width"
  1734. ],
  1735. th: [
  1736. "align",
  1737. "colspan",
  1738. "height",
  1739. "nowrap",
  1740. "rowspan",
  1741. "style",
  1742. "valign",
  1743. "width"
  1744. ],
  1745. u: [],
  1746. ul: [],
  1747. video: [
  1748. "autoplay",
  1749. "controls",
  1750. "height",
  1751. "loop",
  1752. "muted",
  1753. "poster",
  1754. "preload",
  1755. "width"
  1756. ]
  1757. };
  1758. this.allowedProtocols = [
  1759. "http",
  1760. "https",
  1761. "mailto",
  1762. "iform",
  1763. "tel",
  1764. "flow",
  1765. "lfmobile",
  1766. "arcgis-navigator",
  1767. "arcgis-appstudio-player",
  1768. "arcgis-survey123",
  1769. "arcgis-collector",
  1770. "arcgis-workforce",
  1771. "arcgis-explorer",
  1772. "arcgis-trek2there",
  1773. "arcgis-quickcapture",
  1774. "mspbi",
  1775. "comgooglemaps",
  1776. "pdfefile",
  1777. "pdfehttp",
  1778. "pdfehttps",
  1779. "boxapp",
  1780. "boxemm",
  1781. "awb",
  1782. "awbs",
  1783. "gropen",
  1784. "radarscope"
  1785. ];
  1786. this.arcgisFilterOptions = {
  1787. allowCommentTag: true,
  1788. safeAttrValue: function (tag, name, value, cssFilter) {
  1789. // Take over safe attribute filtering for `a` `href`, `img` `src`,
  1790. // and `source` `src` attributes, otherwise pass onto the
  1791. // default `XSS.safeAttrValue` method.
  1792. if ((tag === "a" && name === "href") ||
  1793. ((tag === "img" || tag === "source") && name === "src")) {
  1794. return _this.sanitizeUrl(value);
  1795. }
  1796. return lib$1.exports.safeAttrValue(tag, name, value, cssFilter);
  1797. }
  1798. };
  1799. var xssFilterOptions;
  1800. if (filterOptions && !extendDefaults) {
  1801. // Override the defaults
  1802. xssFilterOptions = filterOptions;
  1803. }
  1804. else if (filterOptions && extendDefaults) {
  1805. // Extend the defaults
  1806. xssFilterOptions = Object.create(this.arcgisFilterOptions);
  1807. Object.keys(filterOptions).forEach(function (key) {
  1808. if (key === "whiteList") {
  1809. // Extend the whitelist by concatenating arrays
  1810. xssFilterOptions.whiteList = _this._extendObjectOfArrays([
  1811. _this.arcgisWhiteList,
  1812. filterOptions.whiteList || {}
  1813. ]);
  1814. }
  1815. else {
  1816. xssFilterOptions[key] = filterOptions[key];
  1817. }
  1818. });
  1819. }
  1820. else {
  1821. // Only use the defaults
  1822. xssFilterOptions = Object.create(this.arcgisFilterOptions);
  1823. xssFilterOptions.whiteList = this.arcgisWhiteList;
  1824. }
  1825. this.xssFilterOptions = xssFilterOptions;
  1826. // Make this readable to tests
  1827. this._xssFilter = new lib$1.exports.FilterXSS(xssFilterOptions);
  1828. }
  1829. /**
  1830. * Sanitizes value to remove invalid HTML tags.
  1831. *
  1832. * Note: If the value passed does not contain a valid JSON data type (String,
  1833. * Number, JSON Object, Array, Boolean, or null), the value will be nullified.
  1834. *
  1835. * @param {any} value The value to sanitize.
  1836. * @returns {any} The sanitized value.
  1837. * @memberof Sanitizer
  1838. */
  1839. Sanitizer.prototype.sanitize = function (value, options) {
  1840. if (options === void 0) { options = {}; }
  1841. switch (typeof value) {
  1842. case "number":
  1843. if (isNaN(value) || !isFinite(value)) {
  1844. return null;
  1845. }
  1846. return value;
  1847. case "boolean":
  1848. return value;
  1849. case "string":
  1850. return this._xssFilter.process(value);
  1851. case "object":
  1852. return this._iterateOverObject(value, options);
  1853. default:
  1854. if (options.allowUndefined && typeof value === "undefined") {
  1855. return;
  1856. }
  1857. return null;
  1858. }
  1859. };
  1860. /**
  1861. * Sanitizes a URL string following the allowed protocols and sanitization rules.
  1862. *
  1863. * @param {string} value The URL to sanitize.
  1864. * @param {{ isProtocolRequired: boolean }} options Configuration options for URL checking.
  1865. * @returns {string} The sanitized URL if it's valid, or an empty string if the URL is invalid.
  1866. */
  1867. Sanitizer.prototype.sanitizeUrl = function (value, options) {
  1868. var _a = (options !== null && options !== void 0 ? options : {}).isProtocolRequired, isProtocolRequired = _a === void 0 ? true : _a;
  1869. var protocol = this._trim(value.substring(0, value.indexOf(":")));
  1870. var isRootUrl = value === '/';
  1871. var isUrlFragment = /^#/.test(value);
  1872. var isValidProtocol = protocol && this.allowedProtocols.indexOf(protocol.toLowerCase()) > -1;
  1873. if (isRootUrl || isUrlFragment || isValidProtocol) {
  1874. return lib$1.exports.escapeAttrValue(value);
  1875. }
  1876. if (!protocol && !isProtocolRequired) {
  1877. return lib$1.exports.escapeAttrValue("https://".concat(value));
  1878. }
  1879. return "";
  1880. };
  1881. /**
  1882. * Sanitizes an HTML attribute value.
  1883. *
  1884. * @param {string} tag The tagname of the HTML element.
  1885. * @param {string} attribute The attribute name of the HTML element.
  1886. * @param {string} value The raw value to be used for the HTML attribute value.
  1887. * @param {XSS.ICSSFilter} [cssFilter] The CSS filter to be used.
  1888. * @returns {string} The sanitized attribute value.
  1889. * @memberof Sanitizer
  1890. */
  1891. Sanitizer.prototype.sanitizeHTMLAttribute = function (tag, attribute, value, cssFilter) {
  1892. // use the custom safeAttrValue function if provided
  1893. if (typeof this.xssFilterOptions.safeAttrValue === 'function') {
  1894. // @ts-ignore safeAttrValue does handle undefined cssFilter
  1895. return this.xssFilterOptions.safeAttrValue(tag, attribute, value, cssFilter);
  1896. }
  1897. // otherwise use the default
  1898. // @ts-ignore safeAttrValue does handle undefined cssFilter
  1899. return lib$1.exports.safeAttrValue(tag, attribute, value, cssFilter);
  1900. };
  1901. /**
  1902. * Checks if a value only contains valid HTML.
  1903. *
  1904. * @param {any} value The value to validate.
  1905. * @returns {boolean}
  1906. * @memberof Sanitizer
  1907. */
  1908. Sanitizer.prototype.validate = function (value, options) {
  1909. if (options === void 0) { options = {}; }
  1910. var sanitized = this.sanitize(value, options);
  1911. return {
  1912. isValid: value === sanitized,
  1913. sanitized: sanitized
  1914. };
  1915. };
  1916. /**
  1917. * Extends an object of arrays by by concatenating arrays of the same object
  1918. * keys. If the if the previous key's value is not an array, the next key's
  1919. * value will replace the previous key. This method is used for extending the
  1920. * whiteList in the XSS filter options.
  1921. *
  1922. * @private
  1923. * @param {Array<{}>} objects An array of objects.
  1924. * @returns {{}} The extended object.
  1925. * @memberof Sanitizer
  1926. */
  1927. Sanitizer.prototype._extendObjectOfArrays = function (objects) {
  1928. var finalObj = {};
  1929. objects.forEach(function (obj) {
  1930. Object.keys(obj).forEach(function (key) {
  1931. if (Array.isArray(obj[key]) && Array.isArray(finalObj[key])) {
  1932. finalObj[key] = finalObj[key].concat(obj[key]);
  1933. }
  1934. else {
  1935. finalObj[key] = obj[key];
  1936. }
  1937. });
  1938. });
  1939. return finalObj;
  1940. };
  1941. /**
  1942. * Iterate over a plain object or array to deeply sanitize each value.
  1943. *
  1944. * @private
  1945. * @param {object} obj The object to iterate over.
  1946. * @returns {(object | null)} The sanitized object.
  1947. * @memberof Sanitizer
  1948. */
  1949. Sanitizer.prototype._iterateOverObject = function (obj, options) {
  1950. var _this = this;
  1951. if (options === void 0) { options = {}; }
  1952. try {
  1953. var hasChanged_1 = false;
  1954. var changedObj = void 0;
  1955. if (Array.isArray(obj)) {
  1956. changedObj = obj.reduce(function (prev, value) {
  1957. var validation = _this.validate(value, options);
  1958. if (validation.isValid) {
  1959. return prev.concat([value]);
  1960. }
  1961. else {
  1962. hasChanged_1 = true;
  1963. return prev.concat([validation.sanitized]);
  1964. }
  1965. }, []);
  1966. }
  1967. else if (!lodash_isplainobject(obj)) {
  1968. if (options.allowUndefined && typeof obj === "undefined") {
  1969. return;
  1970. }
  1971. return null;
  1972. }
  1973. else {
  1974. var keys = Object.keys(obj);
  1975. changedObj = keys.reduce(function (prev, key) {
  1976. var value = obj[key];
  1977. var validation = _this.validate(value, options);
  1978. if (validation.isValid) {
  1979. prev[key] = value;
  1980. }
  1981. else {
  1982. hasChanged_1 = true;
  1983. prev[key] = validation.sanitized;
  1984. }
  1985. return prev;
  1986. }, {});
  1987. }
  1988. if (hasChanged_1) {
  1989. return changedObj;
  1990. }
  1991. return obj;
  1992. }
  1993. catch (err) {
  1994. return null;
  1995. }
  1996. };
  1997. /**
  1998. * Trim whitespace from the start and ends of a string.
  1999. * @param {string} val The string to trim.
  2000. * @returns {string} The trimmed string.
  2001. */
  2002. Sanitizer.prototype._trim = function (val) {
  2003. // @ts-ignore This is used by Jest,
  2004. // but TypeScript errors since it assumes `trim` is always available.
  2005. return String.prototype.trim
  2006. ? val.trim()
  2007. : val.replace(/(^\s*)|(\s*$)/g, "");
  2008. };
  2009. return Sanitizer;
  2010. }());
  2011. return Sanitizer;
  2012. }));