Issues (320)

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/php/Apix/HttpRequest.php (3 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
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix;
14
15
use Apix\Request,
16
    Apix\Input\InputInterface,
17
    Apix\Input\Xml,
18
    Apix\Input\Json;
19
20
class HttpRequest extends Request
21
{
22
    /**
23
     * List of supported input formats.
24
     * @var array
25
     */
26
    protected $formats = array('post', 'json', 'xml');
27
28
    /**
29
     * Returns the format from an HTTP context.
30
     *
31
     * @param  string $context The context to extract the format from.
32
     * @return string The extracted format.
33
     */
34
    public static function getFormat($context)
35
    {
36
        switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strstr($context, '/html') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing strstr($context, '/json') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
37
            // text/html
38
            case (strstr($context, '/html')):
39
                return 'html';
40
41
            // application/json
42
            case (strstr($context, '/json')):
43
                return 'json';
44
45
            // text/xml, application/xml
46
            case (strstr($context, '/xml')
47
                && (!strstr($context, 'html'))):
48
                return 'xml';
49
50
            default:
51
                return null;
52
        }
53
    }
54
55
    /**
56
     * Returns the format from an HTTP Accept.
57
     *
58
     * @return string The output format
59
     */
60
    public function getAcceptFormat()
61
    {
62
        if ($this->hasHeader('HTTP_ACCEPT')) {
63
            $accept = $this->getHeader('HTTP_ACCEPT');
64
65
            if (!$format = self::getFormat($accept)) {
66
                // 'application/javascript'
67
                $format = strstr($accept, '/javascript') ? 'jsonp' : null;
68
            }
69
        }
70
71
        return isset($format) ? $format : false;
72
    }
73
74
    /**
75
     * Get & parse the request body-data.
76
     *
77
     * @param  boolean $assoc Wether to convert objects to associative arrays or not.
78
     * @return array
79
     * @link http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4
80
     * @link http://www.w3.org/TR/html401/references.html#ref-RFC2388
81
     */
82
    public function getBodyData($assoc=true)
83
    {
84
        if ($this->hasBody() && $this->hasHeader('CONTENT_TYPE')) {
85
            $ctx = $this->getHeader('CONTENT_TYPE');
86
87
            if (
88
                in_array('post', $this->formats)
89
                // application/x-www-form-urlencoded
90
                && strstr($ctx, '/x-www-form-urlencoded')
91
                // TODO: shall we do multipart/form-data too?
92
            ) {
93
                // handles by PHP already. No need to parse the body.
94
                return $this->getParams();
95
            } elseif ($format = self::getFormat($ctx)) {
96
                if (in_array(strtolower($format), $this->formats)) {
97
                    $class = __NAMESPACE__ . '\Input\\' . ucfirst($format);
98
                    $input = new $class();
99
100
                    return $input->decode($this->getBody(), $assoc);
101
                    #$this->setParams($r); // TODO: maybe set as request params?
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
102
                }
103
            }
104
105
            return null;
106
        }
107
    }
108
109
    /**
110
     * Sets the input formats.
111
     *
112
     * @return void
113
     */
114
    public function setFormats(array $formats)
115
    {
116
        $this->formats = $formats;
117
    }
118
119
}
120