Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature #12560: enable video in spite of active xss filtering (#1589
) Dev Added new configuration to the HtmlPurifier. Dev Extended the standard HtmlPurifier so it exposes the config in a public method.
- Loading branch information
1 parent
518e519
commit 8493b59
Showing
2 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php if (!defined('BASEPATH')) { | ||
exit('No direct script access allowed'); | ||
} | ||
/* | ||
* LimeSurvey | ||
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz | ||
* All rights reserved. | ||
* License: GNU/GPL License v2 or later, see LICENSE.php | ||
* LimeSurvey is free software. This version may have been modified pursuant | ||
* to the GNU General Public License, and as distributed it includes or | ||
* is derivative of works licensed under the GNU General Public License or | ||
* other free or open source software licenses. | ||
* See COPYRIGHT.php for copyright notices and details. | ||
* | ||
*/ | ||
|
||
class LSYii_HtmlPurifier extends CHtmlPurifier | ||
{ | ||
|
||
/** | ||
* Get the config object for the HTML Purifier instance. | ||
* @return mixed the HTML Purifier instance config | ||
*/ | ||
public function getConfig() | ||
{ | ||
$purifier = $this->getPurifier(); | ||
if($purifier!==null) return $purifier->config; | ||
} | ||
|
||
/** | ||
* Get an instance of LSYii_HtmlPurifier configured for XSS filtering | ||
*/ | ||
public static function getXssPurifier() { | ||
$instance = new self(); | ||
$instance->options = array( | ||
'AutoFormat.RemoveEmpty'=>false, | ||
'Core.NormalizeNewlines'=>false, | ||
'CSS.AllowTricky'=>true, // Allow display:none; (and other) | ||
'HTML.SafeObject'=>true, // To allow including youtube | ||
'Output.FlashCompat'=>true, | ||
'Attr.EnableID'=>true, // Allow to set id | ||
'Attr.AllowedFrameTargets'=>array('_blank', '_self'), | ||
'URI.AllowedSchemes'=>array( | ||
'http' => true, | ||
'https' => true, | ||
'mailto' => true, | ||
'ftp' => true, | ||
'nntp' => true, | ||
'news' => true, | ||
) | ||
); | ||
// To allow script BUT purify : HTML.Trusted=true (plugin idea for admin or without XSS filtering ?) | ||
|
||
// Enable video | ||
$config = $instance->getConfig(); | ||
if (!empty($config)) { | ||
$config->set('HTML.DefinitionID', 'html5-definitions'); | ||
$def = $config->maybeGetRawHTMLDefinition(); | ||
$max = $config->get('HTML.MaxImgLength'); | ||
if ($def) { | ||
$def->addElement( | ||
'video', // name | ||
'Inline', // content set | ||
'Flow', // allowed children | ||
'Common', // attribute collection | ||
array( // attributes | ||
'src' => 'URI', | ||
'id' => 'Text', | ||
'poster' => 'Text', | ||
'width' => 'Pixels#' . $max, | ||
'height' => 'Pixels#' . $max, | ||
'controls' => 'Bool#controls', | ||
'autobuffer' => 'Bool#autobuffer', | ||
'autoplay' => 'Bool#autoplay', | ||
'loop' => 'Bool#loop', | ||
'muted' => 'Bool#muted' | ||
) | ||
); | ||
$def->addElement( | ||
'source', // name | ||
'Inline', // content set | ||
'Empty', // allowed children | ||
null, // attribute collection | ||
array( // attributes | ||
'src*' => 'URI', | ||
'type' => 'Enum#video/mp4,video/webm', | ||
) | ||
); | ||
} | ||
} | ||
|
||
return $instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8493b59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to have tis feature in 3.X , but what new feature is allowed are really complex ... and can make developer really unhappy ....