index.js 65 KB

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