Transport\Curl/Fsockopen: add input validation #629
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Transport\Curl/Fsockopen::request(): add input validation
This commit adds input validation to the
Curl::request()
and theFsockopen::request()
methods along the same lines as added toRequests::request()
.$url
parameter is validated to allow for a string or Stringable (Iri) object.$headers
parameter is validated to allow only an array for consistency between both transport classes.$data
parameter already had (looser) input validation. This has been tightened up to only allow for the declared supported types, array and string (and null).$options
parameter is validated to allow only an array - same as inRequests::request()
.Includes:
$url
as a stringable object is safeguarded.$data
parameter validation to be in line with the new validation.Transport\Curl/Fsockopen::request_multiple(): add input validation
This commit adds input validation to the
Curl::request_multiple()
and theFsockopen::request_multiple()
methods along the same lines as added toRequests::request_multiple()
.$requests
, arrays and iterable objects with array access should be accepted based on how the parameter is used within this class.$options
parameter is validated to allow only an array - same as inRequests::request()
.Includes aligning the behaviour when receiving an empty
$requests
array between theCurl
and theFsockopen
classes and returning an empty array in that case.Includes adding perfunctory tests for the new exceptions.
Regarding the other
public
methods inCurl
:public
, theget_subrequest_handle()
andprocess_response()
methods look to be intended for internal use only.stream_headers()
andstream_body()
. Note: these methods both take a$handle
parameter which is subsequently unused. I imagine this was to allow for overloaded methods to receive the$handle
, but the class has becomefinal
now (after investigation and finding no extended classes), so these methods can no be overloaded.I think it may be a good idea to deprecate the public methods in a future minor in favour of
protected
/private
replacements which only receive the parameters which are actually use.test()
method for which the$capabilities
parameter is only used after anisset()
on the keys used, so this is safe as-is.public
methods do not take parameters.Regarding the other
public
methods inFsockopen
:connect_error_handler()
method is an error handler and should not be called directly.public
, theverify_certificate_from_context()
method looks to be intended for internal use only.test()
method for which the$capabilities
parameter is only used after anisset()
on the keys used, so this is safe as-is.