WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 21 months ago

#24182 closed defect (bug)

WP_Http_Fsockopen fails when requesting an IP based URL with an explicit Host header — at Version 1

Reported by: friedcell Owned by:
Milestone: 3.7 Priority: normal
Severity: normal Version: 2.7
Component: HTTP API Keywords: needs-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

When requesting a resource with a IP based URL and an explicitly set Host header fsockopen fails.

wp_remote_post():

$url = http://72.233.69.89/1.1/verify-key
$args = Array
(
    [body] => key=xxxxxxxxxxxx&blog=http%3A%2F%2Ffriedcell.si%2Foutbreak
    [headers] => Array
        (
            [Content-Type] => application/x-www-form-urlencoded; charset=UTF-8
            [Host] => rest.akismet.com
            [User-Agent] => WordPress/3.5.1 | Akismet/2.5.7
        )

    [httpversion] => 1.0
    [timeout] => 15
)

WP_Http_Fsockopen $strHeaders just before fwrite:

POST /1.1/verify-key HTTP/1.0
Host: 72.233.69.89
User-agent: WordPress/3.5.1 | Akismet/2.5.7
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: rest.akismet.com
Accept-Encoding: deflate;q=1.0, compress;q=0.5
Content-Length: 58

key=xxxxxxxxxxxx&blog=http%3A%2F%2Ffriedcell.si%2Foutbreak

The request fails as the first Host header is used.

When $arrURL['host'] is an IP and there is a Host header in $r['headers'], the Host header should not be added from the URL (http://core.trac.wordpress.org/browser/trunk/wp-includes/class-http.php#L706) so that the explicitly specified Host header is used.

Change History (1)

comment:1 @SergeyBiryukov2 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.