Issues (9)

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/Controller.php (1 issue)

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
namespace NavJobs\Transmit;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Support\Facades\App;
7
use Illuminate\Support\Facades\Input;
8
use NavJobs\Transmit\Traits\ErrorResponsesTrait;
9
use NavJobs\Transmit\Traits\QueryHelperTrait;
10
use Illuminate\Routing\Controller as BaseController;
11
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
12
13
abstract class Controller extends BaseController
14
{
15
    use QueryHelperTrait, ErrorResponsesTrait;
16
17
    protected $statusCode = 200;
18
    protected $fractal;
19
20
    public function __construct()
21
    {
22
        $this->fractal = App::make(Fractal::class);
23
24
        $this->parseIncludes();
25
    }
26
27
    /**
28
     * Parses includes from either the header or query string.
29
     *
30
     * @return mixed
31
     */
32
    protected function parseIncludes()
33
    {
34
        if (Input::header('include')) {
35
            return $this->fractal->parseIncludes(Input::header('include'));
36
        }
37
38
        if (Input::get('include')) {
39
            return $this->fractal->parseIncludes(Input::get('include'));
40
        }
41
42
        return null;
43
    }
44
45
    /**
46
     * Returns the current status code.
47
     *
48
     * @return int
49
     */
50
    protected function getStatusCode()
51
    {
52
        return $this->statusCode;
53
    }
54
55
    /**
56
     * Sets the current status code.
57
     *
58
     * @param $statusCode
59
     * @return $this
60
     */
61
    protected function setStatusCode($statusCode)
62
    {
63
        $this->statusCode = $statusCode;
64
65
        return $this;
66
    }
67
68
    /**
69
     * Returns a json response that contains the specified resource
70
     * passed through fractal and optionally a transformer.
71
     *
72
     * @param $item
73
     * @param null $callback
74
     * @param null $resourceKey
75
     * @return \Illuminate\Http\JsonResponse
76
     */
77
    protected function respondWithItem($item, $callback = null, $resourceKey = null)
78
    {
79
        $rootScope = $this->fractal->item($item, $callback, $resourceKey);
80
81
        return $this->respondWithArray($rootScope->toArray());
82
    }
83
84
    /**
85
     * Returns a json response that indicates the resource was successfully created also
86
     * returns the resource passed through fractal and optionally a transformer.
87
     *
88
     * @param $item
89
     * @param null $callback
90
     * @param null $resourceKey
91
     * @return \Illuminate\Http\JsonResponse
92
     */
93
    protected function respondWithItemCreated($item, $callback = null, $resourceKey = null)
94
    {
95
        $this->setStatusCode(201);
96
        $rootScope = $this->fractal->item($item, $callback, $resourceKey);
97
98
        return $this->respondWithArray($rootScope->toArray());
99
    }
100
101
    /**
102
     * Returns a json response that contains the specified collection
103
     * passed through fractal and optionally a transformer.
104
     *
105
     * @param $collection
106
     * @param $callback
107
     * @param null $resourceKey
108
     * @return \Illuminate\Http\JsonResponse
109
     */
110
    protected function respondWithCollection($collection, $callback, $resourceKey = null)
111
    {
112
        $rootScope = $this->fractal->collection($collection, $callback, $resourceKey);
113
114
        return $this->respondWithArray($rootScope->toArray());
115
    }
116
117
    /**
118
     * Returns a json response that contains the specified paginated collection
119
     * passed through fractal and optionally a transformer.
120
     *
121
     * @param $builder
122
     * @param $callback
123
     * @param int $perPage
124
     * @param null $resourceKey
125
     * @return \Illuminate\Http\JsonResponse
126
     */
127
    protected function respondWithPaginatedCollection($builder, $callback, $perPage = 10, $resourceKey = null)
128
    {
129
        $paginator = $builder->paginate($perPage);
130
        $paginator->appends($this->getQueryParameters());
131
132
        $rootScope = $this->fractal
133
            ->collection($paginator->getCollection(), $callback, $resourceKey)
134
            ->paginateWith(new IlluminatePaginatorAdapter($paginator));
135
136
        return $this->respondWithArray($rootScope->toArray());
137
    }
138
139
    /**
140
     * Returns an array of Query Parameters, not including pagination.
141
     *
142
     * @return array
143
     */
144
    protected function getQueryParameters()
0 ignored issues
show
getQueryParameters uses the super-global variable $_GET 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...
145
    {
146
        return array_diff_key($_GET, array_flip(['page']));
147
    }
148
149
    /**
150
     * Returns a json response that contains the specified array,
151
     * the current status code and optional headers.
152
     *
153
     * @param array $array
154
     * @param array $headers
155
     * @return \Illuminate\Http\JsonResponse
156
     */
157
    protected function respondWithArray(array $array, array $headers = [])
158
    {
159
        return response()->json($array, $this->statusCode, $headers);
160
    }
161
162
    /**
163
     * Returns a response that indicates success but no content returned.
164
     *
165
     * @return \Illuminate\Http\Response
166
     */
167
    protected function respondWithNoContent()
168
    {
169
        return response()->json('', 204);
170
    }
171
}
172