Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Security: Mitigate HTTPoxy vulnerability (#23)
Browse files Browse the repository at this point in the history
This mitigates the HTTPoxy vulnerability, see https://httpoxy.org/.

Related CVE: CVE-2016-5385.
  • Loading branch information
kelunik authored and theofidry committed Feb 12, 2018
1 parent 50e137d commit dcb0860
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,15 @@ protected function getMergedStreamContext($url)
{
$options = $this->options;

// Handle system proxy
if (!empty($_SERVER['HTTP_PROXY']) || !empty($_SERVER['http_proxy'])) {
// Some systems seem to rely on a lowercased version instead...
$proxy = parse_url(!empty($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY']);
// See CVE-2016-5385, due to (emulation of) header copying with PHP web SAPIs into HTTP_* variables,
// HTTP_PROXY can be set by an user to any value he wants by setting the Proxy header.
// Mitigate the vulnerability by only allowing CLI SAPIs to use HTTP(S)_PROXY environment variables.
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
// Handle system proxy
if (!empty($_SERVER['HTTP_PROXY']) || !empty($_SERVER['http_proxy'])) {
// Some systems seem to rely on a lowercased version instead...
$proxy = parse_url(!empty($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY']);
}
}

if (!empty($proxy)) {
Expand Down

0 comments on commit dcb0860

Please sign in to comment.