Issues (47)

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.

library/Respect/Rest/Routines/AbstractAccept.php (2 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
 * This file is part of the Respect\Rest package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Respect\Rest\Routines;
10
11
use SplObjectStorage;
12
use Respect\Rest\Request;
13
14
/** Base class for content-negotiation */
15
abstract class AbstractAccept extends AbstractCallbackMediator implements
16
    ProxyableBy,
17
    ProxyableThrough,
18
    Unique,
19
    IgnorableFileExtension
20
{
21
    protected $negotiated = null;
22
    protected $request_uri;
23
24 27
    protected function identifyRequested(Request $request, $params)
0 ignored issues
show
identifyRequested 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...
25
    {
26 27
        $this->request_uri = $request->uri;
27
28 27
        if (!isset($_SERVER[static::ACCEPT_HEADER])) {
29
            return array();
30
        }
31 27
        $acceptHeader = $_SERVER[static::ACCEPT_HEADER];
32 27
        $acceptParts = explode(',', $acceptHeader);
33 27
        $acceptList = array();
34 27
        foreach ($acceptParts as $k => &$acceptPart) {
35 27
            $parts = explode(';q=', trim($acceptPart));
36 27
            $provided = array_shift($parts);
37 27
            $quality = array_shift($parts) ?: (10000 - $k) / 10000;
38 27
            $acceptList[$provided] = $quality;
39
        }
40 27
        arsort($acceptList);
41
42 27
        return array_keys($acceptList);
43
    }
44 27
    protected function considerProvisions($requested)
45
    {
46 27
        return $this->getKeys(); // no need to split see authorize
47
    }
48 26
    protected function notifyApproved($requested, $provided, Request $request, $params)
0 ignored issues
show
notifyApproved 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...
49
    {
50 26
        $this->negotiated = new SplObjectStorage();
51 26
        $this->negotiated[$request] = $this->getCallback($provided);
52 26
        if (false === strpos($provided, '.')) {
53 21
            $header_type = preg_replace(
54
                array(
55 21
                    '/(^.*)(?=\w*$)/U', // select namespace to strip
56
                    '/(?!^)([A-Z]+)/',   // select camels to add -
57
                ),
58 21
                array('', '-$1'),
59 21
                get_class($this)
60
            );
61
62 21
            $content_header = 'Content-Type';
63
64 21
            if (false !== strpos($header_type, '-')) {
65 12
                $content_header = str_replace('Accept', 'Content', $header_type);
66
            }
67
68 21
            header("$content_header: $provided");                   // RFC 2616
69 21
            header("Vary: negotiate,".strtolower($header_type));    // RFC 2616/2295
70 21
            header("Content-Location: {$_SERVER['REQUEST_URI']}");  // RFC 2616
71 21
            header('Expires: Thu, 01 Jan 1980 00:00:00 GMT');       // RFC 2295
72 21
            header('Cache-Control: max-age=86400');                 // RFC 2295
73
        }
74 26
    }
75 1
    protected function notifyDeclined($requested, $provided, Request $request, $params)
76
    {
77 1
        $this->negotiated = false;
78 1
        header('HTTP/1.1 406');
79 1
    }
80
81 10
    protected function authorize($requested, $provided)
82
    {
83
        // negotiate on file extension
84 10
        if (false !== strpos($provided, '.')) {
85 5
            if (false !== stripos($this->request_uri, $provided)) {
86 5
                return true;
87
            }
88
        }
89
90
        // normal matching requirements
91 5
        return $requested == $provided;
92
    }
93
94 23
    public function by(Request $request, $params)
95
    {
96 23
        $unsyncedParams = $request->params;
97 23
        $extensions = $this->filterKeysContain('.');
98
99 23
        if (empty($extensions) || empty($unsyncedParams)) {
100 22
            return;
101
        }
102
103 1
        $unsyncedParams[] = str_replace(
104 1
            $extensions,
105 1
            '',
106 1
            array_pop($unsyncedParams)
107
        );
108 1
        $request->params = $unsyncedParams;
109 1
    }
110
111 23
    public function through(Request $request, $params)
112
    {
113 23
        if (!isset($this->negotiated[$request])
114 23
            || false === $this->negotiated[$request]) {
115
            return;
116
        }
117
118 23
        return $this->negotiated[$request];
119
    }
120
}
121