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/ToneAnalyzer/Message/AnalyzeToneRequest.php (3 issues)

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
 * Analyze Tone Request
4
 */
5
namespace IBM\Watson\Service\ToneAnalyzer\Message;
6
7
use GuzzleHttp\Exception\ClientException;
8
use GuzzleHttp\Psr7\Request;
9
use IBM\Watson\Common\Exception\AuthException;
10
use IBM\Watson\Common\Message\AbstractRequest;
11
12
/**
13
 * Analyze Tone Request
14
 *
15
 * @see IBM\Watson\Common\Message\AbstractRequest
16
 */
17
class AnalyzeToneRequest extends AbstractRequest
18
{
19
    /**
20
     * Tone analyzer API url
21
     *
22
     * @var string
23
     */
24
    protected $endpoint = 'https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone';
25
26
    /**
27
     * Get API endpoint
28
     *
29
     * @return string
30
     */
31
    public function getEndpoint()
32
    {
33
        return $this->endpoint;
34
    }
35
36
    /**
37
     * Get data to be sent with the request
38
     *
39
     * @return array required request data
40
     */
41
    public function getData()
42
    {
43
        return [
44
            'username'  => $this->getUsername(),
45
            'password'  => $this->getPassword(),
46
            'version'   => $this->getVersion(),
47
            'text'      => $this->getText(),
48
        ];
49
    }
50
51
    /**
52
     * Send request with data
53
     *
54
     * @param mixed $data
55
     * @throws AuthException
56
     * @throws \Exception
57
     *
58
     * @return \IBM\Watson\Service\ToneAnalyzer\Message\AnalyzeToneResponse
59
     */
60
    public function sendData($data)
61
    {
62
        $request = new Request(
63
            'GET',
64
            $this->getEndpoint() . '?' . http_build_query(['version' => $data['version'], 'text' => $data['text']]),
65
            ['Authorization' => 'Basic ' . base64_encode($data['username'] . ':' . $data['password'])]
66
        );
67
68
        try {
69
            $response = $this->httpClient->send($request);
70
71
            if ($response->getStatusCode() != 200) {
72
                throw new \Exception($response->getBody()->getContents(), $response->getStatusCode());
73
            }
74
        } catch (ClientException $e) {
75
            switch ($e->getCode()) {
76
                case 401:
77
                    throw new AuthException('Invalid credentials provided');
78
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
79
                case 400:
80
                    throw new \InvalidArgumentException('Missing a required parameter or invalid parameter value.');
81
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
82
                default:
83
                    throw $e;
84
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
85
            }
86
        }
87
88
        return $this->response = new AnalyzeToneResponse($this, $response->getBody());
89
    }
90
91
    /**
92
     * Set API version
93
     *
94
     * @param $value
95
     * @return AbstractRequest
96
     */
97
    public function setVersion($value)
98
    {
99
        return $this->setParameter('version', $value);
100
    }
101
102
    /**
103
     * Set API version
104
     *
105
     * @return mixed
106
     */
107
    public function getVersion()
108
    {
109
        return $this->getParameter('version');
110
    }
111
112
    /**
113
     * Set text to analyze
114
     *
115
     * @param $value
116
     * @return AbstractRequest
117
     */
118
    public function setText($value)
119
    {
120
        return $this->setParameter('text', $value);
121
    }
122
123
    /**
124
     * Get text to analyze
125
     *
126
     * @return mixed
127
     */
128
    public function getText()
129
    {
130
        return $this->getParameter('text');
131
    }
132
}
133