-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CWE errors #58
Fix CWE errors #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,7 @@ function &getDebugAsXMLComment() | |
while (strpos($this->debug_str, '--')) { | ||
$this->debug_str = str_replace('--', '- -', $this->debug_str); | ||
} | ||
$ret = "<!--\n" . $this->debug_str . "\n-->"; | ||
$ret = "<!--\n" . $this->sanitize($this->debug_str) . "\n-->"; | ||
return $ret; | ||
} | ||
|
||
|
@@ -908,11 +908,15 @@ function getmicrotime() | |
function varDump($data) | ||
{ | ||
ob_start(); | ||
var_dump($data); | ||
var_dump($this->sanitize($data)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$ret_val = ob_get_contents(); | ||
ob_end_clean(); | ||
return $ret_val; | ||
} | ||
|
||
function sanitize($value) { | ||
return htmlspecialchars(strip_tags($value), ENT_COMPAT, 'utf-8'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running both |
||
} | ||
|
||
/** | ||
* represents the object as a string | ||
|
@@ -2714,13 +2718,13 @@ function setCredentials($username, $password, $authtype = 'basic', $digestReques | |
$A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; | ||
|
||
// H(A1) = MD5(A1) | ||
$HA1 = md5($A1); | ||
$HA1 = password_hash($A1, PASSWORD_DEFAULT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Digest Authentication is specified to use MD5 hashes, we can't simply substitute a different algorithm. |
||
|
||
// A2 = Method ":" digest-uri-value | ||
$A2 = $this->request_method . ':' . $this->digest_uri; | ||
|
||
// H(A2) | ||
$HA2 = md5($A2); | ||
$HA2 = password_hash($A2, PASSWORD_DEFAULT); | ||
|
||
// KD(secret, data) = H(concat(secret, ":", data)) | ||
// if qop == auth: | ||
|
@@ -2742,7 +2746,7 @@ function setCredentials($username, $password, $authtype = 'basic', $digestReques | |
$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2; | ||
} | ||
|
||
$hashedDigest = md5($unhashedDigest); | ||
$hashedDigest = password_hash($unhashedDigest, PASSWORD_DEFAULT); | ||
|
||
$opaque = ''; | ||
if (isset($digestRequest['opaque'])) { | ||
|
@@ -3871,11 +3875,11 @@ function service($data) | |
} else { | ||
$this->debug("In service, there is no WSDL"); | ||
header("Content-Type: text/html; charset=ISO-8859-1\r\n"); | ||
print "This service does not provide WSDL"; | ||
print $this->sanitize("This service does not provide WSDL"); | ||
} | ||
} elseif ($this->wsdl) { | ||
$this->debug("In service, return Web description"); | ||
print $this->wsdl->webDescription(); | ||
print $this->sanitize($this->wsdl->webDescription()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a huge breaking change: HTML documentation can be embedded in WSDL files, and this completely breaks its display. |
||
} else { | ||
$this->debug("In service, no Web description"); | ||
header("Content-Type: text/html; charset=ISO-8859-1\r\n"); | ||
|
@@ -4177,34 +4181,7 @@ function invoke_method() | |
$this->appendDebug($this->varDump($this->methodparams)); | ||
$this->debug("in invoke_method, calling '$this->methodname'"); | ||
if (!function_exists('call_user_func_array')) { | ||
if ($class == '') { | ||
$this->debug('in invoke_method, calling function using eval()'); | ||
$funcCall = "\$this->methodreturn = $this->methodname("; | ||
} else { | ||
if ($delim == '..') { | ||
$this->debug('in invoke_method, calling class method using eval()'); | ||
$funcCall = "\$this->methodreturn = " . $class . "::" . $method . "("; | ||
} else { | ||
$this->debug('in invoke_method, calling instance method using eval()'); | ||
// generate unique instance name | ||
$instname = "\$inst_" . time(); | ||
$funcCall = $instname . " = new " . $class . "(); "; | ||
$funcCall .= "\$this->methodreturn = " . $instname . "->" . $method . "("; | ||
} | ||
} | ||
if ($this->methodparams) { | ||
foreach ($this->methodparams as $param) { | ||
if (is_array($param) || is_object($param)) { | ||
$this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available'); | ||
return; | ||
} | ||
$funcCall .= "\"$param\","; | ||
} | ||
$funcCall = substr($funcCall, 0, -1); | ||
} | ||
$funcCall .= ');'; | ||
$this->debug('in invoke_method, function call: ' . $funcCall); | ||
@eval($funcCall); | ||
$this->debug('call_user_func_array not exists'); | ||
} else { | ||
if ($class == '') { | ||
$this->debug('in invoke_method, calling function using call_user_func_array()'); | ||
|
@@ -8433,7 +8410,7 @@ function __construct($cache_dir='.', $cache_lifetime=0) { | |
* @access private | ||
*/ | ||
function createFilename($wsdl) { | ||
return $this->cache_dir.'/wsdlcache-' . md5($wsdl); | ||
return $this->cache_dir.'/wsdlcache-' . password_hash($wsdl, PASSWORD_DEFAULT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a security hash, so |
||
} | ||
|
||
/** | ||
|
@@ -8497,15 +8474,15 @@ function get($wsdl) { | |
* @access private | ||
*/ | ||
function obtainMutex($filename, $mode) { | ||
if (isset($this->fplock[md5($filename)])) { | ||
if (isset($this->fplock[password_hash($filename, PASSWORD_DEFAULT)])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, this is not a secure hash, |
||
$this->debug("Lock for $filename already exists"); | ||
return false; | ||
} | ||
$this->fplock[md5($filename)] = fopen($filename.".lock", "w"); | ||
$this->fplock[password_hash($filename, PASSWORD_DEFAULT)] = fopen($filename.".lock", "w"); | ||
if ($mode == "r") { | ||
return flock($this->fplock[md5($filename)], LOCK_SH); | ||
return flock($this->fplock[password_hash($filename, PASSWORD_DEFAULT)], LOCK_SH); | ||
} else { | ||
return flock($this->fplock[md5($filename)], LOCK_EX); | ||
return flock($this->fplock[password_hash($filename, PASSWORD_DEFAULT)], LOCK_EX); | ||
} | ||
} | ||
|
||
|
@@ -8545,9 +8522,9 @@ function put($wsdl_instance) { | |
* @access private | ||
*/ | ||
function releaseMutex($filename) { | ||
$ret = flock($this->fplock[md5($filename)], LOCK_UN); | ||
fclose($this->fplock[md5($filename)]); | ||
unset($this->fplock[md5($filename)]); | ||
$ret = flock($this->fplock[password_hash($filename, PASSWORD_DEFAULT)], LOCK_UN); | ||
fclose($this->fplock[password_hash($filename, PASSWORD_DEFAULT)]); | ||
unset($this->fplock[password_hash($filename, PASSWORD_DEFAULT)]); | ||
if (! $ret) { | ||
$this->debug("Not able to release lock for $filename"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably just use
htmlspecialchars
directly, because we shouldn't be changing the value, just escaping it for the browser.