Issues (29)

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.

code/Backend/PostgresJSONBackend.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
/**
4
 * JSONText database backend that encapsulates a Postgres-like syntax for JSON querying.
5
 * 
6
 * @package silverstripe-jsontext
7
 * @subpackage models
8
 * @author Russell Michell <[email protected]>
9
 * @see https://www.postgresql.org/docs/9.6/static/functions-json.html
10
 */
11
12
namespace PhpTek\JSONText\Backend;
13
14
use PhpTek\JSONText\Exception\JSONTextInvalidArgsException;
15
16
class PostgresJSONBackend extends JSONBackend
17
{
18
    /**
19
     * An array of acceptable operators for this backend.
20
     * 
21
     * @var array
22
     * @config
23
     */
24
    private static $allowed_operators = [
25
        'matchOnInt'    => '->',
26
        'matchOnStr'    => '->>',
27
        'matchOnPath'   => '#>'
28
    ];
29
    
30
    /**
31
     * @inheritdoc
32
     */
33 View Code Duplication
    public function matchOnInt()
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...
34
    {
35
        if (!\is_int($this->operand)) {
36
            $msg = 'Non-integer passed to: ' . __FUNCTION__ . '()';
37
            throw new JSONTextInvalidArgsException($msg);
38
        }
39
        
40
        $expr = '$.[' . $this->operand . ']';
41
        $fetch = $this->jsonText->getJSONStore()->get($expr);
42
        $vals = \array_values($fetch);
43
        
44
        if (isset($vals[0])) {
45
            return [$this->operand => $vals[0]];
46
        }
47
48
        return [];
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 View Code Duplication
    public function matchOnStr()
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...
55
    {
56
        if (!\is_string($this->operand)) {
57
            $msg = 'Non-string passed to: ' . __FUNCTION__ . '()';
58
            throw new JSONTextInvalidArgsException($msg);
59
        }
60
        
61
        $expr = '$..' . $this->operand;
62
        $fetch = $this->jsonText->getJSONStore()->get($expr);
63
        $vals = \array_values($fetch);
64
65
        if (isset($vals[0])) {
66
            return [$this->operand => $vals[0]];
67
        }
68
69
        return [];
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function matchOnPath()
76
    {
77
        if (!\is_string($this->operand) || !$this->jsonText->isValidJson($this->operand)) {
78
            $msg = 'Invalid JSON passed as operand on RHS.';
79
            throw new JSONTextInvalidArgsException($msg);
80
        }
81
        
82
        $operandAsArray = $this->jsonText->toArray($this->operand);
83
        
84
        if (!\count($operandAsArray)) {
85
            return [];
86
        }
87
88
        $keys = \array_keys($operandAsArray);
89
        $vals = \array_values($operandAsArray);
90
        
91
        if (\count($keys) > 1 || \count($vals) > 1) {
92
            $msg = 'Sorry. I can\'t handle complex operands.';
93
            throw new JSONTextInvalidArgsException($msg);
94
        }
95
96
        $source = $this->jsonText->getStoreAsArray();
97
        $sourceAsIterator = new \RecursiveIteratorIterator(
98
            new \RecursiveArrayIterator($source),
99
            \RecursiveIteratorIterator::SELF_FIRST
100
        );
101
        
102
        $data = [];
103
        foreach ($sourceAsIterator as $sourceKey => $sourceVal) {
104
            if ($keys[0] === $sourceKey && is_array($sourceVal) && !empty($sourceVal[$vals[0]])) {
105
                $data[] = $sourceVal[$vals[0]];
106
            }
107
        }
108
109
        return $data;
110
    }
111
    
112
}
113