Issues (19)

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/Constraint/DraftFour/AdditionalProperties.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
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard;
6
use League\JsonGuard\Assert;
7
use League\JsonGuard\ConstraintInterface;
8
use League\JsonGuard\Validator;
9
use function League\JsonGuard\error;
10
use function League\JsonGuard\pointer_push;
11
12
final class AdditionalProperties implements ConstraintInterface
13
{
14
    const KEYWORD = 'additionalProperties';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 16
    public function validate($value, $parameter, Validator $validator)
20
    {
21 16
        Assert::type($parameter, ['object', 'boolean'], self::KEYWORD, $validator->getSchemaPath());
22
23 14
        if (!is_object($value)) {
24 4
            return null;
25
        }
26
27 14
        $diff = self::getDiff($value, $validator->getSchema());
28
29 14
        if (count($diff) === 0) {
30 10
            return null;
31
        }
32
33 12
        if ($parameter === false) {
34 8
            return error('The object must not contain additional properties ({cause}).', $validator)
35 8
                ->withCause($diff);
36 6
        } elseif (is_object($parameter)) {
37
            // If additionalProperties is an object it's a schema,
38
            // so validate all additional properties against it.
39 6
            $errors = [];
40 6 View Code Duplication
            foreach ($diff as $property) {
0 ignored issues
show
Duplication introduced by Matt A
This code seems to be duplicated across 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...
41 6
                $subValidator = $validator->makeSubSchemaValidator(
42 6
                    $value->$property,
43 6
                    $parameter,
44 6
                    pointer_push($validator->getDataPath(), $property)
45
                );
46 6
                $errors = array_merge($errors, $subValidator->errors());
47
            }
48
49 6
            return $errors;
50
        }
51
    }
52
53
    /**
54
     * Get the properties in $value which are not in $schema 'properties' or matching 'patternProperties'.
55
     *
56
     * @param object $value
57
     * @param object $schema
58
     *
59
     * @return array
60
     */
61 14
    private static function getDiff($value, $schema)
62
    {
63 14
        if (property_exists($schema, Properties::KEYWORD)) {
64 10
            $definedProperties = array_keys(get_object_vars($schema->properties));
65
        } else {
66 6
            $definedProperties = [];
67
        }
68
69 14
        $actualProperties = array_keys(get_object_vars($value));
70 14
        $diff             = array_diff($actualProperties, $definedProperties);
71
72
        // The diff doesn't account for patternProperties, so lets filter those out too.
73 14
        if (property_exists($schema, PatternProperties::KEYWORD)) {
74 4
            foreach ($schema->patternProperties as $property => $schema) {
75 4
                $matches = JsonGuard\properties_matching_pattern($property, $diff);
76 4
                $diff    = array_diff($diff, $matches);
77
            }
78
79 4
            return $diff;
80
        }
81
82 12
        return $diff;
83
    }
84
}
85