PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Symfony/Component/HtmlSanitizer/Reference/W3CReference.php

https://github.com/FabienD/symfony
PHP | 400 lines | 358 code | 7 blank | 35 comment | 0 complexity | fbe95fb96eb3087328f5c361ed421775 MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HtmlSanitizer\Reference;
  11. /**
  12. * Stores reference data from the W3C Sanitizer API standard.
  13. *
  14. * @see https://wicg.github.io/sanitizer-api/#default-configuration
  15. *
  16. * @author Titouan Galopin <galopintitouan@gmail.com>
  17. *
  18. * @internal
  19. */
  20. final class W3CReference
  21. {
  22. /**
  23. * Sanitizer supported contexts.
  24. *
  25. * A parent element name can be passed as an argument to {@see HtmlSanitizer::sanitizeFor()}.
  26. * When doing so, depending on the given context, different elements will be allowed.
  27. */
  28. public const CONTEXT_HEAD = 'head';
  29. public const CONTEXT_BODY = 'body';
  30. public const CONTEXT_TEXT = 'text';
  31. // Which context to apply depending on the passed parent element name
  32. public const CONTEXTS_MAP = [
  33. 'head' => self::CONTEXT_HEAD,
  34. 'textarea' => self::CONTEXT_TEXT,
  35. 'title' => self::CONTEXT_TEXT,
  36. ];
  37. /**
  38. * Elements allowed by the Sanitizer standard in <head> as keys, including whether
  39. * they are safe or not as values (safe meaning no global display/audio/video impact).
  40. */
  41. public const HEAD_ELEMENTS = [
  42. 'head' => true,
  43. 'link' => true,
  44. 'meta' => true,
  45. 'style' => false,
  46. 'title' => true,
  47. ];
  48. /**
  49. * Elements allowed by the Sanitizer standard in <body> as keys, including whether
  50. * they are safe or not as values (safe meaning no global display/audio/video impact).
  51. */
  52. public const BODY_ELEMENTS = [
  53. 'a' => true,
  54. 'abbr' => true,
  55. 'acronym' => true,
  56. 'address' => true,
  57. 'area' => true,
  58. 'article' => true,
  59. 'aside' => true,
  60. 'audio' => true,
  61. 'b' => true,
  62. 'basefont' => true,
  63. 'bdi' => true,
  64. 'bdo' => true,
  65. 'bgsound' => false,
  66. 'big' => true,
  67. 'blockquote' => true,
  68. 'body' => true,
  69. 'br' => true,
  70. 'button' => true,
  71. 'canvas' => true,
  72. 'caption' => true,
  73. 'center' => true,
  74. 'cite' => true,
  75. 'code' => true,
  76. 'col' => true,
  77. 'colgroup' => true,
  78. 'command' => true,
  79. 'data' => true,
  80. 'datalist' => true,
  81. 'dd' => true,
  82. 'del' => true,
  83. 'details' => true,
  84. 'dfn' => true,
  85. 'dialog' => true,
  86. 'dir' => true,
  87. 'div' => true,
  88. 'dl' => true,
  89. 'dt' => true,
  90. 'em' => true,
  91. 'fieldset' => true,
  92. 'figcaption' => true,
  93. 'figure' => true,
  94. 'font' => true,
  95. 'footer' => true,
  96. 'form' => false,
  97. 'h1' => true,
  98. 'h2' => true,
  99. 'h3' => true,
  100. 'h4' => true,
  101. 'h5' => true,
  102. 'h6' => true,
  103. 'header' => true,
  104. 'hgroup' => true,
  105. 'hr' => true,
  106. 'html' => true,
  107. 'i' => true,
  108. 'image' => true,
  109. 'img' => true,
  110. 'input' => false,
  111. 'ins' => true,
  112. 'kbd' => true,
  113. 'keygen' => true,
  114. 'label' => true,
  115. 'layer' => true,
  116. 'legend' => true,
  117. 'li' => true,
  118. 'listing' => true,
  119. 'main' => true,
  120. 'map' => true,
  121. 'mark' => true,
  122. 'marquee' => true,
  123. 'menu' => true,
  124. 'meter' => true,
  125. 'nav' => true,
  126. 'nobr' => true,
  127. 'ol' => true,
  128. 'optgroup' => true,
  129. 'option' => true,
  130. 'output' => true,
  131. 'p' => true,
  132. 'picture' => true,
  133. 'plaintext' => true,
  134. 'popup' => true,
  135. 'portal' => true,
  136. 'pre' => true,
  137. 'progress' => true,
  138. 'q' => true,
  139. 'rb' => true,
  140. 'rp' => true,
  141. 'rt' => true,
  142. 'rtc' => true,
  143. 'ruby' => true,
  144. 's' => true,
  145. 'samp' => true,
  146. 'section' => true,
  147. 'select' => false,
  148. 'selectmenu' => false,
  149. 'slot' => true,
  150. 'small' => true,
  151. 'source' => true,
  152. 'span' => true,
  153. 'strike' => true,
  154. 'strong' => true,
  155. 'sub' => true,
  156. 'summary' => true,
  157. 'sup' => true,
  158. 'table' => true,
  159. 'tbody' => true,
  160. 'td' => true,
  161. 'template' => true,
  162. 'textarea' => false,
  163. 'tfoot' => true,
  164. 'th' => true,
  165. 'thead' => true,
  166. 'time' => true,
  167. 'tr' => true,
  168. 'track' => true,
  169. 'tt' => true,
  170. 'u' => true,
  171. 'ul' => true,
  172. 'var' => true,
  173. 'video' => true,
  174. 'wbr' => true,
  175. 'xmp' => true,
  176. ];
  177. /**
  178. * Attributes allowed by the standard.
  179. */
  180. public const ATTRIBUTES = [
  181. 'abbr' => true,
  182. 'accept' => true,
  183. 'accept-charset' => true,
  184. 'accesskey' => true,
  185. 'action' => true,
  186. 'align' => true,
  187. 'alink' => true,
  188. 'allow' => true,
  189. 'allowfullscreen' => true,
  190. 'allowpaymentrequest' => false,
  191. 'alt' => true,
  192. 'anchor' => true,
  193. 'archive' => true,
  194. 'as' => true,
  195. 'async' => false,
  196. 'autocapitalize' => false,
  197. 'autocomplete' => false,
  198. 'autocorrect' => false,
  199. 'autofocus' => false,
  200. 'autopictureinpicture' => false,
  201. 'autoplay' => false,
  202. 'axis' => true,
  203. 'background' => false,
  204. 'behavior' => true,
  205. 'bgcolor' => false,
  206. 'border' => false,
  207. 'bordercolor' => false,
  208. 'capture' => true,
  209. 'cellpadding' => true,
  210. 'cellspacing' => true,
  211. 'challenge' => true,
  212. 'char' => true,
  213. 'charoff' => true,
  214. 'charset' => true,
  215. 'checked' => false,
  216. 'cite' => true,
  217. 'class' => false,
  218. 'classid' => false,
  219. 'clear' => true,
  220. 'code' => true,
  221. 'codebase' => true,
  222. 'codetype' => true,
  223. 'color' => false,
  224. 'cols' => true,
  225. 'colspan' => true,
  226. 'compact' => true,
  227. 'content' => true,
  228. 'contenteditable' => false,
  229. 'controls' => true,
  230. 'controlslist' => true,
  231. 'conversiondestination' => true,
  232. 'coords' => true,
  233. 'crossorigin' => true,
  234. 'csp' => true,
  235. 'data' => true,
  236. 'datetime' => true,
  237. 'declare' => true,
  238. 'decoding' => true,
  239. 'default' => true,
  240. 'defer' => true,
  241. 'dir' => true,
  242. 'direction' => true,
  243. 'dirname' => true,
  244. 'disabled' => true,
  245. 'disablepictureinpicture' => true,
  246. 'disableremoteplayback' => true,
  247. 'disallowdocumentaccess' => true,
  248. 'download' => true,
  249. 'draggable' => true,
  250. 'elementtiming' => true,
  251. 'enctype' => true,
  252. 'end' => true,
  253. 'enterkeyhint' => true,
  254. 'event' => true,
  255. 'exportparts' => true,
  256. 'face' => true,
  257. 'for' => true,
  258. 'form' => false,
  259. 'formaction' => false,
  260. 'formenctype' => false,
  261. 'formmethod' => false,
  262. 'formnovalidate' => false,
  263. 'formtarget' => false,
  264. 'frame' => false,
  265. 'frameborder' => false,
  266. 'headers' => true,
  267. 'height' => true,
  268. 'hidden' => false,
  269. 'high' => true,
  270. 'href' => true,
  271. 'hreflang' => true,
  272. 'hreftranslate' => true,
  273. 'hspace' => true,
  274. 'http-equiv' => false,
  275. 'id' => true,
  276. 'imagesizes' => true,
  277. 'imagesrcset' => true,
  278. 'importance' => true,
  279. 'impressiondata' => true,
  280. 'impressionexpiry' => true,
  281. 'incremental' => true,
  282. 'inert' => true,
  283. 'inputmode' => true,
  284. 'integrity' => true,
  285. 'invisible' => true,
  286. 'is' => true,
  287. 'ismap' => true,
  288. 'keytype' => true,
  289. 'kind' => true,
  290. 'label' => true,
  291. 'lang' => true,
  292. 'language' => true,
  293. 'latencyhint' => true,
  294. 'leftmargin' => true,
  295. 'link' => true,
  296. 'list' => true,
  297. 'loading' => true,
  298. 'longdesc' => true,
  299. 'loop' => true,
  300. 'low' => true,
  301. 'lowsrc' => true,
  302. 'manifest' => true,
  303. 'marginheight' => true,
  304. 'marginwidth' => true,
  305. 'max' => true,
  306. 'maxlength' => true,
  307. 'mayscript' => true,
  308. 'media' => true,
  309. 'method' => true,
  310. 'min' => true,
  311. 'minlength' => true,
  312. 'multiple' => true,
  313. 'muted' => true,
  314. 'name' => true,
  315. 'nohref' => true,
  316. 'nomodule' => true,
  317. 'nonce' => true,
  318. 'noresize' => true,
  319. 'noshade' => true,
  320. 'novalidate' => true,
  321. 'nowrap' => true,
  322. 'object' => true,
  323. 'open' => true,
  324. 'optimum' => true,
  325. 'part' => true,
  326. 'pattern' => true,
  327. 'ping' => false,
  328. 'placeholder' => true,
  329. 'playsinline' => true,
  330. 'policy' => true,
  331. 'poster' => true,
  332. 'preload' => true,
  333. 'pseudo' => true,
  334. 'readonly' => true,
  335. 'referrerpolicy' => true,
  336. 'rel' => true,
  337. 'reportingorigin' => true,
  338. 'required' => true,
  339. 'resources' => true,
  340. 'rev' => true,
  341. 'reversed' => true,
  342. 'role' => true,
  343. 'rows' => true,
  344. 'rowspan' => true,
  345. 'rules' => true,
  346. 'sandbox' => true,
  347. 'scheme' => true,
  348. 'scope' => true,
  349. 'scopes' => true,
  350. 'scrollamount' => true,
  351. 'scrolldelay' => true,
  352. 'scrolling' => true,
  353. 'select' => false,
  354. 'selected' => false,
  355. 'shadowroot' => true,
  356. 'shadowrootdelegatesfocus' => true,
  357. 'shape' => true,
  358. 'size' => true,
  359. 'sizes' => true,
  360. 'slot' => true,
  361. 'span' => true,
  362. 'spellcheck' => true,
  363. 'src' => true,
  364. 'srcdoc' => true,
  365. 'srclang' => true,
  366. 'srcset' => true,
  367. 'standby' => true,
  368. 'start' => true,
  369. 'step' => true,
  370. 'style' => false,
  371. 'summary' => true,
  372. 'tabindex' => true,
  373. 'target' => true,
  374. 'text' => true,
  375. 'title' => true,
  376. 'topmargin' => true,
  377. 'translate' => true,
  378. 'truespeed' => true,
  379. 'trusttoken' => true,
  380. 'type' => true,
  381. 'usemap' => true,
  382. 'valign' => true,
  383. 'value' => false,
  384. 'valuetype' => true,
  385. 'version' => true,
  386. 'virtualkeyboardpolicy' => true,
  387. 'vlink' => false,
  388. 'vspace' => true,
  389. 'webkitdirectory' => true,
  390. 'width' => false,
  391. 'wrap' => true,
  392. ];
  393. }