diff options
Diffstat (limited to 'core/Translate/Validate/NoScripts.php')
-rw-r--r-- | core/Translate/Validate/NoScripts.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/core/Translate/Validate/NoScripts.php b/core/Translate/Validate/NoScripts.php new file mode 100644 index 0000000000..b3017b840c --- /dev/null +++ b/core/Translate/Validate/NoScripts.php @@ -0,0 +1,46 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik + */ + +namespace Piwik\Translate\Validate; + +use Piwik\Translate\Validate\ValidateAbstract; +use Piwik\Common; + +/** + * @package Piwik + * @subpackage Piwik_Translate + */ +class NoScripts extends ValidateAbstract +{ + /** + * Validates the given translations + * + * @param array $translations + * + * @return boolean + * + */ + public function isValid($translations) + { + $this->_error = null; + + // check if any translation contains restricted script tags + $serializedStrings = serialize($translations); + $invalids = array("<script", 'document.', 'javascript:', 'src=', 'background=', 'onload='); + foreach ($invalids as $invalid) { + if (stripos($serializedStrings, $invalid) !== false) { + $this->_error = 'script tags restricted for language files'; + return false; + } + } + return true; + } +}
\ No newline at end of file |