Ticket #53236: nonce-age-resolution.patch
| File nonce-age-resolution.patch, 4.6 KB (added by , 5 years ago) |
|---|
-
src/wp-includes/pluggable.php
a b 1160 1160 * @param int|string $action The nonce action. 1161 1161 * @param string $query_arg Optional. Key to check for nonce in `$_REQUEST`. Default '_wpnonce'. 1162 1162 * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, 1163 * 2 if the nonce is valid and generated between 12-24 hours ago.1163 * 2 if the nonce is valid and generated between 8-24 hours ago. 1164 1164 * False if the nonce is invalid. 1165 1165 */ 1166 1166 function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { … … 1179 1179 * 1180 1180 * @param string $action The nonce action. 1181 1181 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between 1182 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.1182 * 0-12 hours ago, 2 if the nonce is valid and generated between 8-24 hours ago. 1183 1183 */ 1184 1184 do_action( 'check_admin_referer', $action, $result ); 1185 1185 … … 1205 1205 * @param bool $die Optional. Whether to die early when the nonce cannot be verified. 1206 1206 * Default true. 1207 1207 * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, 1208 * 2 if the nonce is valid and generated between 12-24 hours ago.1208 * 2 if the nonce is valid and generated between 8-24 hours ago. 1209 1209 * False if the nonce is invalid. 1210 1210 */ 1211 1211 function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { … … 1232 1232 * 1233 1233 * @param string $action The Ajax nonce action. 1234 1234 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between 1235 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.1235 * 0-12 hours ago, 2 if the nonce is valid and generated between 8-24 hours ago. 1236 1236 */ 1237 1237 do_action( 'check_ajax_referer', $action, $result ); 1238 1238 … … 2129 2129 /** 2130 2130 * Returns the time-dependent variable for nonce creation. 2131 2131 * 2132 * A nonce has a lifespan of two ticks. Nonces in their second tick may be2133 * updated, e.g. by autosave.2132 * A nonce has a lifespan of six ticks. Nonces in their fourth tick onwards 2133 * may be updated, e.g. by autosave. 2134 2134 * 2135 2135 * @since 2.5.0 2136 2136 * … … 2146 2146 */ 2147 2147 $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS ); 2148 2148 2149 return ceil( time() / ( $nonce_life / 2) );2149 return ceil( time() / ( $nonce_life / 6 ) ); 2150 2150 } 2151 2151 endif; 2152 2152 … … 2154 2154 /** 2155 2155 * Verifies that a correct security nonce was used with time limit. 2156 2156 * 2157 * A nonce is valid for 24 hours (by default).2157 * A nonce is valid for at most 24 hours (by default). 2158 2158 * 2159 2159 * @since 2.0.3 2160 2160 * 2161 2161 * @param string $nonce Nonce value that was used for verification, usually via a form field. 2162 2162 * @param string|int $action Should give context to what is taking place and be the same when nonce was created. 2163 2163 * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago, 2164 * 2 if the nonce is valid and generated between 12-24 hours ago.2164 * 2 if the nonce is valid and generated between 8-24 hours ago. 2165 2165 * False if the nonce is invalid. 2166 2166 */ 2167 2167 function wp_verify_nonce( $nonce, $action = -1 ) { … … 2185 2185 } 2186 2186 2187 2187 $token = wp_get_session_token(); 2188 $i = wp_nonce_tick(); 2188 $tick = wp_nonce_tick(); 2189 $i = 0; 2189 2190 2190 // Nonce generated 0-12 hours ago. 2191 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 2192 if ( hash_equals( $expected, $nonce ) ) { 2193 return 1; 2194 } 2191 while ( $i < 6 ) { 2192 $expected = substr( wp_hash( "$tick|$action|$uid|$token", 'nonce' ), -12, 10 ); 2193 if ( hash_equals( $expected, $nonce ) ) { 2194 // Nonce generated 0-12 hours ago. 2195 if ( $i < 3 ) { 2196 return 1; 2197 } 2195 2198 2196 // Nonce generated 12-24 hours ago. 2197 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 2198 if ( hash_equals( $expected, $nonce ) ) { 2199 return 2; 2199 // Nonce generated 8-24 hours ago. 2200 return 2; 2201 } 2202 $tick--; 2203 $i++; 2200 2204 } 2201 2205 2202 2206 /** … … 2236 2240 } 2237 2241 2238 2242 $token = wp_get_session_token(); 2239 $ i= wp_nonce_tick();2243 $tick = wp_nonce_tick(); 2240 2244 2241 return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );2245 return substr( wp_hash( "$tick|$action|$uid|$token", 'nonce' ), -12, 10 ); 2242 2246 } 2243 2247 endif; 2244 2248