Issues (110)

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.

src/Wrappers/ArrayWrapper.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 declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Wrappers;
17
18
19
use V8\ArrayObject;
20
use V8\Context;
21
use V8\IntegerValue;
22
use V8\Isolate;
23
use V8\ObjectValue;
24
25
26
class ArrayWrapper implements WrapperInterface, WrapperAwareInterface
27
{
28
    use WrapperAwareTrait;
29
30
    /**
31
     * @param Isolate $isolate
32
     * @param Context $context
33
     * @param array   $value
34
     *
35
     * @return ArrayObject|ObjectValue
36
     * @throws WrapperException
37
     */
38
    public function wrap(Isolate $isolate, Context $context, $value)
39
    {
40
        // NOTE: js arrays, unlike php, will have gaps if indices are not monotonically increasing from 0.
41
        //       Also, non-integer keys does not affect array length as they become properties of array object,
42
        //       so if we have associative array, we will wrap it as object.
43
        if ($this->isAssoc($value)) {
44
            return $this->wrapAsObject($isolate, $context, $value);
45
        } else {
46
            return $this->wrapAsArray($isolate, $context, $value);
47
        }
48
    }
49
50
    private function isAssoc(array $value)
51
    {
52
        if (!$value) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $value of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
53
            return false;
54
        }
55
56
        sort($value);
57
58
        return array_keys($value) != range(0, count($value) - 1);
59
    }
60
61 View Code Duplication
    private function wrapAsArray(Isolate $isolate, Context $context, array $value): ArrayObject
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...
62
    {
63
        $ret = new ArrayObject($context);
64
        // TODO: write test to ensure items have the same order, sort() was breaking that order
65
        $key = 0;
66
        foreach ($value as $val) {
67
            $js_val = $this->wrapper->wrap($isolate, $context, $val);
68
            $js_key = new IntegerValue($isolate, $key++);
69
            $ret->set($context, $js_key, $js_val);
70
        }
71
72
        return $ret;
73
    }
74
75 View Code Duplication
    private function wrapAsObject(Isolate $isolate, Context $context, array $value): ObjectValue
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...
76
    {
77
        $ret = new ObjectValue($context);
78
79
        foreach ($value as $key => $val) {
80
            $js_val = $this->wrapper->wrap($isolate, $context, $val);
81
            $js_key = $this->wrapper->wrap($isolate, $context, $key);
82
            $ret->set($context, $js_key, $js_val);
83
        }
84
85
        return $ret;
86
    }
87
}
88