Skip to content
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

Vulnerability: SafeCurl::Execute() "Check if called statically" check seems brittle, can cause explicit $options to be disregarded #26

Open
justinsteven opened this issue Oct 4, 2019 · 0 comments

Comments

@justinsteven
Copy link

public static function execute($url, $curlHandle = null, Options $options = null) {
//Check if we've been called staticly or not
if (isset($this) && get_class($this) == __CLASS__) {
$safeCurl = $this;
//Get the cURL handle, if it wasn't passed in
if (!is_resource($curlHandle) || get_resource_type($curlHandle) != 'curl') {
$curlHandle = $this->getCurlHandle();
}
} else {
$safeCurl = new SafeCurl($curlHandle, $options);
}

This "Check if called statically" check is brittle in my testing.

For example, the following PHPUnit test fails:

    public function testSafeCurlThrowsOnNonWhitelistedDomain() {
        $curlHandle = curl_init();
        $options = new Options();
        $options->setList('whitelist', array('www.google.com'), 'domain');
        $safeCurl = new SafeCurl($curlHandle, $options);
        $this->expectException(InvalidDomainException::Class);
        $safeCurl->execute('http://www.gstatic.com/generate_204', $curlHandle);
    }
Failed asserting that exception of type "fin1te\SafeCurl\Exception\InvalidURLException\InvalidDomainException" is thrown.

The "else" branch in the "Check if I'm being called statically" conditional is being taken. There's something wrong with the check when it's done from the context of a PHPUnit test. Perhaps this is related to the comments in https://stackoverflow.com/a/1858577 and it could happen in other PHP contexts as well?

As such, a temporary SafeCurl is being created. Since I'm passing a curlHandle to execute() the creation succeeds. Since I'm not passing an Options to execute() the creation uses a default Options object which doesn't have my explicit whitelist set.

This causes the HTTP request to succeed, when it should fail because "www.gstatic.com" is not on the whitelist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant