rattfieldnz /
shodan
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||
| 2 | |||||
|
0 ignored issues
–
show
|
|||||
| 3 | namespace RattfieldNz\Shodan\Libraries\Curl; |
||||
| 4 | |||||
| 5 | use Curl\Curl as PhpCurl; |
||||
| 6 | use RattfieldNz\Shodan\Libraries\Data\Data; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Class Curl. |
||||
| 10 | * |
||||
| 11 | * @category PHP |
||||
|
0 ignored issues
–
show
|
|||||
| 12 | * |
||||
| 13 | * @author Rob Attfield <[email protected]> |
||||
|
0 ignored issues
–
show
|
|||||
| 14 | * @license https://github.com/rattfieldnz/shodan/blob/master/LICENSE MIT |
||||
|
0 ignored issues
–
show
|
|||||
| 15 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | class Curl |
||||
| 17 | { |
||||
|
0 ignored issues
–
show
|
|||||
| 18 | private $_data; |
||||
|
0 ignored issues
–
show
|
|||||
| 19 | private $_defaultHeaders; |
||||
|
0 ignored issues
–
show
|
|||||
| 20 | private $_timeout; |
||||
|
0 ignored issues
–
show
|
|||||
| 21 | private $_curl; |
||||
|
0 ignored issues
–
show
|
|||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * Curl constructor. |
||||
| 25 | * |
||||
| 26 | * Set the needed properties to do a CURL request. |
||||
| 27 | * |
||||
| 28 | * @param Data $data Data to use when executing cURL. |
||||
| 29 | * @param int $timeout Timeout in seconds to complete a CURL request. Default is 10. |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | * |
||||
| 31 | * @throws \ErrorException Will throw an exception if PHP ext-curl is not installed. |
||||
| 32 | */ |
||||
| 33 | 4 | public function __construct(Data $data, int $timeout = 10) |
|||
|
0 ignored issues
–
show
|
|||||
| 34 | { |
||||
|
0 ignored issues
–
show
|
|||||
| 35 | 4 | if (!extension_loaded('curl')) { |
|||
|
0 ignored issues
–
show
|
|||||
| 36 | throw new \ErrorException( |
||||
| 37 | 'The cURL extensions is not loaded, make sure you have installed the cURL extension: https://php.net/manual/curl.setup.php' |
||||
|
0 ignored issues
–
show
|
|||||
| 38 | ); |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | 4 | $this->_curl = new PhpCurl(); |
|||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 42 | 4 | $this->_data = $data; |
|||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 43 | 4 | $this->_timeout = $timeout; |
|||
| 44 | 4 | $this->_setDefaultHeaders(); |
|||
| 45 | 4 | } |
|||
|
0 ignored issues
–
show
|
|||||
| 46 | |||||
| 47 | /** |
||||
| 48 | * Execute a CURL request, and return current object for further processing. |
||||
| 49 | * |
||||
| 50 | * @return PhpCurl |
||||
| 51 | */ |
||||
| 52 | 3 | public function execute(): PhpCurl |
|||
| 53 | { |
||||
|
0 ignored issues
–
show
|
|||||
| 54 | 3 | $this->_curl->setOpt(CURLOPT_RETURNTRANSFER, true); |
|||
|
0 ignored issues
–
show
|
|||||
| 55 | 3 | $this->_curl->setOpt(CURLOPT_CONNECTTIMEOUT, $this->_timeout); |
|||
| 56 | 3 | $this->_curl->setOpt(CURLOPT_HTTPHEADER, $this->_defaultHeaders); |
|||
| 57 | 3 | $this->_curl->setOpt(CURLOPT_SSL_VERIFYPEER, false); |
|||
|
0 ignored issues
–
show
|
|||||
| 58 | 3 | $this->_curl->setOpt(CURLOPT_SSL_VERIFYHOST, false); |
|||
|
0 ignored issues
–
show
|
|||||
| 59 | 3 | $this->_curl->get($this->_data->shodanApiUrl()); |
|||
| 60 | |||||
| 61 | 3 | return $this->_curl; |
|||
| 62 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 63 | |||||
| 64 | /** |
||||
| 65 | * Get the data retrieved from executing CURL request, in JSON format. |
||||
| 66 | * |
||||
| 67 | * @return array |
||||
| 68 | * |
||||
| 69 | * @see \RattfieldNz\SafeUrls\Libraries\Curl\Curl->execute(). |
||||
| 70 | */ |
||||
| 71 | 3 | public function getData() |
|||
| 72 | { |
||||
|
0 ignored issues
–
show
|
|||||
| 73 | 3 | $dataObject = $this->execute(); |
|||
| 74 | |||||
| 75 | 3 | $status = $dataObject->getHttpStatus(); |
|||
| 76 | |||||
| 77 | 3 | $response = $dataObject->error_code != 0 ? |
|||
|
0 ignored issues
–
show
|
|||||
| 78 | 1 | ['message' => $dataObject->error_message] : |
|||
|
0 ignored issues
–
show
|
|||||
| 79 | 3 | json_decode($dataObject->response, true); |
|||
|
0 ignored issues
–
show
It seems like
$dataObject->response can also be of type boolean and null; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 80 | |||||
| 81 | $data = [ |
||||
|
0 ignored issues
–
show
|
|||||
| 82 | 3 | 'status' => $status, |
|||
|
0 ignored issues
–
show
|
|||||
| 83 | 3 | 'response' => $response, |
|||
|
0 ignored issues
–
show
|
|||||
| 84 | ]; |
||||
|
0 ignored issues
–
show
|
|||||
| 85 | |||||
| 86 | 3 | return $data; |
|||
| 87 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 88 | |||||
| 89 | /** |
||||
| 90 | * Sets the default headers to use for CURL request. |
||||
| 91 | * |
||||
| 92 | * @return void |
||||
| 93 | */ |
||||
| 94 | 4 | private function _setDefaultHeaders(): void |
|||
| 95 | { |
||||
|
0 ignored issues
–
show
|
|||||
| 96 | 4 | $this->_defaultHeaders = [ |
|||
|
0 ignored issues
–
show
|
|||||
| 97 | 'Content-Type: application/json', |
||||
|
0 ignored issues
–
show
|
|||||
| 98 | 'Connection: Keep-Alive', |
||||
|
0 ignored issues
–
show
|
|||||
| 99 | ]; |
||||
|
0 ignored issues
–
show
|
|||||
| 100 | 4 | } |
|||
|
0 ignored issues
–
show
|
|||||
| 101 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 102 |