Issues (1131)

Security Analysis    not enabled

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/request/WebserviceRequest.class.php (2 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
2
namespace Agavi\Request;
3
4
// +---------------------------------------------------------------------------+
5
// | This file is part of the Agavi package.                                   |
6
// | Copyright (c) 2005-2011 the Agavi Project.                                |
7
// |                                                                           |
8
// | For the full copyright and license information, please view the LICENSE   |
9
// | file that was distributed with this source code. You can also view the    |
10
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
11
// |   vi: set noexpandtab:                                                    |
12
// |   Local Variables:                                                        |
13
// |   indent-tabs-mode: t                                                     |
14
// |   End:                                                                    |
15
// +---------------------------------------------------------------------------+
16
use Agavi\Core\Context;
17
18
/**
19
 * AgaviWebserviceRequest is the base class for Web Service requests
20
 *
21
 * @package    agavi
22
 * @subpackage request
23
 *
24
 * @author     David Zülke <[email protected]>
25
 * @copyright  Authors
26
 * @copyright  The Agavi Project
27
 *
28
 * @since      0.11.0
29
 *
30
 * @version    $Id$
31
 */
32
abstract class WebserviceRequest extends Request
33
{
34
    /**
35
     * @var        string The Input Data.
36
     */
37
    protected $input = '';
38
    
39
    /**
40
     * @var        string The method called by the web service request.
41
     */
42
    protected $invokedMethod = '';
43
    
44
    /**
45
     * Constructor.
46
     *
47
     * @author     David Zülke <[email protected]>
48
     * @since      0.11.0
49
     */
50
    public function __construct()
51
    {
52
        parent::__construct();
53
        $this->setParameters(array(
54
            'request_data_holder_class' => 'AgaviWebserviceRequestDataHolder',
55
        ));
56
    }
57
    
58
    /**
59
     * Initialize this Request.
60
     *
61
     * @param      Context $context    A Context instance.
62
     * @param      array   $parameters An associative array of initialization parameters.
63
     *
64
     * @throws     <b>AgaviInitializationException</b> If an error occurs while
65
     *                                                 initializing this Request.
66
     *
67
     * @author     David Zülke <[email protected]>
68
     * @since      0.11.0
69
     */
70
    public function initialize(Context $context, array $parameters = array())
0 ignored issues
show
initialize uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
71
    {
72
        // empty $_POST just to be sure
73
        $_POST = array();
74
        
75
        // grab the POST body
76
        $this->input = file_get_contents('php://input');
77
        
78
        parent::initialize($context, $parameters);
79
    }
80
    
81
    /**
82
     * Get the input data, usually the request from the POST body.
83
     *
84
     * @return     string The input data.
85
     *
86
     * @author     David Zülke <[email protected]>
87
     * @since      0.11.0
88
     */
89
    public function getInput()
90
    {
91
        return $this->input;
92
    }
93
    
94
    /**
95
     * Set the input data. Useful for debugging purposes.
96
     *
97
     * @param      string $input The input data.
98
     *
99
     * @author     David Zülke <[email protected]>
100
     * @since      0.11.0
101
     */
102
    public function setInput($input)
103
    {
104
        $this->input = $input;
105
    }
106
    
107
    /**
108
     * Set the name of the method called by the web service request.
109
     *
110
     * @return     string $method A method name.
111
     *
112
     * @author     David Zülke <[email protected]>
113
     * @since      0.11.0
114
     */
115
    public function setInvokedMethod($method)
116
    {
117
        $this->invokedMethod = $method;
118
        
119
        // let the routing update its input
120
        $this->context->getRouting()->updateInput();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Agavi\Routing\Routing as the method updateInput() does only exist in the following sub-classes of Agavi\Routing\Routing: Agavi\Routing\SoapRouting, Agavi\Routing\WebserviceRouting, Agavi\Routing\XmlrpcepiphpRouting. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
121
    }
122
    
123
    /**
124
     * Get the name of the method called by the web service request.
125
     *
126
     * @return     string A method name.
127
     *
128
     * @author     David Zülke <[email protected]>
129
     * @since      0.11.0
130
     */
131
    public function getInvokedMethod()
132
    {
133
        return $this->invokedMethod;
134
    }
135
}
136