Issues (4)

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.

Twig/CropTwigExtension.php (4 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 Fenrizbes\CropBundle\Twig;
4
5
use Fenrizbes\UploadableBundle\File\UploadableFile;
6
use Symfony\Component\HttpFoundation\File\File;
7
8
class CropTwigExtension extends \Twig_Extension
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $root_path;
14
15
    public function __construct($root_path)
16
    {
17
        $this->root_path = $root_path;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getName()
24
    {
25
        return 'CropTwigExtension';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getFilters()
32
    {
33
        return array(
34
            new \Twig_SimpleFilter('crop', array($this, 'crop'))
35
        );
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getFunctions()
42
    {
43
        return array(
44
            new \Twig_SimpleFunction('image_size', array($this, 'getSize'))
45
        );
46
    }
47
48
    /**
49
     * Crops a file and returns crop's web path
50
     *
51
     * @param array $croppable
52
     * @param int $index
53
     * @return mixed
54
     */
55
    public function crop(array $croppable, $index = 0)
56
    {
57
        $coordinates = $croppable['coordinates'][$index];
58
59
        $file = new UploadableFile($this->root_path, $croppable['image']);
60
        $name = $this->makeCropName($file, $coordinates);
61
        $path = $file->getRootPath() . $name;
62
63
        if (!file_exists($path)) {
64
            $this->doCrop($file, $coordinates, $path);
65
        }
66
67
        return $name;
68
    }
69
70
    /**
71
     * Returns the name for a cropped file
72
     *
73
     * @param UploadableFile $file
74
     * @param $coordinates
75
     * @return mixed
76
     */
77
    protected function makeCropName(UploadableFile $file, $coordinates)
78
    {
79
        $ext    = $file->getExtension();
80
        $suffix = implode('_', $coordinates);
81
82
        return preg_replace('/\.'. $ext .'$/ui', '_crop_'. $suffix .'.'. $ext, $file->getWebPath());
83
    }
84
85
    /**
86
     * Crops a file
87
     *
88
     * @param UploadableFile $file
89
     * @param $coordinates
90
     * @param $path
91
     */
92
    protected function doCrop(UploadableFile $file, $coordinates, $path)
93
    {
94
        $crop = imagecreatetruecolor($coordinates['min_width'], $coordinates['min_height']);
95
96
        switch ($file->getExtension()) {
97
            case 'gif':
98
                $source = imagecreatefromgif($file); break;
0 ignored issues
show
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
99
100
            case 'png':
101
                $source = imagecreatefrompng($file); break;
0 ignored issues
show
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
102
103
            default:
104
                $source = imagecreatefromjpeg($file);
105
        }
106
107
        if (preg_match('/^(gif|png)$/', $file->getExtension())) {
108
            imagecolortransparent($crop, imagecolorallocatealpha($crop, 0, 0, 0, 127));
109
            imagealphablending($crop, false);
110
            imagesavealpha($crop, true);
111
        }
112
113
        imagecopyresampled(
114
            $crop, $source,
115
            0, 0,
116
            $coordinates['left'], $coordinates['top'],
117
            $coordinates['min_width'], $coordinates['min_height'],
118
            $coordinates['width'], $coordinates['height']
119
        );
120
121
        switch ($file->getExtension()) {
122
            case 'gif':
123
                imagegif($crop, $path); break;
0 ignored issues
show
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
124
125
            case 'png':
126
                imagepng($crop, $path); break;
0 ignored issues
show
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
127
128
            default:
129
                imagejpeg($crop, $path, 100);
130
        }
131
    }
132
133
    /**
134
     * Returns image size info
135
     *
136
     * @param $image
137
     * @param bool $relative
138
     * @return array
139
     */
140
    public function getSize($image, $relative = false)
141
    {
142
        if (!$image instanceof File) {
143
            if ($relative) {
144
                $image = $this->root_path . $image;
145
            }
146
147
            $image = new File($image);
148
        }
149
150
        return getimagesize($image->getRealPath());
151
    }
152
}