Issues (1704)

Branch: master

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.

Bundle/WidgetBundle/Cache/WidgetCache.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 Victoire\Bundle\WidgetBundle\Cache;
4
5
use Predis\Client;
6
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
7
use Victoire\Bundle\WidgetBundle\Entity\Widget;
8
use Victoire\Bundle\WidgetBundle\Entity\WidgetSlotInterface;
9
use Victoire\Bundle\WidgetBundle\Helper\WidgetHelper;
10
11
/**
12
 * This class handle the saving of Widgets.
13
 * Widgets are stored for a week, but are invalidated as soon as
14
 * the Widget's or BusinessEntity's updatedAt field is changed.
15
 */
16
class WidgetCache
17
{
18
    /**
19
     * @var Client
20
     */
21
    private $redis;
22
    /**
23
     * @var AuthorizationChecker
24
     */
25
    private $authorizationChecker;
26
    /**
27
     * @var WidgetHelper
28
     */
29
    private $widgetHelper;
30
31
    /**
32
     * WidgetCache constructor.
33
     *
34
     * @param Client               $redis
35
     * @param AuthorizationChecker $authorizationChecker
36
     * @param WidgetHelper         $widgetHelper
37
     */
38
    public function __construct(Client $redis, AuthorizationChecker $authorizationChecker, WidgetHelper $widgetHelper)
39
    {
40
        $this->redis = $redis;
41
        $this->authorizationChecker = $authorizationChecker;
42
        $this->widgetHelper = $widgetHelper;
43
    }
44
45
    /**
46
     * @param Widget $widget
47
     *
48
     * @return string
49
     */
50
    public function fetch(Widget $widget)
51
    {
52
        return $this->redis->get($this->getHash($widget));
53
    }
54
55
    /**
56
     * @param Widget $widget
57
     *
58
     * @return int
59
     */
60
    public function remove(Widget $widget)
61
    {
62
        return $this->redis->del($this->getHash($widget));
63
    }
64
65
    /**
0 ignored issues
show
Doc comment for parameter "$content" missing
Loading history...
66
     * @param Widget $widget
0 ignored issues
show
Expected 2 spaces after parameter type; 1 found
Loading history...
67
     * @param        $content
0 ignored issues
show
Missing parameter name
Loading history...
68
     */
69
    public function save(Widget $widget, $content)
70
    {
71
        $hash = $this->getHash($widget);
72
        if ($hash) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $hash of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
73
            $this->redis->set($hash, $content);
74
            $this->redis->expire($hash, $this->widgetHelper->getCacheTimeout($widget)); // cache for a week
75
        }
76
    }
77
78
    /**
79
     * clear all redis cache.
80
     */
81
    public function clear()
82
    {
83
        $keys = $this->redis->keys('widgets/*');
84
        foreach ($keys as $key) {
85
            $this->redis->del($key);
86
        }
87
    }
88
89
    /**
90
     * @param Widget $widget
91
     *
92
     * @return string
93
     */
94
    protected function getHash(Widget $widget)
95
    {
96
        $hash = null;
97
        if (!$widget instanceof WidgetSlotInterface) {
98
            if ($widget->getMode() == Widget::MODE_BUSINESS_ENTITY
99
                && $widget->getEntity()
100
                && method_exists($widget->getEntity(), 'getUpdatedAt')) {
101
                $hash = $this->generateBusinessEntityHash($widget);
102
            } elseif ($widget->getMode() == Widget::MODE_STATIC) {
103
                $hash = $this->generateHash($widget);
104
            }
105
        }
106
107
        return $hash;
108
    }
109
110
    protected function generateBusinessEntityHash(Widget $widget)
111
    {
112
        return sprintf('widgets/%s--%s-%s-%s',
113
            $widget->generateCacheId(),
114
            $widget->getEntity()->getId(),
115
            $widget->getEntity()->getUpdatedAt()->getTimestamp(),
116
            (string) $this->authorizationChecker->isGranted('ROLE_VICTOIRE')
117
        );
118
    }
119
120
    private function generateHash(Widget $widget)
121
    {
122
        return sprintf('widgets/%s-%s',
123
            $widget->generateCacheId(),
124
            (string) $this->authorizationChecker->isGranted('ROLE_VICTOIRE')
125
        );
126
    }
127
}
128