Issues (30)

Security Analysis    no request data  

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.

app/Http/Controllers/PostController.php (6 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
namespace App\Http\Controllers;
4
5
use App\Post;
6
7
use Illuminate\Http\Request;
8
9
class PostController extends Controller{
10
11
	public function __construct(){
12
13
		$this->middleware('oauth', ['except' => ['index', 'show']]);
14
		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
15
	}
16
17
	public function index(){
18
19
		$posts = Post::all();
20
		return $this->success($posts, 200);
0 ignored issues
show
It seems like $posts defined by \App\Post::all() on line 19 can also be of type object<Illuminate\Database\Eloquent\Collection>; however, App\Http\Controllers\Controller::success() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
21
	}
22
23
	public function store(Request $request){
24
25
		$this->validateRequest($request);
26
27
		$post = Post::create([
0 ignored issues
show
The method create() does not exist on App\Post. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
28
					'title' => $request->get('title'),
29
					'content'=> $request->get('content'),
30
					'user_id' => $this->getUserId()
31
				]);
32
33
		return $this->success("The post with with id {$post->id} has been created", 201);
34
	}
35
36 View Code Duplication
	public function show($id){
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
38
		$post = Post::find($id);
39
40
		if(!$post){
41
			return $this->error("The post with {$id} doesn't exist", 404);
42
		}
43
44
		return $this->success($post, 200);
45
	}
46
47
	public function update(Request $request, $id){
48
49
		$post = Post::find($id);
50
51
		if(!$post){
52
			return $this->error("The post with {$id} doesn't exist", 404);
53
		}
54
55
		$this->validateRequest($request);
56
57
		$post->title 		= $request->get('title');
58
		$post->content 		= $request->get('content');
59
		$post->user_id 		= $this->getUserId();
60
61
		$post->save();
62
63
		return $this->success("The post with with id {$post->id} has been updated", 200);
64
	}
65
66 View Code Duplication
	public function destroy($id){
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
68
		$post = Post::find($id);
69
70
		if(!$post){
71
			return $this->error("The post with {$id} doesn't exist", 404);
72
		}
73
74
		// no need to delete the comments for the current post,
75
		// since we used on delete cascase on update cascase.
76
		// $post->comments()->delete();
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
77
		$post->delete();
78
79
		return $this->success("The post with with id {$id} has been deleted along with it's comments", 200);
80
	}
81
82
	public function validateRequest(Request $request){
83
84
		$rules = [
85
			'title' => 'required', 
86
			'content' => 'required'
87
		];
88
89
		$this->validate($request, $rules);
90
	}
91
92
	public function isAuthorized(Request $request){
93
94
		$resource = "posts";
95
		$post     = Post::find($this->getArgs($request)["post_id"]);
96
97
		return $this->authorizeUser($request, $resource, $post);
0 ignored issues
show
$resource is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
98
	}
99
}