1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Schema Class for output data. |
4
|
|
|
*/ |
5
|
|
|
namespace Graviton\ProxyApiBundle\Processor; |
6
|
|
|
|
7
|
|
|
use Graviton\ProxyApiBundle\Helper\HttpHelper; |
8
|
|
|
use Graviton\ProxyApiBundle\Model\ProxyModel; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Before Proxy Request process and prepare data for orequest |
13
|
|
|
* |
14
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
16
|
|
|
* @link http://swisscom.ch |
17
|
|
|
*/ |
18
|
|
|
class PreProcessor implements PreProcessorInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Filter or change values of incoming request to be processed |
22
|
|
|
* |
23
|
|
|
* @param Request $originalRequest Incoming current request |
24
|
|
|
* @param HttpHelper $httpHelper Building the new request |
25
|
|
|
* @param ProxyModel $proxyModel Configuration model |
26
|
|
|
* @return HttpHelper |
27
|
|
|
*/ |
28
|
|
|
public function process( |
29
|
|
|
Request $originalRequest, |
30
|
|
|
HttpHelper $httpHelper, |
31
|
|
|
ProxyModel $proxyModel |
32
|
|
|
) { |
33
|
|
|
$httpHelper->setMethod($originalRequest->getMethod()); |
34
|
|
|
|
35
|
|
|
$queryParams = (array) $originalRequest->query->all(); |
36
|
|
|
|
37
|
|
|
// Query Params, it will remove unwanted params and map to new. |
38
|
|
|
if ($optParams = $proxyModel->getQueryParams()) { |
39
|
|
|
$newParamsString = http_build_query($optParams); |
40
|
|
|
foreach ($queryParams as $key => $value) { |
41
|
|
|
// Remove attempt to inject with %26 = & in value. |
42
|
|
|
$value = strpos($value, '&') !== false ? strstr($value, '&', true) : $value; |
43
|
|
|
$newParamsString = str_replace('%7B'.$key.'%7D', trim($value), $newParamsString); |
44
|
|
|
} |
45
|
|
|
parse_str($newParamsString, $queryParams); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Map additional params, append additional params |
49
|
|
|
if ($optParams = $proxyModel->getQueryAdditionals()) { |
50
|
|
|
foreach ($optParams as $key => $value) { |
51
|
|
|
$queryParams[$key] = $value; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Add to HTTP Query Params |
56
|
|
|
foreach ($queryParams as $name => $value) { |
|
|
|
|
57
|
|
|
$httpHelper->addQueryParams($name, $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $httpHelper; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.