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

PHP8 compatibility changes #30

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "fin1te/safecurl",
"name": "barmat/safecurl",
"description": "A drop-in replacement for 'curl_exec', designed to prevent SSRF attacks.",
"keywords": ["curl", "safecurl", "safe", "ssrf", "websec"],
"license": "MIT",
"authors": [
{
"name": "Matt Barry",
"email": "mattbarrah@gmail.com"
},
{
"name": "Jack W",
"email": "jack@fin1te.net"
Expand Down
28 changes: 10 additions & 18 deletions src/fin1te/SafeCurl/SafeCurl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace fin1te\SafeCurl;

use CurlHandle;
use fin1te\SafeCurl\Exception;
use fin1te\SafeCurl\Exception\InvalidURLException;
use fin1te\SafeCurl\Exception\InvalidURLException\InvalidDomainException;
Expand All @@ -12,7 +13,7 @@ class SafeCurl {
/**
* cURL Handle
*
* @var resource
* @var resource|CurlHandle
*/
private $curlHandle;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function getCurlHandle() {
* @param $curlHandle resource
*/
public function setCurlHandle($curlHandle) {
if (!is_resource($curlHandle) || get_resource_type($curlHandle) != 'curl') {
if (!((is_resource($curlHandle) && get_resource_type($curlHandle) === 'curl') || (class_exists('CurlHandle') && $curlHandle instanceof CurlHandle))) {
//Need a valid cURL resource, throw exception
throw new Exception("SafeCurl expects a valid cURL resource - '" . gettype($curlHandle) . "' provided.");
}
Expand All @@ -64,7 +65,7 @@ public function setCurlHandle($curlHandle) {
/**
* Gets Options
*
* @return SafeCurl\Options
* @return Options
*/
public function getOptions() {
return $this->options;
Expand All @@ -73,7 +74,7 @@ public function getOptions() {
/**
* Sets Options
*
* @param $options SafeCurl\Options
* @param $options Options
*/
public function setOptions(Options $options) {
$this->options = $options;
Expand All @@ -97,27 +98,18 @@ protected function init() {
}

/**
* Exectutes a cURL request, whilst checking that the
* Exectutes a cURL request, whilst checking that the
* URL abides by our whitelists/blacklists
*
* @param $url string
* @param $curlHandle resource optional - Incase called on an object rather than statically
* @param $options SafeCurl\Options optional
*
* @param $options Options optional
* @return bool
* @throws InvalidURLException
* @throws \fin1te\SafeCurl\Exception
*/
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);
}

$safeCurl = new SafeCurl($curlHandle, $options);

//Backup the existing URL
$originalUrl = $url;
Expand Down
2 changes: 1 addition & 1 deletion src/fin1te/SafeCurl/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function buildUrl($parts) {
: '';

$url .= (!empty($parts['path']))
? '/' . rawurlencode(substr($parts['path'], 1))
? str_replace('%2F', '/', rawurlencode($parts['path']))
: '';

//The query string is difficult to encode properly
Expand Down