Issues (43)

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/SimpleUPS/RegionValidate/Request.php (4 issues)

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 namespace SimpleUPS\RegionValidate;
2
3
use \SimpleUPS\Api\MissingParameterException;
4
5
use \SimpleUPS\Address;
6
7
use \SimpleUPS\UPS;
8
9
/**
10
 * @internal
11
 */
12
class Request extends \SimpleUPS\Api\Request
13
{
14
    private
15
        /* @var Address $address */
16
        $address;
17
18
    public function __construct($debug = null)
19
    {
20
        parent::__construct($debug);
21
22
        $this->responseClass = false;
23
    }
24
25
    /**
26
     * Determine which API call will be made
27
     * @return string
28
     */
29
    public function getUrl()
30
    {
31
        return $this->getDebug() ? 'https://wwwcie.ups.com/ups.app/xml/AV' : 'https://onlinetools.ups.com/ups.app/xml/AV';
32
    }
33
34
    /**
35
     * Build the validate address request
36
     * @return string
37
     * @throws \SimpleUPS\Api\MissingParameterException
38
     */
39
    public function buildXml()
40
    {
41
        if (serialize($this->getAddress()) == serialize(new Address())) {
42
            throw new MissingParameterException(
43
                'Address requires a Country code, Postal code, and either a City or State\Province code'
44
            );
45
        }
46
47
        if ($this->getAddress()->getCountryCode() === null) {
48
            throw new MissingParameterException('Address requires a Country code');
49
        }
50
51
        if ($this->getAddress()->getPostalCode() === null) {
52
            throw new MissingParameterException('Address requires a Postal code');
53
        }
54
55
        $dom = new \DomDocument('1.0');
56
        $dom->formatOutput = $this->getDebug();
57
        $dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest'));
58
        $addressRequestLang = $dom->createAttribute('xml:lang');
59
        $addressRequestLang->value = parent::getXmlLang();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getXmlLang() instead of buildXml()). Are you sure this is correct? If so, you might want to change this to $this->getXmlLang().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
60
        $addressRequest->appendChild($request = $dom->createElement('Request'));
61
        $request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
62
        $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
63
        $transactionReference->appendChild($dom->createElement('XpciVersion', $this->getXpciVersion()));
64
65
        $request->appendChild($dom->createElement('RequestAction', 'AV'));
66
        $addressRequest->appendChild($address = $dom->createElement('Address'));
67
68
        if ($this->getAddress()->getCity() != null) {
69
            $address->appendChild($dom->createElement('City', $this->getAddress()->getCity()));
70
        }
71
72
        if ($this->getAddress()->getStateProvinceCode() != null) {
73
            $address->appendChild(
74
                $dom->createElement('StateProvinceCode', $this->getAddress()->getStateProvinceCode())
75
            );
76
        }
77
78
        if ($this->getAddress()->getPostalCode() != null) {
79
            $address->appendChild($dom->createElement('PostalCode', $this->getAddress()->getPostalCode()));
80
        }
81
        $address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode()));
82
83
        $xml = parent::buildAuthenticationXml() . $dom->saveXML();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (buildAuthenticationXml() instead of buildXml()). Are you sure this is correct? If so, you might want to change this to $this->buildAuthenticationXml().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
84
85
        return $xml;
86
    }
87
88
    /**
89
     * Send a request to the API and get region rankings for the provided address
90
     * @return Response
91
     */
92 View Code Duplication
    public function sendRequest()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        $xml = parent::sendRequest();
95
96
        $responseClass = new \SimpleUPS\RegionValidate\Response($this->getAddress());
97
        $response = $responseClass->fromXml($xml);
0 ignored issues
show
It seems like $xml defined by parent::sendRequest() on line 94 can also be of type object<SimpleUPS\Api\Response>; however, SimpleUPS\RegionValidate\Response::fromXml() does only seem to accept object<SimpleXMLElement>, 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...
98
99
        return $response;
100
    }
101
102
    /**
103
     * @param \SimpleUPS\Address $address
104
     */
105
    public function setAddress(Address $address)
106
    {
107
        $this->address = $address;
108
    }
109
110
    /**
111
     * @return Address
112
     */
113
    public function getAddress()
114
    {
115
        return $this->address;
116
    }
117
}