Issues (29)

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.

Http/Controllers/Api/MediaController.php (1 issue)

Labels
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 namespace Modules\Media\Http\Controllers\Api;
2
3
use Illuminate\Http\Request;
4
use Illuminate\Routing\Controller;
5
use Illuminate\Support\Facades\DB;
6
use Illuminate\Support\Facades\Response;
7
use Modules\Media\Events\FileWasLinked;
8
use Modules\Media\Events\FileWasUnlinked;
9
use Modules\Media\Events\FileWasUploaded;
10
use Modules\Media\Http\Requests\UploadMediaRequest;
11
use Modules\Media\Image\Imagy;
12
use Modules\Media\Repositories\FileRepository;
13
use Modules\Media\Services\FileService;
14
15
class MediaController extends Controller
16
{
17
    /**
18
     * @var FileService
19
     */
20
    private $fileService;
21
    /**
22
     * @var FileRepository
23
     */
24
    private $file;
25
    /**
26
     * @var Imagy
27
     */
28
    private $imagy;
29
30
    public function __construct(FileService $fileService, FileRepository $file, Imagy $imagy)
31
    {
32
        $this->fileService = $fileService;
33
        $this->file = $file;
34
        $this->imagy = $imagy;
35
    }
36
37
    public function all()
38
    {
39
        $files = $this->file->all();
40
41
        return [
42
            'count' => $files->count(),
43
            'data' => $files,
44
        ];
45
    }
46
47
    /**
48
     * Store a newly created resource in storage.
49
     * @param  UploadMediaRequest $request
50
     * @return Response
51
     */
52
    public function store(UploadMediaRequest $request)
53
    {
54
        $savedFile = $this->fileService->store($request->file('file'));
0 ignored issues
show
It seems like $request->file('file') targeting Illuminate\Http\Request::file() can also be of type array or null; however, Modules\Media\Services\FileService::store() does only seem to accept object<Symfony\Component...tion\File\UploadedFile>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
55
56
        if (is_string($savedFile)) {
57
            return Response::json(['error' => $savedFile], 409);
58
        }
59
60
        event(new FileWasUploaded($savedFile));
61
62
        return Response::json($savedFile->toArray());
63
    }
64
65
    /**
66
     * Link the given entity with a media file
67
     * @param Request $request
68
     */
69
    public function linkMedia(Request $request)
70
    {
71
        $mediaId = $request->get('mediaId');
72
        $entityClass = $request->get('entityClass');
73
        $entityId = $request->get('entityId');
74
75
        $entity = $entityClass::find($entityId);
76
        $zone = $request->get('zone');
77
        $entity->files()->attach($mediaId, ['imageable_type' => $entityClass, 'zone' => $zone]);
78
        $imageable = DB::table('media__imageables')->whereFileId($mediaId)->whereZone($zone)->whereImageableType($entityClass)->first();
79
        $file = $this->file->find($imageable->file_id);
80
81
        $thumbnailPath = $this->imagy->getThumbnail($file->path, 'mediumThumb');
82
83
        event(new FileWasLinked($file, $entity));
84
85
        return Response::json([
86
            'error' => false,
87
            'message' => 'The link has been added.',
88
            'result' => ['path' => $thumbnailPath, 'imageableId' => $imageable->id]
89
        ]);
90
    }
91
92
    /**
93
     * Remove the record in the media__imageables table for the given id
94
     * @param Request $request
95
     */
96
    public function unlinkMedia(Request $request)
97
    {
98
        $imageableId = $request->get('imageableId');
99
        $deleted = DB::table('media__imageables')->whereId($imageableId)->delete();
100
        if (! $deleted) {
101
            return Response::json(['error' => true, 'message' => 'The file was not found.']);
102
        }
103
104
        event(new FileWasUnlinked($imageableId));
105
106
        return Response::json(['error' => false, 'message' => 'The link has been removed.']);
107
    }
108
}
109