Issues (191)

Security Analysis    no request data  

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.

lib/ILess/Node/ExpressionNode.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
/*
4
 * This file is part of the ILess
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace ILess\Node;
11
12
use ILess\Context;
13
use ILess\Exception\Exception;
14
use ILess\Node;
15
use ILess\Output\OutputInterface;
16
use ILess\Visitor\VisitorInterface;
17
18
/**
19
 * Expression.
20
 */
21
class ExpressionNode extends Node implements MarkableAsReferencedInterface
22
{
23
    /**
24
     * Node type.
25
     *
26
     * @var string
27
     */
28
    protected $type = 'Expression';
29
30
    /**
31
     * Parens flag.
32
     *
33
     * @var bool
34
     */
35
    public $parens = false;
36
37
    /**
38
     * Parens in operator flag.
39
     *
40
     * @var bool
41
     */
42
    public $parensInOp = false;
43
44
    /**
45
     * Constructor.
46
     *
47
     * @param array $value
48
     *
49
     * @throws Exception
50
     */
51
    public function __construct(array $value)
52
    {
53
        parent::__construct($value);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function accept(VisitorInterface $visitor)
60
    {
61
        $this->value = $visitor->visitArray($this->value);
0 ignored issues
show
$this->value is of type object<ILess\Node>|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...
62
    }
63
64
    /**
65
     * Compiles the node.
66
     *
67
     * @param Context $context The context
68
     * @param array|null $arguments Array of arguments
69
     * @param bool|null $important Important flag
70
     *
71
     * @return ParenNode|ExpressionNode|Node
72
     */
73
    public function compile(Context $context, $arguments = null, $important = null)
74
    {
75
        $inParenthesis = $this->parens && !$this->parensInOp;
76
        $doubleParen = false;
77
78
        if ($inParenthesis) {
79
            $context->inParenthesis();
80
        }
81
        $count = count($this->value);
82
        if ($count > 1) {
83
            $compiled = [];
84
            foreach ($this->value as $v) {
0 ignored issues
show
The expression $this->value of type object<ILess\Node>|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
85
                /* @var $v Node */
86
                $compiled[] = $v->compile($context);
87
            }
88
            $return = new self($compiled);
89
        } elseif ($count === 1) {
90
            if (property_exists($this->value[0], 'parens') && $this->value[0]->parens
91
                && property_exists($this->value[0], 'parensInOp') && !$this->value[0]->parensInOp
92
            ) {
93
                $doubleParen = true;
94
            }
95
            $return = $this->value[0]->compile($context);
96
        } else {
97
            $return = $this;
98
        }
99
100
        if ($inParenthesis) {
101
            $context->outOfParenthesis();
102
        }
103
104
        if ($this->parens && $this->parensInOp && !($context->isMathOn()) && !$doubleParen) {
105
            $return = new ParenNode($return);
106
        }
107
108
        return $return;
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function generateCSS(Context $context, OutputInterface $output)
115
    {
116
        for ($i = 0, $count = count($this->value); $i < $count; ++$i) {
117
            $this->value[$i]->generateCSS($context, $output);
118
            if ($i + 1 < $count) {
119
                $output->add(' ');
120
            }
121
        }
122
    }
123
124
    public function throwAwayComments()
125
    {
126
        if (is_array($this->value)) {
127
            $new = [];
128
            foreach ($this->value as $v) {
129
                if ($v instanceof CommentNode) {
130
                    continue;
131
                }
132
                $new[] = $v;
133
            }
134
            $this->value = $new;
0 ignored issues
show
Documentation Bug introduced by
It seems like $new of type array is incompatible with the declared type object<ILess\Node>|string of property $value.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
135
        }
136
    }
137
138
    /**
139
     * Marks as referenced.
140
     */
141
    public function markReferenced()
142
    {
143
        foreach ($this->value as $value) {
0 ignored issues
show
The expression $this->value of type object<ILess\Node>|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
144
            if ($value instanceof MarkableAsReferencedInterface) {
145
                $value->markReferenced();
146
            }
147
        }
148
    }
149
}
150