SECURITY: Work around CURL insanity breaking POST parameters that start with '@'
authorRoan Kattouw <roan.kattouw@gmail.com>
Fri, 6 Nov 2015 20:55:16 +0000 (12:55 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Fri, 18 Dec 2015 09:22:30 +0000 (01:22 -0800)
commite95721aae1daad4503eb23d87a114f363b324442
tree5a12ead702b2164bd46c63d4056a663238c1bab7
parentf5db0b307b45cbd236e4426440653e697ef4cf80
SECURITY: Work around CURL insanity breaking POST parameters that start with '@'

CURL has a "feature" where passing array( 'foo' => '@bar' )
in CURLOPT_POSTFIELDS results in the contents of the file named "bar"
being POSTed. This makes it impossible to POST the literal string "@bar",
because array( 'foo' => '%40bar' ) gets double-encoded to foo=%2540bar.

Disable this "feature" by setting CURLOPT_SAFE_UPLOAD to true,
if available. According to the PHP manual, this option became
available in 5.5 and started defaulting to true in 5.6.
However, we support versions as low as 5.3, and this option
doesn't exist at all in 5.6.99-hhvm, which we run in production.

For versions where this option is not available (pre-5.5 versions
and HHVM), serialize POSTFIELDS arrays to strings. This works
around the issue because the '@' "feature" only works
for arrays, not strings, as of PHP 5.2. (We don't support pre-5.2
versions, and I've verified 5.6.99-hhvm behaves this way as well.)

Bug: T118032
Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
Change-Id: I3f996e2eb87c7bd3b94ca9d3cc14a3e12f34f241
includes/HttpFunctions.php
includes/libs/MultiHttpClient.php