[TASK] Move RemoveXSS to EXT:core 48/37448/3
authorBenjamin Mack <benni@typo3.org>
Mon, 2 Mar 2015 10:50:42 +0000 (11:50 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 2 Mar 2015 11:07:32 +0000 (12:07 +0100)
The external library RemoveXSS placed
within typo3/contrib/ is moved to EXT:core
and also loaded via composer in order
to avoid a require_once.

Additionally, some other changes in
the static composer class loader shipped
with typo3/contrib/vendor are updated
as well.

Resolves: #65450
Releases: master
Change-Id: I804754df10288924247f58dc93a8e46f9268aa3b
Reviewed-on: http://review.typo3.org/37448
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
composer.json
typo3/contrib/RemoveXSS/RemoveXSS.php [deleted file]
typo3/contrib/vendor/composer/autoload_classmap.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Resources/PHP/RemoveXSS.php [new file with mode: 0644]
typo3/sysext/core/Tests/Legacy/typo3/contrib/class.removexssTest.php
typo3/sysext/core/composer.json

index 679b078..e5e247f 100644 (file)
                        "TYPO3\\CMS\\Recordlist\\": "typo3/sysext/recordlist/Classes/",
                        "TYPO3\\CMS\\Saltedpasswords\\": "typo3/sysext/saltedpasswords/Classes/",
                        "TYPO3\\CMS\\Sv\\": "typo3/sysext/sv/Classes/"
-               }
+               },
+               "classmap": ["typo3/sysext/core/Resources/PHP/RemoveXSS.php"]
        },
        "autoload-dev": {
                "psr-4": {
diff --git a/typo3/contrib/RemoveXSS/RemoveXSS.php b/typo3/contrib/RemoveXSS/RemoveXSS.php
deleted file mode 100644 (file)
index b1598d0..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-<?php
-/**
- * Usage: Run *every* variable passed in through it.
- * The goal of this function is to be a generic function that can be used to
- * parse almost any input and render it XSS safe. For more information on
- * actual XSS attacks, check out http://ha.ckers.org/xss.html. Another
- * excellent site is the XSS Database which details each attack and how it
- * works.
- *
- * Used with permission by the author.
- * URL: http://quickwired.com/smallprojects/php_xss_filter_function.php
- *
- * Check XSS attacks on http://ha.ckers.org/xss.html
- *
- * License:
- * This code is public domain, you are free to do whatever you want with it,
- * including adding it to your own project which can be under any license.
- *
- * @author     Travis Puderbaugh <kallahar@quickwired.com>
- * @author     Jigal van Hemert <jigal@xs4all.nl>
- * @package    RemoveXSS
- */
-class RemoveXSS {
-
-       /**
-        * Removes potential XSS code from an input string.
-        *
-        * Using an external class by Travis Puderbaugh <kallahar@quickwired.com>
-        *
-        * @param string $val Input string
-        * @param string $replaceString replaceString for inserting in keywords (which destroys the tags)
-        * @return string Input string with potential XSS code removed
-        */
-       public static function process($val, $replaceString = '<x>') {
-               // Don't use empty $replaceString because then no XSS-remove will be done
-               if ($replaceString == '') {
-                       $replaceString = '<x>';
-               }
-               // Remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed.
-               // This prevents some character re-spacing such as <java\0script>
-               // Note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
-               $val = preg_replace('/([\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19])/', '', $val);
-
-               // Straight replacements, the user should never need these since they're normal characters.
-               // This prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
-               $searchHexEncodings = '/&#[xX]0{0,8}(21|22|23|24|25|26|27|28|29|2a|2b|2d|2f|30|31|32|33|34|35|36|37|38|39|3a|3b|3d|3f|40|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|5b|5c|5d|5e|5f|60|61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|7b|7c|7d|7e);?/i';
-               $searchUnicodeEncodings = '/&#0{0,8}(33|34|35|36|37|38|39|40|41|42|43|45|47|48|49|50|51|52|53|54|55|56|57|58|59|61|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126);?/i';
-               while (preg_match($searchHexEncodings, $val) || preg_match($searchUnicodeEncodings, $val)) {
-                       $val = preg_replace_callback(
-                               $searchHexEncodings,
-                               function ($matches) {
-                                       return chr(hexdec($matches[1]));
-                               },
-                               $val
-                       );
-                       $val = preg_replace_callback(
-                               $searchUnicodeEncodings,
-                               function ($matches) {
-                                       return chr($matches[1]);
-                               },
-                               $val
-                       );
-               }
-
-               // Now the only remaining whitespace attacks are \t, \n, and \r
-               $ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed',
-                       'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base', 'video', 'audio', 'track',
-                       'canvas', 'onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut',
-                       'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate',
-                       'onblur', 'onbounce', 'oncanplay', 'oncanplaythrough', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu',
-                       'oncontrolselect', 'oncopy', 'oncuechange', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete',
-                       'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart',
-                       'ondrop', 'ondurationchange', 'onemptied', 'onended', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish',
-                       'onfocus', 'onfocusin', 'onfocusout', 'onhashchange', 'onhelp', 'oninput', 'oninvalid', 'onkeydown', 'onkeypress',
-                       'onkeyup', 'onlayoutcomplete', 'onload', 'onloadeddata', 'onloadedmetadata', 'onloadstart', 'onlosecapture',
-                       'onmessage', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup',
-                       'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onoffline', 'ononline', 'onpagehide', 'onpageshow', 'onpaste',
-                       'onpause', 'onplay', 'onplaying', 'onpopstate', 'onprogress', 'onpropertychange', 'onratechange', 'onreadystatechange',
-                       'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted',
-                       'onscroll', 'onseeked', 'onseeking','onselect', 'onselectionchange', 'onselectstart', 'onshow', 'onstalled', 'onstart',
-                       'onstop', 'onstorage', 'onsubmit', 'onsuspend', 'ontimeupdate', 'onunload', 'onvolumechange', 'onwaiting');
-               $ra_tag = array('applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame',
-                       'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base', 'video', 'audio', 'track', 'canvas');
-               $ra_attribute = array('style', 'onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate',
-                       'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint',
-                       'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncanplay', 'oncanplaythrough', 'oncellchange', 'onchange',
-                       'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncuechange', 'oncut', 'ondataavailable', 'ondatasetchanged',
-                       'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover',
-                       'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended', 'onerror', 'onerrorupdate', 'onfilterchange',
-                       'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhashchange', 'onhelp', 'oninput', 'oninvalid,', 'onkeydown',
-                       'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onloadeddata', 'onloadedmetadata', 'onloadstart',
-                       'onlosecapture', 'onmessage', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout',
-                       'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onoffline', 'ononline',
-                       'onpagehide', 'onpageshow', 'onpaste', 'onpause', 'onplay', 'onplaying', 'onpopstate', 'onprogress',
-                       'onpropertychange', 'onratechange', 'onreadystatechange', 'onredo', 'onreset', 'onresize', 'onresizeend',
-                       'onresizestart','onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onseeked', 'onseeking',
-                       'onselect', 'onselectionchange', 'onselectstart', 'onshow', 'onstalled', 'onstart', 'onstop', 'onstorage', 'onsubmit',
-                       'onsuspend', 'ontimeupdate', 'onundo', 'onunload', 'onvolumechange', 'onwaiting');
-               $ra_protocol = array('javascript', 'vbscript', 'expression');
-
-               // Remove the potential &#xxx; stuff for testing
-               $val2 = preg_replace('/(&#[xX]?0{0,8}(9|10|13|a|b);?)*\s*/i', '', $val);
-               $ra = array();
-
-               foreach ($ra1 as $ra1word) {
-                       // Stripos is faster than the regular expressions used later and because the words we're looking for only have
-                       // chars < 0x80 we can use the non-multibyte safe version.
-                       if (stripos($val2, $ra1word ) !== FALSE ) {
-                                       //keep list of potential words that were found
-                               if (in_array($ra1word, $ra_protocol, TRUE)) {
-                                       $ra[] = array($ra1word, 'ra_protocol');
-                               }
-                               if (in_array($ra1word, $ra_tag, TRUE)) {
-                                       $ra[] = array($ra1word, 'ra_tag');
-                               }
-                               if (in_array($ra1word, $ra_attribute, TRUE)) {
-                                       $ra[] = array($ra1word, 'ra_attribute');
-                               }
-                               // Some keywords appear in more than one array.
-                               // These get multiple entries in $ra, each with the appropriate type
-                       }
-               }
-               // Only process potential words
-               if (count($ra) > 0) {
-                       // Keep replacing as long as the previous round replaced something
-                       $found = TRUE;
-                       while ($found == TRUE) {
-                               $val_before = $val;
-                               for ($i = 0; $i < sizeof($ra); $i++) {
-                                       $pattern = '';
-                                       for ($j = 0; $j < strlen($ra[$i][0]); $j++) {
-                                               if ($j > 0) {
-                                                       $pattern .= '((&#[xX]0{0,8}([9ab]);?)|(&#0{0,8}(9|10|13);?)|\s)*';
-                                               }
-                                               $pattern .= $ra[$i][0][$j];
-                                       }
-                                       // Handle each type a little different (extra conditions to prevent false positives a bit better)
-                                       switch ($ra[$i][1]) {
-                                               case 'ra_protocol':
-                                                       // These take the form of e.g. 'javascript:'
-                                                       $pattern .= '((&#[xX]0{0,8}([9ab]);?)|(&#0{0,8}(9|10|13);?)|\s)*(?=:)';
-                                                       break;
-                                               case 'ra_tag':
-                                                       // These take the form of e.g. '<SCRIPT[^\da-z] ....';
-                                                       $pattern = '(?<=<)' . $pattern . '((&#[xX]0{0,8}([9ab]);?)|(&#0{0,8}(9|10|13);?)|\s)*(?=[^\da-z])';
-                                                       break;
-                                               case 'ra_attribute':
-                                                       // These take the form of e.g. 'onload='  Beware that a lot of characters are allowed
-                                                       // between the attribute and the equal sign!
-                                                       $pattern .= '[\s\!\#\$\%\&\(\)\*\~\+\-\_\.\,\:\;\?\@\[\/\|\\\\\]\^\`]*(?==)';
-                                                       break;
-                                       }
-                                       $pattern = '/' . $pattern . '/i';
-                                       // Add in <x> to nerf the tag
-                                       $replacement = substr_replace($ra[$i][0], $replaceString, 2, 0);
-                                       // Filter out the hex tags
-                                       $val = preg_replace($pattern, $replacement, $val);
-                                       if ($val_before == $val) {
-                                               // No replacements were made, so exit the loop
-                                               $found = FALSE;
-                                       }
-                               }
-                       }
-               }
-               return $val;
-       }
-}
index ab31388..090ccf5 100644 (file)
@@ -10,6 +10,7 @@ return array(
     'Helhum\\ClassAliasLoader\\Composer\\ClassAliasLoader' => $vendorDir . '/helhum/class-alias-loader/Classes/Composer/ClassAliasLoader.php',
     'Psr\\Log\\InvalidArgumentException' => $baseDir . '/typo3/contrib/Psr/Log/InvalidArgumentException.php',
     'Psr\\Log\\LoggerInterface' => $baseDir . '/typo3/contrib/Psr/Log/LoggerInterface.php',
+    'RemoveXSS' => $baseDir . '/typo3/sysext/core/Resources/PHP/RemoveXSS.php',
     'TYPO3\\CMS\\Backend\\AjaxLoginHandler' => $baseDir . '/typo3/sysext/backend/Classes/AjaxLoginHandler.php',
     'TYPO3\\CMS\\Backend\\Backend\\ToolbarItems\\ClearCacheToolbarItem' => $baseDir . '/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php',
     'TYPO3\\CMS\\Backend\\Backend\\ToolbarItems\\HelpToolbarItem' => $baseDir . '/typo3/sysext/backend/Classes/Backend/ToolbarItems/HelpToolbarItem.php',
@@ -75,17 +76,18 @@ return array(
     'TYPO3\\CMS\\Backend\\Form\\Element\\NoneElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/NoneElement.php',
     'TYPO3\\CMS\\Backend\\Form\\Element\\RadioElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/RadioElement.php',
     'TYPO3\\CMS\\Backend\\Form\\Element\\SelectElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/SelectElement.php',
-    'TYPO3\\CMS\\Backend\\Form\\Element\\SuggestDefaultReceiver' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/SuggestDefaultReceiver.php',
-    'TYPO3\\CMS\\Backend\\Form\\Element\\SuggestElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/SuggestElement.php',
     'TYPO3\\CMS\\Backend\\Form\\Element\\TextElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/TextElement.php',
     'TYPO3\\CMS\\Backend\\Form\\Element\\TreeElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/TreeElement.php',
     'TYPO3\\CMS\\Backend\\Form\\Element\\UnknownElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/UnknownElement.php',
     'TYPO3\\CMS\\Backend\\Form\\Element\\UserElement' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/UserElement.php',
-    'TYPO3\\CMS\\Backend\\Form\\Element\\ValueSlider' => $baseDir . '/typo3/sysext/backend/Classes/Form/Element/ValueSlider.php',
     'TYPO3\\CMS\\Backend\\Form\\FlexFormsHelper' => $baseDir . '/typo3/sysext/backend/Classes/Form/FlexFormsHelper.php',
     'TYPO3\\CMS\\Backend\\Form\\FormDataTraverser' => $baseDir . '/typo3/sysext/backend/Classes/Form/FormDataTraverser.php',
     'TYPO3\\CMS\\Backend\\Form\\FormEngine' => $baseDir . '/typo3/sysext/backend/Classes/Form/FormEngine.php',
     'TYPO3\\CMS\\Backend\\Form\\FrontendFormEngine' => $baseDir . '/typo3/sysext/backend/Classes/Form/FrontendFormEngine.php',
+    'TYPO3\\CMS\\Backend\\Form\\Utility\\FormEngineUtility' => $baseDir . '/typo3/sysext/backend/Classes/Form/Utility/FormEngineUtility.php',
+    'TYPO3\\CMS\\Backend\\Form\\Wizard\\SuggestWizard' => $baseDir . '/typo3/sysext/backend/Classes/Form/Wizard/SuggestWizard.php',
+    'TYPO3\\CMS\\Backend\\Form\\Wizard\\SuggestWizardDefaultReceiver' => $baseDir . '/typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php',
+    'TYPO3\\CMS\\Backend\\Form\\Wizard\\ValueSliderWizard' => $baseDir . '/typo3/sysext/backend/Classes/Form/Wizard/ValueSliderWizard.php',
     'TYPO3\\CMS\\Backend\\FrontendBackendUserAuthentication' => $baseDir . '/typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php',
     'TYPO3\\CMS\\Backend\\History\\RecordHistory' => $baseDir . '/typo3/sysext/backend/Classes/History/RecordHistory.php',
     'TYPO3\\CMS\\Backend\\InterfaceState\\ExtDirect\\DataProvider' => $baseDir . '/typo3/sysext/backend/Classes/InterfaceState/ExtDirect/DataProvider.php',
@@ -1039,13 +1041,11 @@ return array(
     'TYPO3\\CMS\\Frontend\\ContentObject\\FileContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/FileContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\FileLinkHookInterface' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/FileLinkHookInterface.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\FilesContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php',
-    'TYPO3\\CMS\\Frontend\\ContentObject\\FlowPlayerContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/FlowPlayerContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\FluidTemplateContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\HierarchicalMenuContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/HierarchicalMenuContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\ImageContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/ImageContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\ImageResourceContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/ImageResourceContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\LoadRegisterContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/LoadRegisterContentObject.php',
-    'TYPO3\\CMS\\Frontend\\ContentObject\\MediaContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/MediaContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\AbstractMenuContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\AbstractMenuFilterPagesHookInterface' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuFilterPagesHookInterface.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\CategoryMenuUtility' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/Menu/CategoryMenuUtility.php',
@@ -1055,12 +1055,9 @@ return array(
     'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\JavaScriptMenuContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/Menu/JavaScriptMenuContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\MenuContentObjectFactory' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/Menu/MenuContentObjectFactory.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\TextMenuContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/Menu/TextMenuContentObject.php',
-    'TYPO3\\CMS\\Frontend\\ContentObject\\MultimediaContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/MultimediaContentObject.php',
-    'TYPO3\\CMS\\Frontend\\ContentObject\\QuicktimeObjectContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/QuicktimeObjectContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\RecordsContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\RestoreRegisterContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/RestoreRegisterContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\ScalableVectorGraphicsContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/ScalableVectorGraphicsContentObject.php',
-    'TYPO3\\CMS\\Frontend\\ContentObject\\ShockwaveFlashObjectContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/ShockwaveFlashObjectContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\TemplateContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/TemplateContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\TextContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/TextContentObject.php',
     'TYPO3\\CMS\\Frontend\\ContentObject\\UserContentObject' => $baseDir . '/typo3/sysext/frontend/Classes/ContentObject/UserContentObject.php',
@@ -1214,6 +1211,7 @@ return array(
     'TYPO3\\CMS\\Install\\Updates\\FinalDatabaseSchemaUpdate' => $baseDir . '/typo3/sysext/install/Classes/Updates/FinalDatabaseSchemaUpdate.php',
     'TYPO3\\CMS\\Install\\Updates\\InitialDatabaseSchemaUpdate' => $baseDir . '/typo3/sysext/install/Classes/Updates/InitialDatabaseSchemaUpdate.php',
     'TYPO3\\CMS\\Install\\Updates\\LanguageIsoCodeUpdate' => $baseDir . '/typo3/sysext/install/Classes/Updates/LanguageIsoCodeUpdate.php',
+    'TYPO3\\CMS\\Install\\Updates\\MigrateShortcutUrlsUpdate' => $baseDir . '/typo3/sysext/install/Classes/Updates/MigrateShortcutUrlsUpdate.php',
     'TYPO3\\CMS\\Install\\Updates\\PageShortcutParentUpdate' => $baseDir . '/typo3/sysext/install/Classes/Updates/PageShortcutParentUpdate.php',
     'TYPO3\\CMS\\Install\\ViewHelpers\\Be\\ContainerViewHelper' => $baseDir . '/typo3/sysext/install/Classes/ViewHelpers/Be/ContainerViewHelper.php',
     'TYPO3\\CMS\\Install\\ViewHelpers\\ConstantViewHelper' => $baseDir . '/typo3/sysext/install/Classes/ViewHelpers/ConstantViewHelper.php',
index 7e9e5c4..3875a60 100755 (executable)
@@ -251,9 +251,7 @@ class GeneralUtility {
         * @return string Input string with potential XSS code removed
         */
        static public function removeXSS($string) {
-               require_once PATH_typo3 . 'contrib/RemoveXSS/RemoveXSS.php';
-               $string = \RemoveXSS::process($string);
-               return $string;
+               return \RemoveXSS::process($string);
        }
 
        /*************************
diff --git a/typo3/sysext/core/Resources/PHP/RemoveXSS.php b/typo3/sysext/core/Resources/PHP/RemoveXSS.php
new file mode 100644 (file)
index 0000000..b1598d0
--- /dev/null
@@ -0,0 +1,167 @@
+<?php
+/**
+ * Usage: Run *every* variable passed in through it.
+ * The goal of this function is to be a generic function that can be used to
+ * parse almost any input and render it XSS safe. For more information on
+ * actual XSS attacks, check out http://ha.ckers.org/xss.html. Another
+ * excellent site is the XSS Database which details each attack and how it
+ * works.
+ *
+ * Used with permission by the author.
+ * URL: http://quickwired.com/smallprojects/php_xss_filter_function.php
+ *
+ * Check XSS attacks on http://ha.ckers.org/xss.html
+ *
+ * License:
+ * This code is public domain, you are free to do whatever you want with it,
+ * including adding it to your own project which can be under any license.
+ *
+ * @author     Travis Puderbaugh <kallahar@quickwired.com>
+ * @author     Jigal van Hemert <jigal@xs4all.nl>
+ * @package    RemoveXSS
+ */
+class RemoveXSS {
+
+       /**
+        * Removes potential XSS code from an input string.
+        *
+        * Using an external class by Travis Puderbaugh <kallahar@quickwired.com>
+        *
+        * @param string $val Input string
+        * @param string $replaceString replaceString for inserting in keywords (which destroys the tags)
+        * @return string Input string with potential XSS code removed
+        */
+       public static function process($val, $replaceString = '<x>') {
+               // Don't use empty $replaceString because then no XSS-remove will be done
+               if ($replaceString == '') {
+                       $replaceString = '<x>';
+               }
+               // Remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed.
+               // This prevents some character re-spacing such as <java\0script>
+               // Note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
+               $val = preg_replace('/([\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19])/', '', $val);
+
+               // Straight replacements, the user should never need these since they're normal characters.
+               // This prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
+               $searchHexEncodings = '/&#[xX]0{0,8}(21|22|23|24|25|26|27|28|29|2a|2b|2d|2f|30|31|32|33|34|35|36|37|38|39|3a|3b|3d|3f|40|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|5b|5c|5d|5e|5f|60|61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|7b|7c|7d|7e);?/i';
+               $searchUnicodeEncodings = '/&#0{0,8}(33|34|35|36|37|38|39|40|41|42|43|45|47|48|49|50|51|52|53|54|55|56|57|58|59|61|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126);?/i';
+               while (preg_match($searchHexEncodings, $val) || preg_match($searchUnicodeEncodings, $val)) {
+                       $val = preg_replace_callback(
+                               $searchHexEncodings,
+                               function ($matches) {
+                                       return chr(hexdec($matches[1]));
+                               },
+                               $val
+                       );
+                       $val = preg_replace_callback(
+                               $searchUnicodeEncodings,
+                               function ($matches) {
+                                       return chr($matches[1]);
+                               },
+                               $val
+                       );
+               }
+
+               // Now the only remaining whitespace attacks are \t, \n, and \r
+               $ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed',
+                       'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base', 'video', 'audio', 'track',
+                       'canvas', 'onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut',
+                       'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate',
+                       'onblur', 'onbounce', 'oncanplay', 'oncanplaythrough', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu',
+                       'oncontrolselect', 'oncopy', 'oncuechange', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete',
+                       'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart',
+                       'ondrop', 'ondurationchange', 'onemptied', 'onended', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish',
+                       'onfocus', 'onfocusin', 'onfocusout', 'onhashchange', 'onhelp', 'oninput', 'oninvalid', 'onkeydown', 'onkeypress',
+                       'onkeyup', 'onlayoutcomplete', 'onload', 'onloadeddata', 'onloadedmetadata', 'onloadstart', 'onlosecapture',
+                       'onmessage', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup',
+                       'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onoffline', 'ononline', 'onpagehide', 'onpageshow', 'onpaste',
+                       'onpause', 'onplay', 'onplaying', 'onpopstate', 'onprogress', 'onpropertychange', 'onratechange', 'onreadystatechange',
+                       'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted',
+                       'onscroll', 'onseeked', 'onseeking','onselect', 'onselectionchange', 'onselectstart', 'onshow', 'onstalled', 'onstart',
+                       'onstop', 'onstorage', 'onsubmit', 'onsuspend', 'ontimeupdate', 'onunload', 'onvolumechange', 'onwaiting');
+               $ra_tag = array('applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame',
+                       'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base', 'video', 'audio', 'track', 'canvas');
+               $ra_attribute = array('style', 'onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate',
+                       'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint',
+                       'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncanplay', 'oncanplaythrough', 'oncellchange', 'onchange',
+                       'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncuechange', 'oncut', 'ondataavailable', 'ondatasetchanged',
+                       'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover',
+                       'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended', 'onerror', 'onerrorupdate', 'onfilterchange',
+                       'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhashchange', 'onhelp', 'oninput', 'oninvalid,', 'onkeydown',
+                       'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onloadeddata', 'onloadedmetadata', 'onloadstart',
+                       'onlosecapture', 'onmessage', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout',
+                       'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onoffline', 'ononline',
+                       'onpagehide', 'onpageshow', 'onpaste', 'onpause', 'onplay', 'onplaying', 'onpopstate', 'onprogress',
+                       'onpropertychange', 'onratechange', 'onreadystatechange', 'onredo', 'onreset', 'onresize', 'onresizeend',
+                       'onresizestart','onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onseeked', 'onseeking',
+                       'onselect', 'onselectionchange', 'onselectstart', 'onshow', 'onstalled', 'onstart', 'onstop', 'onstorage', 'onsubmit',
+                       'onsuspend', 'ontimeupdate', 'onundo', 'onunload', 'onvolumechange', 'onwaiting');
+               $ra_protocol = array('javascript', 'vbscript', 'expression');
+
+               // Remove the potential &#xxx; stuff for testing
+               $val2 = preg_replace('/(&#[xX]?0{0,8}(9|10|13|a|b);?)*\s*/i', '', $val);
+               $ra = array();
+
+               foreach ($ra1 as $ra1word) {
+                       // Stripos is faster than the regular expressions used later and because the words we're looking for only have
+                       // chars < 0x80 we can use the non-multibyte safe version.
+                       if (stripos($val2, $ra1word ) !== FALSE ) {
+                                       //keep list of potential words that were found
+                               if (in_array($ra1word, $ra_protocol, TRUE)) {
+                                       $ra[] = array($ra1word, 'ra_protocol');
+                               }
+                               if (in_array($ra1word, $ra_tag, TRUE)) {
+                                       $ra[] = array($ra1word, 'ra_tag');
+                               }
+                               if (in_array($ra1word, $ra_attribute, TRUE)) {
+                                       $ra[] = array($ra1word, 'ra_attribute');
+                               }
+                               // Some keywords appear in more than one array.
+                               // These get multiple entries in $ra, each with the appropriate type
+                       }
+               }
+               // Only process potential words
+               if (count($ra) > 0) {
+                       // Keep replacing as long as the previous round replaced something
+                       $found = TRUE;
+                       while ($found == TRUE) {
+                               $val_before = $val;
+                               for ($i = 0; $i < sizeof($ra); $i++) {
+                                       $pattern = '';
+                                       for ($j = 0; $j < strlen($ra[$i][0]); $j++) {
+                                               if ($j > 0) {
+                                                       $pattern .= '((&#[xX]0{0,8}([9ab]);?)|(&#0{0,8}(9|10|13);?)|\s)*';
+                                               }
+                                               $pattern .= $ra[$i][0][$j];
+                                       }
+                                       // Handle each type a little different (extra conditions to prevent false positives a bit better)
+                                       switch ($ra[$i][1]) {
+                                               case 'ra_protocol':
+                                                       // These take the form of e.g. 'javascript:'
+                                                       $pattern .= '((&#[xX]0{0,8}([9ab]);?)|(&#0{0,8}(9|10|13);?)|\s)*(?=:)';
+                                                       break;
+                                               case 'ra_tag':
+                                                       // These take the form of e.g. '<SCRIPT[^\da-z] ....';
+                                                       $pattern = '(?<=<)' . $pattern . '((&#[xX]0{0,8}([9ab]);?)|(&#0{0,8}(9|10|13);?)|\s)*(?=[^\da-z])';
+                                                       break;
+                                               case 'ra_attribute':
+                                                       // These take the form of e.g. 'onload='  Beware that a lot of characters are allowed
+                                                       // between the attribute and the equal sign!
+                                                       $pattern .= '[\s\!\#\$\%\&\(\)\*\~\+\-\_\.\,\:\;\?\@\[\/\|\\\\\]\^\`]*(?==)';
+                                                       break;
+                                       }
+                                       $pattern = '/' . $pattern . '/i';
+                                       // Add in <x> to nerf the tag
+                                       $replacement = substr_replace($ra[$i][0], $replaceString, 2, 0);
+                                       // Filter out the hex tags
+                                       $val = preg_replace($pattern, $replacement, $val);
+                                       if ($val_before == $val) {
+                                               // No replacements were made, so exit the loop
+                                               $found = FALSE;
+                                       }
+                               }
+                       }
+               }
+               return $val;
+       }
+}
index 547e5b7..514d061 100644 (file)
@@ -12,8 +12,6 @@
  * The TYPO3 project - inspiring people to share!
  */
 
-require_once(PATH_typo3 . 'contrib/RemoveXSS/RemoveXSS.php');
-
 /**
  * Testcase for class RemoveXSS
  *
index da532e4..55a1349 100644 (file)
@@ -27,7 +27,8 @@
                },
                "psr-0": {
                        "TYPO3\\Flow\\": "Resources/PHP/TYPO3.Flow/Classes/"
-               }
+               },
+               "classmap": ["Resources/PHP/RemoveXSS.php"]
        },
        "autoload-dev": {
                "psr-4": {