Make WordPress Core

Ticket #12284: miqro-html-injections-for-wordpress.patch

File miqro-html-injections-for-wordpress.patch, 5.1 KB (added by miqrogroove, 15 years ago)

This file fully patches kses, and resolves one known issue in html_esc()

  • wp-includes/formatting.php

     
    334334        // Handle double encoding ourselves
    335335        if ( !$double_encode ) {
    336336                $string = wp_specialchars_decode( $string, $_quote_style );
     337
     338                /* Critical */
     339                // The previous line decodes &phrase; into &phrase;  We must guarantee that &phrase; is valid before proceeding.
     340                $string = wp_kses_normalize_entities($string);
     341
     342                // Now proceed with custom double-encoding silliness
    337343                $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
    338344        }
    339345
  • wp-includes/kses.php

     
    952952
    953953        # Change back the allowed entities in our entity whitelist
    954954
    955         $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string);
     955        $string = preg_replace_callback('/&([A-Za-z]{2,8});/', 'wp_kses_named_entities', $string);
    956956        $string = preg_replace_callback('/&#0*([0-9]{1,5});/', 'wp_kses_normalize_entities2', $string);
    957957        $string = preg_replace_callback('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', 'wp_kses_normalize_entities3', $string);
    958958
     
    962962/**
    963963 * Callback for wp_kses_normalize_entities() regular expression.
    964964 *
     965 * This function only accepts valid named entity references, which are finite,
     966 * case-sensitive, and highly scrutinized by HTML and XML validators.
     967 *
     968 * @since 3.0.0
     969 *
     970 * @param array $matches preg_replace_callback() matches array
     971 * @return string Correctly encoded entity
     972 */
     973function wp_kses_named_entities($matches) {
     974        if ( empty($matches[1]) )
     975                return '';
     976
     977        $names = array(
     978        'nbsp',
     979        'iexcl',
     980        'cent',
     981        'pound',
     982        'curren',
     983        'yen',
     984        'brvbar',
     985        'sect',
     986        'uml',
     987        'copy',
     988        'ordf',
     989        'laquo',
     990        'not',
     991        'shy',
     992        'reg',
     993        'macr',
     994        'deg',
     995        'plusmn',
     996        'acute',
     997        'micro',
     998        'para',
     999        'middot',
     1000        'cedil',
     1001        'ordm',
     1002        'raquo',
     1003        'iquest',
     1004        'Agrave',
     1005        'Aacute',
     1006        'Acirc',
     1007        'Atilde',
     1008        'Auml',
     1009        'Aring',
     1010        'AElig',
     1011        'Ccedil',
     1012        'Egrave',
     1013        'Eacute',
     1014        'Ecirc',
     1015        'Euml',
     1016        'Igrave',
     1017        'Iacute',
     1018        'Icirc',
     1019        'Iuml',
     1020        'ETH',
     1021        'Ntilde',
     1022        'Ograve',
     1023        'Oacute',
     1024        'Ocirc',
     1025        'Otilde',
     1026        'Ouml',
     1027        'times',
     1028        'Oslash',
     1029        'Ugrave',
     1030        'Uacute',
     1031        'Ucirc',
     1032        'Uuml',
     1033        'Yacute',
     1034        'THORN',
     1035        'szlig',
     1036        'agrave',
     1037        'aacute',
     1038        'acirc',
     1039        'atilde',
     1040        'auml',
     1041        'aring',
     1042        'aelig',
     1043        'ccedil',
     1044        'egrave',
     1045        'eacute',
     1046        'ecirc',
     1047        'euml',
     1048        'igrave',
     1049        'iacute',
     1050        'icirc',
     1051        'iuml',
     1052        'eth',
     1053        'ntilde',
     1054        'ograve',
     1055        'oacute',
     1056        'ocirc',
     1057        'otilde',
     1058        'ouml',
     1059        'divide',
     1060        'oslash',
     1061        'ugrave',
     1062        'uacute',
     1063        'ucirc',
     1064        'uuml',
     1065        'yacute',
     1066        'thorn',
     1067        'yuml',
     1068        'quot',
     1069        'amp',
     1070        'lt',
     1071        'gt',
     1072        'apos',
     1073        'OElig',
     1074        'oelig',
     1075        'Scaron',
     1076        'scaron',
     1077        'Yuml',
     1078        'circ',
     1079        'tilde',
     1080        'ensp',
     1081        'emsp',
     1082        'thinsp',
     1083        'zwnj',
     1084        'zwj',
     1085        'lrm',
     1086        'rlm',
     1087        'ndash',
     1088        'mdash',
     1089        'lsquo',
     1090        'rsquo',
     1091        'sbquo',
     1092        'ldquo',
     1093        'rdquo',
     1094        'bdquo',
     1095        'dagger',
     1096        'Dagger',
     1097        'permil',
     1098        'lsaquo',
     1099        'rsaquo',
     1100        'euro',
     1101        'fnof',
     1102        'Alpha',
     1103        'Beta',
     1104        'Gamma',
     1105        'Delta',
     1106        'Epsilon',
     1107        'Zeta',
     1108        'Eta',
     1109        'Theta',
     1110        'Iota',
     1111        'Kappa',
     1112        'Lambda',
     1113        'Mu',
     1114        'Nu',
     1115        'Xi',
     1116        'Omicron',
     1117        'Pi',
     1118        'Rho',
     1119        'Sigma',
     1120        'Tau',
     1121        'Upsilon',
     1122        'Phi',
     1123        'Chi',
     1124        'Psi',
     1125        'Omega',
     1126        'alpha',
     1127        'beta',
     1128        'gamma',
     1129        'delta',
     1130        'epsilon',
     1131        'zeta',
     1132        'eta',
     1133        'theta',
     1134        'iota',
     1135        'kappa',
     1136        'lambda',
     1137        'mu',
     1138        'nu',
     1139        'xi',
     1140        'omicron',
     1141        'pi',
     1142        'rho',
     1143        'sigmaf',
     1144        'sigma',
     1145        'tau',
     1146        'upsilon',
     1147        'phi',
     1148        'chi',
     1149        'psi',
     1150        'omega',
     1151        'thetasym',
     1152        'upsih',
     1153        'piv',
     1154        'bull',
     1155        'hellip',
     1156        'prime',
     1157        'Prime',
     1158        'oline',
     1159        'frasl',
     1160        'weierp',
     1161        'image',
     1162        'real',
     1163        'trade',
     1164        'alefsym',
     1165        'larr',
     1166        'uarr',
     1167        'rarr',
     1168        'darr',
     1169        'harr',
     1170        'crarr',
     1171        'lArr',
     1172        'uArr',
     1173        'rArr',
     1174        'dArr',
     1175        'hArr',
     1176        'forall',
     1177        'part',
     1178        'exist',
     1179        'empty',
     1180        'nabla',
     1181        'isin',
     1182        'notin',
     1183        'ni',
     1184        'prod',
     1185        'sum',
     1186        'minus',
     1187        'lowast',
     1188        'radic',
     1189        'prop',
     1190        'infin',
     1191        'ang',
     1192        'and',
     1193        'or',
     1194        'cap',
     1195        'cup',
     1196        'int',
     1197        'sim',
     1198        'cong',
     1199        'asymp',
     1200        'ne',
     1201        'equiv',
     1202        'le',
     1203        'ge',
     1204        'sub',
     1205        'sup',
     1206        'nsub',
     1207        'sube',
     1208        'supe',
     1209        'oplus',
     1210        'otimes',
     1211        'perp',
     1212        'sdot',
     1213        'lceil',
     1214        'rceil',
     1215        'lfloor',
     1216        'rfloor',
     1217        'lang',
     1218        'rang',
     1219        'loz',
     1220        'spades',
     1221        'clubs',
     1222        'hearts',
     1223        'diams'
     1224        );
     1225
     1226        $i = $matches[1];
     1227        return ( ( ! in_array($i, $names) ) ? "&$i;" : "&$i;" );
     1228}
     1229
     1230/**
     1231 * Callback for wp_kses_normalize_entities() regular expression.
     1232 *
    9651233 * This function helps wp_kses_normalize_entities() to only accept 16 bit values
    9661234 * and nothing more for &#number; entities.
    9671235 *
     
    9721240 * @return string Correctly encoded entity
    9731241 */
    9741242function wp_kses_normalize_entities2($matches) {
    975         if ( ! isset($matches[1]) || empty($matches[1]) )
     1243        if ( empty($matches[1]) )
    9761244                return '';
    9771245
    9781246        $i = $matches[1];
     
    9911259 * @return string Correctly encoded entity
    9921260 */
    9931261function wp_kses_normalize_entities3($matches) {
    994         if ( ! isset($matches[2]) || empty($matches[2]) )
     1262        if ( empty($matches[2]) )
    9951263                return '';
    9961264
    9971265        $hexchars = $matches[2];