Issues (44)

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.

ExchangeRate/Controller/DeleteController.php (3 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
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\Controller;
11
12
use RunOpenCode\Bundle\ExchangeRate\Security\AccessVoter;
13
use RunOpenCode\ExchangeRate\Contract\RateInterface;
14
use RunOpenCode\ExchangeRate\Contract\RepositoryInterface;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
18
19
/**
20
 * Class DeleteController
21
 *
22
 * @package RunOpenCode\Bundle\ExchangeRate\Controller
23
 */
24
class DeleteController extends Controller
25
{
26
    /**
27
     * Main controller action
28
     *
29
     * @param Request $request
30
     * @return \Symfony\Component\HttpFoundation\Response
31
     */
32 3
    public function indexAction(Request $request)
33
    {
34 3
        return $this->render($this->getTwigTemplate(), [
35 3
            'rate' => $this->getRateFromRequest($request)
36
        ]);
37
    }
38
39
    /**
40
     * Execute delete action.
41
     *
42
     * @param Request $request
43
     *
44
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
45
     */
46 5
    public function deleteAction(Request $request)
47
    {
48 5
        if (!$this->isCsrfTokenValid($request->getRequestUri(), $request->get('_csrf_token'))) {
49 1
            throw new InvalidCsrfTokenException();
50
        }
51
52
        /**
53
         * @var \RunOpenCode\ExchangeRate\Contract\RateInterface $rate
54
         */
55 4
        $rate = $this->getRateFromRequest($request);
56
57 2
        if (!$this->delete($rate)) {
58 1
            return $this->indexAction($request);
59
        }
60
61 1
        return $this->redirectAfterSuccess();
62
    }
63
64
    /**
65
     * Get rate from request
66
     *
67
     * @param Request $request
68
     *
69
     * @return \RunOpenCode\ExchangeRate\Contract\RateInterface
70
     */
71 5
    protected function getRateFromRequest(Request $request)
72
    {
73 5
        $source = $request->get('source');
74 5
        $rateType = $request->get('rate_type');
75 5
        $currencyCode = $request->get('currency_code');
76 5
        $date = \DateTime::createFromFormat('Y-m-d', $request->get('date'));
77
78
        /**
79
         * @var RepositoryInterface $repository
80
         */
81 5
        $repository = $this->get('runopencode.exchange_rate.repository');
82
83 5
        if (!$repository->has($source, $currencyCode, $date, $rateType)) {
0 ignored issues
show
It seems like $date defined by \DateTime::createFromFor... $request->get('date')) on line 76 can also be of type false; however, RunOpenCode\ExchangeRate...ositoryInterface::has() does only seem to accept null|object<DateTime>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
84 1
            throw $this->createNotFoundException();
85
        }
86
87 4
        $rate = $repository->get($source, $currencyCode, $date, $rateType);
0 ignored issues
show
It seems like $date defined by \DateTime::createFromFor... $request->get('date')) on line 76 can also be of type false; however, RunOpenCode\ExchangeRate...ositoryInterface::get() does only seem to accept null|object<DateTime>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
88
89 4
        if (!$this->isGranted(AccessVoter::DELETE, $rate)) {
90 2
            throw $this->createAccessDeniedException();
91
        }
92
93 2
        return $rate;
94
    }
95
96
    /**
97
     * Save rate.
98
     *
99
     * @param RateInterface $rate
100
     *
101
     * @return TRUE if successful.
102
     */
103 2 View Code Duplication
    protected function delete(RateInterface $rate)
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...
104
    {
105
        try {
106 2
            $this->get('runopencode.exchange_rate.repository')->delete([$rate]);
107 1
            $this->addFlash('success', $this->get('translator')->trans('flash.delete.success', [], 'runopencode_exchange_rate'));
108 1
            return true;
109 1
        } catch (\Exception $e) {
110 1
            $this->addFlash('error', $this->get('translator')->trans('flash.delete.error.unknown', [], 'runopencode_exchange_rate'));
111 1
            return false;
112
        }
113
    }
114
115
    /**
116
     * Redirect after success.
117
     *
118
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
119
     */
120 1
    protected function redirectAfterSuccess()
121
    {
122 1
        return $this->redirectToRoute('runopencode_exchange_rate_list');
123
    }
124
125
    /**
126
     * Get Twig template path.
127
     *
128
     * @return string
129
     */
130 3
    protected function getTwigTemplate()
131
    {
132 3
        return '@ExchangeRate/delete.html.twig';
133
    }
134
}
135