Issues (10)

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.

src/AbstractForm.php (2 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 Ray.WebFormModule package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\WebFormModule;
8
9
use Aura\Filter\FilterFactory;
10
use Aura\Filter\SubjectFilter;
11
use Aura\Html\HelperLocator;
12
use Aura\Html\HelperLocatorFactory;
13
use Aura\Input\AntiCsrfInterface;
14
use Aura\Input\BuilderInterface;
15
use Aura\Input\Fieldset;
16
use Ray\WebFormModule\Exception\CsrfViolationException;
17
use Ray\WebFormModule\Exception\LogicException;
18
19
abstract class AbstractForm extends Fieldset implements FormInterface
20
{
21
    /**
22
     * @var SubjectFilter
23
     */
24
    protected $filter;
25
26
    /**
27
     * @var null | array
28
     */
29
    protected $errorMessages;
30
31
    /**
32
     * @var HelperLocator
33
     */
34
    protected $helper;
35
36
    /**
37
     * @var AntiCsrfInterface
38
     */
39
    protected $antiCsrf;
40
41 24
    public function __construct()
42
    {
43 24
    }
44
45 1
    public function __clone()
46
    {
47 1
        $this->filter = clone $this->filter;
48 1
        $this->init();
49 1
    }
50
51
    /**
52
     * Return form markup string
53
     *
54
     * @return string
55
     */
56 1
    public function __toString()
57
    {
58
        try {
59 1
            if (! $this instanceof ToStringInterface) {
60 1
                throw new LogicException(ToStringInterface::class . ' is not implemented');
61
            }
62
63
            return $this->toString();
0 ignored issues
show
The method toString() does not exist on Ray\WebFormModule\AbstractForm. Did you maybe mean __toString()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64 1
        } catch (\Exception $e) {
65 1
            trigger_error($e->getMessage() . PHP_EOL . $e->getTraceAsString(), E_USER_ERROR);
66
67 1
            return '';
68
        }
69
    }
70
71
    /**
72
     * @param BuilderInterface     $builder
73
     * @param FilterFactory        $filterFactory
74
     * @param HelperLocatorFactory $helperFactory
75
     *
76
     * @\Ray\Di\Di\Inject
77
     */
78 24
    public function setBaseDependencies(
79
        BuilderInterface $builder,
80
        FilterFactory $filterFactory,
81
        HelperLocatorFactory $helperFactory
82
    ) {
83 24
        $this->builder = $builder;
0 ignored issues
show
Documentation Bug introduced by
$builder is of type object<Aura\Input\BuilderInterface>, but the property $builder was declared to be of type object<Aura\Input\Builder>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
84 24
        $this->filter = $filterFactory->newSubjectFilter();
85 24
        $this->helper = $helperFactory->newInstance();
86 24
    }
87
88 1
    public function setAntiCsrf(AntiCsrfInterface $antiCsrf)
89
    {
90 1
        $this->antiCsrf = $antiCsrf;
91 1
    }
92
93
    /**
94
     * @\Ray\Di\Di\PostConstruct
95
     */
96 24
    public function postConstruct()
97
    {
98 24
        $this->init();
99 24
        if ($this->antiCsrf instanceof AntiCsrfInterface) {
100 13
            $this->antiCsrf->setField($this);
101
        }
102 24
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 2
    public function input($input)
108
    {
109 2
        return $this->helper->input($this->get($input));
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 2
    public function error($input)
116
    {
117 2
        if (! $this->errorMessages) {
118 2
            $failure = $this->filter->getFailures();
119 2
            if ($failure) {
120 1
                $this->errorMessages = $failure->getMessages();
121
            }
122
        }
123
124 2
        if (isset($this->errorMessages[$input])) {
125 1
            return $this->errorMessages[$input][0];
126
        }
127
128 1
        return '';
129
    }
130
131
    /**
132
     * @param array $attr attributes for the form tag
133
     *
134
     * @throws \Aura\Html\Exception\HelperNotFound
135
     * @throws \Aura\Input\Exception\NoSuchInput
136
     *
137
     * @return string
138
     */
139 3
    public function form($attr = [])
140
    {
141 3
        $form = $this->helper->form($attr);
142 3
        if (isset($this->inputs['__csrf_token'])) {
143 1
            $form .= $this->helper->input($this->get('__csrf_token'));
144
        }
145
146 3
        return $form;
147
    }
148
149
    /**
150
     * Applies the filter to a subject.
151
     *
152
     * @param array $data
153
     *
154
     * @throws CsrfViolationException
155
     *
156
     * @return bool
157
     */
158 10
    public function apply(array $data)
159
    {
160 10
        if ($this->antiCsrf && ! $this->antiCsrf->isValid($data)) {
161 1
            throw new CsrfViolationException;
162
        }
163 9
        $this->fill($data);
164
165 9
        return $this->filter->apply($data);
166
    }
167
168
    /**
169
     * Returns all failure messages for all fields.
170
     *
171
     * @return array
172
     */
173 4
    public function getFailureMessages()
174
    {
175 4
        return $this->filter->getFailures()->getMessages();
176
    }
177
178
    /**
179
     * Returns all the fields collection
180
     *
181
     * @return \ArrayIterator
182
     */
183 1
    public function getIterator()
184
    {
185 1
        return new \ArrayIterator($this->inputs);
186
    }
187
}
188