Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Command/ApiCallCommand.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
namespace Devhelp\PiwikBundle\Command;
5
6
use Devhelp\Piwik\Api\Method\Method;
7
use Devhelp\PiwikBundle\Command\Param\MethodFinder;
8
use Psr\Http\Message\ResponseInterface;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Logger\ConsoleLogger;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
class ApiCallCommand extends ContainerAwareCommand
17
{
18
19
    /**
20
     * @var ConsoleLogger
21
     */
22
    private $logger;
23
24
    protected function configure()
25
    {
26
        // @codingStandardsIgnoreStart
27
        $this
28
            ->setName('devhelp_piwik:api:call')
29
            ->setDescription('Calls piwik api method')
30
            ->addArgument(
31
                'method',
32
                InputArgument::REQUIRED,
33
                'Method to call. Can be either a service id (without @) or method name (like "Actions.getPageUrls")'
34
            )
35
            ->addOption(
36
                'params',
37
                'p',
38
                InputOption::VALUE_OPTIONAL,
39
                'Method parameters as string (must be valid for parse_str function). '.
40
                'They will be merged with params from method service (if it has any) and will override existing ones if names are the same'
41
            )
42
            ->addOption(
43
                'api',
44
                null,
45
                InputOption::VALUE_OPTIONAL,
46
                'Api that will be used to call the method (name from configuration). '.
47
                'If not specified default api is used. Is ignored if "method" is passed as a service'
48
            )->addOption(
49
                'show-response',
50
                'r',
51
                InputOption::VALUE_NONE,
52
                'If set then response is logged. '.
53
                'Verbosity level must be at least -vv and used together with this option in order to display the response'
54
            )
55
            ->setHelp(<<<HELP
56
The <info>%command.name%</info> command calls Piwik API method.
57
58
Method can be either service id or method name:
59
60
  <info>php %command.full_name% SitesManager.getAllSites</info>
61
  <info>php %command.full_name% my_method_service_id</info>
62
63
If method name is used then you can use <comment>--api</comment> to set api name from which the method is to be called (if not specified then default api is used):
64
65
  <info>php %command.full_name% SitesManager.getAllSites --api=reader</info>
66
67
Use <comment>--params</comment> in order to set call parameters (they will be merged with default params defined for the method service):
68
69
  <info>php %command.full_name% my_method_service_id --params='idSite=2&token_auth=MY_TOKEN'</info>
70
71
Use <comment>-vv</comment> in order to display relevant information about the ongoing request
72
73
  <info>php %command.full_name% my_method_service_id -vv</info>
74
75
Use <comment>--show-response</comment> together with <comment>-vv</comment> in order to display the response. <comment>Response must be PSR-7 compatible</comment>
76
77
  <info>php %command.full_name% my_method_service_id -vv --show-response</info>
78
79
HELP
80
            );
81
        // @codingStandardsIgnoreEnd
82
    }
83
84
    protected function execute(InputInterface $input, OutputInterface $output)
85
    {
86
        $methodArg = $input->getArgument('method');
87
        $apiOption = $input->getOption('api');
88
89
        $params = [];
90
91
        if ($input->hasOption('params')) {
92
            parse_str($input->getOption('params'), $params);
93
        }
94
95
        $this->logger = new ConsoleLogger($output);
96
97
        $method = $this->getMethod($methodArg, $apiOption);
98
99
        $callDetails = [];
100
        $callDetails[] = "Calling api...";
101
        $callDetails[] = "- method: ".$method->name();
102
        $callDetails[] = "- url: ".$method->url();
103
104
        if ($params) {
105
            $callDetails[] = "- extra params: ";
106
            $callDetails[] = var_export($params, true);
107
        }
108
109
        $this->logger->info(implode(PHP_EOL, $callDetails));
110
111
        $response = $method->call($params);
0 ignored issues
show
It seems like $params can also be of type null; however, Devhelp\Piwik\Api\Method\Method::call() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
112
113
        $resultDetails = [];
114
        $resultDetails[] = "Finished";
115
116
        if ($input->getOption('show-response') && $response instanceof ResponseInterface) {
117
            $resultDetails[] = "Response:";
118
            $resultDetails[] = "- status code: ".$response->getStatusCode();
119
            $resultDetails[] = "- body: ".$response->getBody()->getContents();
120
        }
121
122
        $this->logger->info(implode(PHP_EOL, $resultDetails));
123
    }
124
125
    /**
126
     * @param string $methodArg
127
     * @param string $apiOption
128
     * @return Method
129
     */
130
    private function getMethod($methodArg, $apiOption)
131
    {
132
        $methodFinder = new MethodFinder($this->getContainer(), $this->logger);
133
134
        return $methodFinder->find($methodArg, $apiOption);
135
    }
136
}
137