SafeScripting.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * A "safe" script module. No inline JS is allowed, and pointed to JS
  4. * files must match whitelist.
  5. */
  6. class HTMLPurifier_HTMLModule_SafeScripting extends HTMLPurifier_HTMLModule
  7. {
  8. public $name = 'SafeScripting';
  9. public function setup($config) {
  10. // These definitions are not intrinsically safe: the attribute transforms
  11. // are a vital part of ensuring safety.
  12. $allowed = $config->get('HTML.SafeScripting');
  13. $script = $this->addElement(
  14. 'script',
  15. 'Inline',
  16. 'Empty',
  17. null,
  18. array(
  19. // While technically not required by the spec, we're forcing
  20. // it to this value.
  21. 'type' => 'Enum#text/javascript',
  22. 'src*' => new HTMLPurifier_AttrDef_Enum(array_keys($allowed))
  23. )
  24. );
  25. $script->attr_transform_pre[] =
  26. $script->attr_transform_post[] = new HTMLPurifier_AttrTransform_ScriptRequired();
  27. }
  28. }
  29. // vim: et sw=4 sts=4