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.

tests/JSONTextTest.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
2
3
/**
4
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 */
8
9
use PhpTek\JSONText\ORM\FieldType\JSONText;
10
use SilverStripe\Dev\SapphireTest;
11
use SilverStripe\ORM\FieldType\DBFloat;
12
use SilverStripe\ORM\FieldType\DBBoolean;
13
use SilverStripe\ORM\FieldType\DBVarchar;
14
use SilverStripe\ORM\FieldType\DBInt;
15
16
class JSONTextTest extends SapphireTest
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $fixtures = [
22
        'array'     => 'fixtures/json/array.json',
23
        'object'    => 'fixtures/json/object.json'
24
    ];
25
26
    /**
27
     * JSONTextTest constructor.
28
     *
29
     * Modify fixtures property to be able to run on PHP <5.6 without use of constant in class property which 5.6+ allows
30
     */
31 View Code Duplication
    public function __construct()
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...
32
    {
33
        foreach($this->fixtures as $name => $path) {
34
            $this->fixtures[$name] = realpath(__DIR__) . '/' . $path;
35
        }
36
        
37
        parent::__construct();
38
    }
39
40
    /**
41
     * @todo There are a ton more permutations of a JSONPath regex
42
     * See the trace() method in JSONPath for more examples to work from
43
     */
44 View Code Duplication
    public function testIsValidExpression()
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...
45
    {
46
        $field = JSONText::create('MyJSON');
47
48
        $this->assertTrue($field->isValidExpression('$..'));
49
        $this->assertTrue($field->isValidExpression('*'));
50
        $this->assertTrue($field->isValidExpression('$.[2]'));
51
        $this->assertTrue($field->isValidExpression('$.cars.american[*]'));
52
        $this->assertTrue($field->isValidExpression('[0:1:1]'));
53
        $this->assertFalse($field->isValidExpression('[0:1:]'));
54
        $this->assertFalse($field->isValidExpression('[0:1:1'));
55
        $this->assertFalse($field->isValidExpression(''));
56
        $this->assertFalse($field->isValidExpression('$.1.cars.american[*]'));
57
        $this->assertFalse($field->isValidExpression('$'));
58
        $this->assertFalse($field->isValidExpression('$[2]'));
59
    }
60
61
    /**
62
     * @return void
63
     */
64 View Code Duplication
    public function testIsValidJson()
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...
65
    {
66
        $field = JSONText::create('MyJSON');
67
68
        $this->assertFalse($field->isValidJson(''));
69
        $this->assertTrue($field->isValidJson('true'));
70
        $this->assertTrue($field->isValidJson('false'));
71
        $this->assertFalse($field->isValidJson('null'));
72
        $this->assertFalse($field->isValidJson("['one']"));
73
        $this->assertFalse($field->isValidJson('["one]'));
74
        $this->assertFalse($field->isValidJson('{{{'));
75
        $this->assertTrue($field->isValidJson('[]'));
76
        $this->assertTrue($field->isValidJson('["one"]'));
77
        $this->assertTrue($field->isValidJson('["one","two"]'));
78
        $this->assertTrue($field->isValidJson('{"cars":{"american":["buick","oldsmobile"]}}'));
79
    }
80
81
82
    /**
83
     * Ordinarily we can just use !is_null(json_decode($json)) but SS allows empty strings passed to setValue() so we need
84
     * to allow otherwise invalid JSON by means of an optional 2nd param
85
     *
86
     * @return void
87
     */
88
    public function testIsValidDBValue()
89
    {
90
        $field = JSONText::create('MyJSON');
91
92
        $this->assertFalse($field->isValidDBValue('true'));
93
        $this->assertFalse($field->isValidDBValue('false'));
94
        $this->assertFalse($field->isValidDBValue('null'));
95
        $this->assertTrue($field->isValidDBValue(''));
96
        $this->assertTrue($field->isValidDBValue('["one","two"]'));
97
        $this->assertTrue($field->isValidDBValue('{"cars":{"american":["buick","oldsmobile"]}}'));
98
    }
99
100
    /**
101
     * Properly excercise our internal SS type conversion.
102
     */
103
    public function testToSSTypes()
104
    {
105
        $field = JSONText::create('MyJSON');
106
        $field->setValue($this->getFixture('array'));
107
        $field->setReturnType('silverstripe');
108
109
        $data = $field->last()[6];
110
        $this->assertInstanceOf(DBFloat::class, $data);
111
112
        $data = $field->first()[0];
113
        $this->assertInstanceOf(DBVarchar::class, $data);
114
115
        $data = $field->nth(5)[5];
116
        $this->assertInstanceOf(DBInt::class, $data);
117
118
        $data = $field->nth(1)[1];
119
        $this->assertInstanceOf(DBBoolean::class, $data);
120
121
        $field->setValue('["true"]');
122
        $data = $field->first()[0];
123
        $this->assertInstanceOf(DBVarchar::class, $data);
124
    }
125
126
    /**
127
     * Get the contents of a fixture
128
     *
129
     * @param string $fixture
130
     * @return string
131
     */
132
    private function getFixture($fixture)
133
    {
134
        $files = $this->fixtures;
135
        return file_get_contents($files[$fixture]);
136
    }
137
}
138