Issues (2366)

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.

src/Eccube/Form/Type/AddCartType.php (1 issue)

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 EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Form\Type;
26
27
use Symfony\Component\Form\AbstractType;
28
use Symfony\Component\Form\FormBuilderInterface;
29
use Symfony\Component\Form\FormEvent;
30
use Symfony\Component\Form\FormEvents;
31
use Symfony\Component\Form\FormInterface;
32
use Symfony\Component\Form\FormView;
33
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
34
use Symfony\Component\Validator\Constraints as Assert;
35
use Symfony\Component\Validator\Context\ExecutionContext;
36
37
class AddCartType extends AbstractType
38
{
39
40
    public $config;
41
    public $security;
42
    public $customerFavoriteProductRepository;
43
    public $Product = null;
44
45 286
    public function __construct(
46
        $config,
47
        \Symfony\Component\Security\Core\SecurityContext $security,
48
        \Eccube\Repository\CustomerFavoriteProductRepository $customerFavoriteProductRepository
49
    ) {
50 286
        $this->config = $config;
51 286
        $this->security = $security;
52 286
        $this->customerFavoriteProductRepository = $customerFavoriteProductRepository;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 3
    public function buildForm(FormBuilderInterface $builder, array $options)
59
    {
60
        /* @var $Product \Eccube\Entity\Product */
61 2
        $Product = $options['product'];
62 2
        $this->Product = $Product;
63
        $ProductClasses = $Product->getProductClasses();
64
65
        $builder
66
            ->add('mode', 'hidden', array(
67
                'data' => 'add_cart',
68
            ))
69
            ->add('product_id', 'hidden', array(
70 2
                'data' => $Product->getId(),
71
                'constraints' => array(
72
                    new Assert\NotBlank(),
73
                    new Assert\Regex(array('pattern' => '/^\d+$/')),
74 2
                ),
75
            ))
76
            ->add('product_class_id', 'hidden', array(
77
                'data' => count($ProductClasses) === 1 ? $ProductClasses[0]->getId() : '',
78
                'constraints' => array(
79
                    new Assert\Regex(array('pattern' => '/^\d+$/')),
80 2
                ),
81
            ));
82
83
        if ($Product->getStockFind()) {
84
            $builder
85
                ->add('quantity', 'integer', array(
86
                    'data' => 1,
87 2
                    'attr' => array(
88
                        'min' => 1,
89 2
                        'maxlength' => $this->config['int_len'],
90 2
                    ),
91 2
                    'constraints' => array(
92
                        new Assert\NotBlank(),
93
                        new Assert\GreaterThanOrEqual(array(
94
                            'value' => 1,
95
                        )),
96
                        new Assert\Regex(array('pattern' => '/^\d+$/')),
97
                    ),
98 2
                ))
99
            ;
100 2
            if ($Product && $Product->getProductClasses()) {
101
                if (!is_null($Product->getClassName1())) {
102
                    $builder->add('classcategory_id1', 'choice', array(
103
                        'label' => $Product->getClassName1(),
104 3
                        'choices'   => array('__unselected' => '選択してください') + $Product->getClassCategories1(),
105
                    ));
106
                }
107
                if (!is_null($Product->getClassName2())) {
108
                    $builder->add('classcategory_id2', 'choice', array(
109
                        'label' => $Product->getClassName2(),
110 3
                        'choices' => array('__unselected' => '選択してください'),
111 3
                    ));
112
                }
113
            }
114
115
            $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($Product) {
116
                $data = $event->getData();
117
                $form = $event->getForm();
118
                if (!is_null($Product->getClassName2())) {
119
                    if ($data['classcategory_id1']) {
120
                        $form->add('classcategory_id2', 'choice', array(
121
                            'label' => $Product->getClassName2(),
122
                            'choices' => array('__unselected' => '選択してください') + $Product->getClassCategories2($data['classcategory_id1']),
123
                        ));
124
                    }
125
                }
126
            });
127
        }
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function setDefaultOptions(OptionsResolverInterface $resolver)
134 3
    {
135
        $resolver->setRequired('product');
0 ignored issues
show
'product' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
        $resolver->setDefaults(array(
137
            'id_add_product_id' => true,
138 3
            'constraints' => array(
139
                new Assert\Callback(array($this, 'validate')),
140
            ),
141 3
        ));
142
    }
143
144
    /*
145
     * {@inheritdoc}
146
     */
147
    public function finishView(FormView $view, FormInterface $form, array $options)
148 2
    {
149
        if ($options['id_add_product_id']) {
150 2
            foreach ($view->vars['form']->children as $child) {
151
                $child->vars['id'] .= $options['product']->getId();
152
            }
153
        }
154
155
        if ($view->vars['form']->children['mode']->vars['value'] === 'add_cart') {
156 2
            $view->vars['form']->children['mode']->vars['value'] = '';
157 2
        }
158
    }
159
160
    /**
161
     * {@inheritdoc}
162
     */
163
    public function getName()
164 283
    {
165
        return 'add_cart';
166 283
    }
167
168
    /**
169
     * validate
170
     *
171
     * @param type             $data
172
     * @param ExecutionContext $context
173
     */
174
    public function validate($data, ExecutionContext $context)
175
    {
176
        if ($data['mode'] !== 'add_favorite') {
177
            $context->validateValue($data['product_class_id'], array(
178
                new Assert\NotBlank(),
179
            ), '[product_class_id]');
180 View Code Duplication
            if ($this->Product->getClassName1()) {
181
                $context->validateValue($data['classcategory_id1'], array(
182
                    new Assert\NotBlank(),
183
                    new Assert\NotEqualTo(array(
184
                        'value' => '__unselected',
185
                        'message' => 'form.type.select.notselect'
186
                    )),
187
                ), '[classcategory_id1]');
188
            }
189
            //商品規格2初期状態(未選択)の場合の返却値は「NULL」で「__unselected」ではない
190 View Code Duplication
            if ($this->Product->getClassName2()) {
191
                $context->validateValue($data['classcategory_id2'], array(
192
                    new Assert\NotBlank(),
193
                    new Assert\NotEqualTo(array(
194
                        'value' => '__unselected',
195
                        'message' => 'form.type.select.notselect'
196
                    )),
197
                ), '[classcategory_id2]');
198
            }
199
200
        }
201
    }
202
}
203