Issues (4141)

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.

app/Controller/BannerController.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
require ROOT . DS . 'app/Vendor/m2brimagem.php';
4
5
class BannerController extends AppController {
6
	
7
	public function listar_cadastros() {
8
		$banners = $this->Banner->find('all', 
9
			array('conditions' => 
10
				array('ativo' => 1,
11
					  'usuario_id' => $this->instancia
12
				)
13
			)
14
		);
15
		
16
		$this->set('banners', $banners);
17
18
		$this->layout = 'wadmin';
19
	}
20
21 View Code Duplication
	public function adicionar_cadastro() {
22
		$this->loadModel('CategoriaBanner');
23
24
		$this->set('categorias', $this->CategoriaBanner->find('all', 
25
				array('conditions' => 
26
					array('ativo' => 1,
27
						  'usuario_id' => $this->instancia
28
					)
29
				)
30
			)
31
		);	
32
33
		$this->layout = 'wadmin';
34
	}
35
36 View Code Duplication
	public function editar_cadastro($id) {
37
		$this->loadModel('CategoriaBanner');
38
		
39
		$this->set('categorias', $this->CategoriaBanner->find('all', 
40
				array('conditions' => 
41
					array('ativo' => 1,
42
						  'usuario_id' => $this->instancia
43
					)
44
				)
45
			)
46
		);	
47
48
		$this->set('banner', $this->Banner->find('all', 
49
				array('conditions' => 
50
					array('ativo' => 1,
51
						  'id' => $id
52
					)
53
				)
54
			)[0]
55
		);
56
57
		$this->layout = 'wadmin';
58
	}
59
60
	public function s_editar_cadastro($id) {
0 ignored issues
show
s_editar_cadastro uses the super-global variable $_FILES 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...
61
		$dados = $this->request->data('dados');
62
63
		$image  = $_FILES['imagem'];
64
		
65 View Code Duplication
		if (!empty($image['name'])) {
66
			$retorno = $this->uploadImage($image);
0 ignored issues
show
The call to uploadImage() misses a required argument $categoriaBanner.

This check looks for function calls that miss required arguments.

Loading history...
67
			
68
			if (!$retorno['status']) 
69
				$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
70
			
71
			$dados['imagem'] = $retorno['nome'];
72
		}
73
74
75
		$dados['id_usuario'] = $this->instancia;
76
		$dados['ativo'] = 1;
77
78
		$this->Banner->id = $id;
79
		
80
		if ($this->Banner->save($dados)) {
81
			$this->Session->setFlash('Banner editado com sucesso!','default','good');
82
            return $this->redirect('/banner/listar_cadastros');
83
		} else {
84
			$this->Session->setFlash('Ocorreu um erro ao editar o Banner!','default','good');
85
            return $this->redirect('/banner/listar_cadastros');
86
		}
87
	}
88
89
	public function s_adicionar_cadastro() {
0 ignored issues
show
s_adicionar_cadastro uses the super-global variable $_FILES 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...
90
		$this->loadModel('CategoriaBanner');
91
92
		$dados  = $this->request->data('dados');
93
94
		$categoriaBanner = $this->CategoriaBanner->find('first', array(
95
				'conditions' => array(
96
					'CategoriaBanner.id' => $dados['categoria_banner_id']
97
				)
98
			)
99
		);
100
101
		$image  = $_FILES['imagem'];
102
103
		$retorno = $this->uploadImage($image, $categoriaBanner);
104
105
		if (!$retorno['status']) 
106
			$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
107
108
		$dados['src'] = $retorno['nome'];
109
		$dados['usuario_id'] = $this->instancia;
110
		$dados['ativo'] = 1;
111
112
		if($this->Banner->save($dados)) {
113
			$this->Session->setFlash('Banner salvo com sucesso!');
114
            return $this->redirect('/banner/listar_cadastros');
115
		} else {
116
			$this->Session->setFlash('Ocorreu um erro ao salva o banner!');
117
            return $this->redirect('/banner/listar_cadastros');
118
		}
119
	}
120
121
	public function uploadImage(&$image, $categoriaBanner) {
122
		$type = substr($image['name'], -4);
123
		
124
		$nameImage = uniqid() . md5($image['name']) . $type;
125
126
		$dir = APP . 'webroot/uploads/banner/imagens/';
127
		
128
		$returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage);
129
				
130
		$oImg = new m2brimagem($dir . $nameImage);
131
		
132
		$valida = $oImg->valida();
133
		
134
		if ($valida == 'OK') {
135
			
136
			$oImg->redimensiona($categoriaBanner['CategoriaBanner']['width'], $categoriaBanner['CategoriaBanner']['height'], 'crop');
137
		    
138
		    $oImg->grava($dir . $nameImage);
139
140
		} else {
141
142
			die($valida);
0 ignored issues
show
Coding Style Compatibility introduced by
The method uploadImage() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
143
144
		}
145
		
146
		if (!$returnUpload)
147
			return array('nome' => null, 'status' => false);
148
149
		return array('nome' => $nameImage, 'status' => true);
150
	}
151
152 View Code Duplication
	public function excluir_cadastro() {
153
		$this->layout = 'ajax';
154
155
		$id = $this->request->data('id');
156
157
		$dados = array ('ativo' => '0');
158
		$parametros = array ('id' => $id);
159
160
		if ($this->Banner->updateAll($dados, $parametros)) {
161
			echo json_encode(true);
162
		} else {
163
			echo json_encode(false);
164
		}
165
	}
166
167
}