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/ConsoleRequest.class.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
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
 * AgaviConsoleRequest provides support for console-only request information
20
 * such as command-line parameters.
21
 *
22
 * @package    agavi
23
 * @subpackage request
24
 *
25
 * @copyright  Authors
26
 * @copyright  The Agavi Project
27
 *
28
 * @since      0.9.0
29
 *
30
 * @version    $Id$
31
 */
32
class ConsoleRequest extends Request
33
{
34
    /**
35
     * @var        string The command given on the command line (without parameters)
36
     */
37
    protected $input = null;
38
39
    /**
40
     * Constructor.
41
     *
42
     * @author     David Zülke <[email protected]>
43
     * @since      1.0.0
44
     */
45
    public function __construct()
46
    {
47
        parent::__construct();
48
        $this->setParameters(array(
49
            'request_data_holder_class' => 'AgaviConsoleRequestDataHolder',
50
        ));
51
    }
52
53
    /**
54
     * Initialize this Request.
55
     *
56
     * @param      Context $context An Context instance.
57
     * @param      array   $parameters An associative array of initialization parameters.
58
     *
59
     * @throws     <b>AgaviInitializationException</b> If an error occurs while
60
     *                                                 initializing this Request.
61
     *
62
     * @author     David Zülke <[email protected]>
63
     * @since      1.0.0
64
     */
65
    public function initialize(Context $context, array $parameters = array())
66
    {
67
        parent::initialize($context, $parameters);
68
        
69
        $argv = self::getSourceValue('argv', array());
70
        // get rid of the script name
71
        array_shift($argv);
72
        
73
        $parameters = array();
74
        $input = array();
75
        
76
        $prev = '';
77
        foreach ($argv as $arg) {
78
            if ($arg[0] == '-') {
79
                // name
80
                $parameters[$arg] = true;
81
            } else {
82
                if ($prev && $prev[0] == '-') {
83
                    $parameters[$prev] = $arg;
84
                } else {
85
                    $input[] = $arg;
86
                }
87
            }
88
            $prev = $arg;
89
        }
90
        
91
        $files = array();
92
        if ($this->getParameter('read_stdin', true) && defined('STDIN') && ($stdinMeta = stream_get_meta_data(STDIN)) && !$stdinMeta['seekable']) {
93
            // if stream_get_meta_data() reports STDIN as not seekable, that means something was piped into our process, and we should put that into a file
94
            // the alternative method to determine this is via posix_isatty(STDIN) which returns false in the same situation, but that requires the posix extension and also doesn't work on Windows
95
            $stdinName = $this->getParameter('stdin_file_name', 'stdin_file');
96
            
97
            $ufc = $this->getParameter('uploaded_file_class', 'AgaviUploadedFile');
98
            $files = array(
99
                $stdinName => new $ufc(array(
100
                    'name' => $stdinName,
101
                    'type' => 'application/octet-stream',
102
                    'size' => -1, // we're not buffering, so -1 is a good choice probably (better than 0 anyway)
103
                    'stream' => STDIN,
104
                    'error' => UPLOAD_ERR_OK,
105
                    'is_uploaded_file' => false,
106
                ))
107
            );
108
        }
109
110
        $rdhc = $this->getParameter('request_data_holder_class');
111
        $this->setRequestData(new $rdhc(array(
112
            constant("$rdhc::SOURCE_PARAMETERS") => array(),
113
            constant("$rdhc::SOURCE_FILES") => $files,
114
        )));
115
        $rd = $this->getRequestData();
116
        
117
        foreach ($parameters as $name => $value) {
118
            $rd->setParameter(substr($name, 1), $value);
119
        }
120
        
121
        $this->input = implode(' ', $input);
122
        
123
        $this->setMethod($this->getParameter('default_method', 'read'));
124
    }
125
    
126
    /**
127
     * Get the command given on the command line (without parameters)
128
     *
129
     * @return     string The command.
130
     *
131
     * @author     David Zülke <[email protected]>
132
     * @since      1.0.0
133
     */
134
    public function getInput()
135
    {
136
        return $this->input;
137
    }
138
139
    /**
140
     * Do any necessary startup work after initialization.
141
     *
142
     * This method is not called directly after initialize().
143
     *
144
     * @author     David Zülke <[email protected]>
145
     * @since      1.0.0
146
     */
147
    public function startup()
0 ignored issues
show
startup uses the super-global variable $_SERVER 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...
startup uses the super-global variable $_ENV 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...
startup uses the super-global variable $GLOBALS 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...
148
    {
149
        parent::startup();
150
        
151
        if ($this->getParameter('unset_input', true)) {
152
            $_SERVER['argv'] = $_ENV['argv'] = $GLOBALS['argv'] = array();
153
            $_SERVER['argc'] = $_ENV['argc'] = $GLOBALS['argc'] = 0;
154
        }
155
    }
156
}
157