Ticket #17490: 17490-2.diff

File 17490-2.diff, 1.7 KB (added by simonwheatley, 16 months ago)

Handle redirections outside Curl

Line 
1Index: wp-includes/class-http.php
2===================================================================
3--- /wp-includes/class-http.php (revision 19740)
4+++ /wp-includes/class-http.php (working copy)
5@@ -1042,7 +1042,7 @@
6                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, ( $ssl_verify === true ) ? 2 : false );
7                curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
8                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
9-               curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
10+               curl_setopt( $handle, CURLOPT_MAXREDIRS, 0 );
11 
12                switch ( $r['method'] ) {
13                        case 'HEAD':
14@@ -1074,9 +1074,9 @@
15                        curl_setopt( $handle, CURLOPT_FILE, $stream_handle );
16                }
17 
18-               // The option doesn't work with safe mode or when open_basedir is set.
19-               if ( !ini_get('safe_mode') && !ini_get('open_basedir') && 0 !== $r['_redirection'] )
20-                       curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
21+               // The option doesn't work with safe mode or when open_basedir is set, and there's a
22+               // bug #17490 with redirected POST requests, so handle redirections outside Curl.
23+               curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );
24 
25                if ( !empty( $r['headers'] ) ) {
26                        // cURL expects full header strings in each element
27@@ -1130,7 +1130,7 @@
28                        fclose( $stream_handle );
29 
30                // See #11305 - When running under safe mode, redirection is disabled above. Handle it manually.
31-               if ( ! empty( $theHeaders['headers']['location'] ) && ( ini_get( 'safe_mode' ) || ini_get( 'open_basedir' ) ) && 0 !== $r['_redirection'] ) {
32+               if ( ! empty( $theHeaders['headers']['location'] ) && 0 !== $r['_redirection'] ) {
33                        if ( $r['redirection']-- > 0 ) {
34                                return $this->request( $theHeaders['headers']['location'], $r );
35                        } else {