GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (119)

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/Manager/AttributeManager.php (11 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
namespace PhpAbac\Manager;
4
5
use PhpAbac\Model\AbstractAttribute;
6
use PhpAbac\Model\Attribute;
7
use PhpAbac\Model\EnvironmentAttribute;
8
9
class AttributeManager
10
{
11
    /** @var array **/
12
    private $attributes;
13
    
14
    /** @var string Prefix to add before getter name (default)'get' */
15
    private $getter_prefix = 'get';
16
    /** @var string Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' */
17
    private $getter_name_transformation_function = 'ucfirst';
18
    
19
20
    /**
21
     * @param array $attributes
22
	 * @param array $options           A List of option to configure This Abac Instance
23
	 *                                 Options list :
24
	 *                                 'getter_prefix' => Prefix to add before getter name (default)'get'
25
	 *                                 'getter_name_transformation_function' => Function to apply on the getter name ( before adding prefix ) (default)'ucfirst'
26
     */
27 28
    public function __construct($attributes, $options = [])
28
    {
29 28
        $this->attributes = $attributes;
30
	
31 28
		$options = array_intersect_key( $options, array_flip( [
32 28
			'getter_prefix',
33 28
			'getter_name_transformation_function',
34 28
		] ) );
35
		
36 28
		foreach($options as $name => $value) {
0 ignored issues
show
Expected 1 space after FOREACH keyword; 0 found
Loading history...
37
			$this->$name = $value;
38 28
		}
39 28
    }
40
41
    /**
42
     * @param string $attributeId
43
     * @return \PhpAbac\Model\AbstractAttribute
44
     */
45 11
    public function getAttribute($attributeId) {
46 11
        $attributeKeys = explode('.', $attributeId);
47
        // The first element will be the attribute ID, then the field ID
48 11
        $attributeId = array_shift($attributeKeys);
49 11
        $attributeName = implode('.', $attributeKeys);
50
        // The field ID is also the attribute object property
51 11
        $attributeData = $this->attributes[$attributeId];
52
        return
53 11
            ($attributeId === 'environment')
54 11
            ? $this->getEnvironmentAttribute($attributeData, $attributeName)
55 11
            : $this->getClassicAttribute($attributeData, $attributeName)
56 11
        ;
57
    }
58
59
    /**
60
     * @param array $attributeData
61
     * @param string $property
62
     * @return \PhpAbac\Model\Attribute
63
     */
64 9
    private function getClassicAttribute($attributeData, $property) {
65
        return
66 9
            (new Attribute())
67 9
            ->setName($attributeData['fields'][$property]['name'])
68 9
            ->setType($attributeData['type'])
69 9
            ->setProperty($property)
70 9
            ->setSlug($this->slugify($attributeData['fields'][$property]['name']))
71 9
        ;
72
    }
73
74
    /**
75
     * @param array $attributeData
76
     * @param string $key
77
     * @return \PhpAbac\Model\EnvironmentAttribute
78
     */
79 4
    private function getEnvironmentAttribute($attributeData, $key) {
80
        return
81 4
            (new EnvironmentAttribute())
82 4
            ->setName($attributeData[$key]['name'])
83 4
            ->setType('environment')
84 4
            ->setVariableName($attributeData[$key]['variable_name'])
85 4
            ->setSlug($this->slugify($attributeData[$key]['name']))
86 4
        ;
87
    }
88
89
    /**
90
     * @param AbstractAttribute $attribute
91
     * @param string $attributeType
0 ignored issues
show
There is no parameter named $attributeType. Did you maybe mean $attribute?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
92
     * @param object $user
93
     * @param object $object
94
     * @return mixed
95
     */
96 9
    public function retrieveAttribute(AbstractAttribute $attribute, $user = null, $object = null, $getter_params = [])
97
    {
98 9
        switch($attribute->getType()) {
0 ignored issues
show
Expected 1 space after SWITCH keyword; 0 found
Loading history...
99 9
            case 'user':
100 6
                return $this->retrieveClassicAttribute($attribute, $user, $getter_params);
0 ignored issues
show
$attribute of type object<PhpAbac\Model\AbstractAttribute> is not a sub-type of object<PhpAbac\Model\Attribute>. It seems like you assume a child class of the class PhpAbac\Model\AbstractAttribute to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
It seems like $user defined by parameter $user on line 96 can also be of type null; however, PhpAbac\Manager\Attribut...rieveClassicAttribute() does only seem to accept object, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
101 6
            case 'resource':
102 5
                return $this->retrieveClassicAttribute($attribute, $object);
0 ignored issues
show
$attribute of type object<PhpAbac\Model\AbstractAttribute> is not a sub-type of object<PhpAbac\Model\Attribute>. It seems like you assume a child class of the class PhpAbac\Model\AbstractAttribute to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
It seems like $object defined by parameter $object on line 96 can also be of type null; however, PhpAbac\Manager\Attribut...rieveClassicAttribute() does only seem to accept object, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
103 2
            case 'environment':
104 2
                return $this->retrieveEnvironmentAttribute($attribute);
0 ignored issues
show
$attribute of type object<PhpAbac\Model\AbstractAttribute> is not a sub-type of object<PhpAbac\Model\EnvironmentAttribute>. It seems like you assume a child class of the class PhpAbac\Model\AbstractAttribute to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
105
        }
106
    }
107
108
    /**
109
     * @param Attribute $attribute
110
     * @param object $object
111
     * @return mixed
112
     */
113 8
    private function retrieveClassicAttribute(Attribute $attribute, $object, $getter_params = [])
114
    {
115 8
        $propertyPath = explode('.', $attribute->getProperty());
116 8
        $propertyValue = $object;
117 8
        foreach($propertyPath as $property) {
0 ignored issues
show
Expected 1 space after FOREACH keyword; 0 found
Loading history...
Blank line found at start of control structure
Loading history...
118
	
119
        	
120 8
			$getter = $this->getter_prefix.call_user_func($this->getter_name_transformation_function,$property);
121
            // Use is_callable, instead of method_exists, to deal with __call magic method
122 8
            if(!is_callable([$propertyValue,$getter])) {
0 ignored issues
show
Expected 1 space after IF keyword; 0 found
Loading history...
123
                throw new \InvalidArgumentException('There is no getter for the "'.$attribute->getProperty().'" attribute for object "'.get_class($propertyValue).'" with getter "'.$getter.'"');
124
            }
125 8
			if ( ( $propertyValue = call_user_func_array( [
126 8
					$propertyValue,
127 8
					$getter,
128 8
				], isset( $getter_params[ $property ] ) ? $getter_params[ $property ] : [] ) ) === null
129 8
			) {
130 1
				return null;
131
			}
132 8
        }
133 8
        return $propertyValue;
134
    }
135
136
    /**
137
     *
138
     * @param \PhpAbac\Model\EnvironmentAttribute $attribute
139
     * @return mixed
140
     */
141 2
    private function retrieveEnvironmentAttribute(EnvironmentAttribute $attribute) {
142 2
        return getenv($attribute->getVariableName());
143
    }
144
145
    /*
146
     * @param string $name
147
     * @return string
148
     */
149 11
    public function slugify($name)
150
    {
151
        // replace non letter or digits by -
152 11
        $name = trim(preg_replace('~[^\\pL\d]+~u', '-', $name), '-');
153
        // transliterate
154 11
        if (function_exists('iconv')) {
155 11
            $name = iconv('utf-8', 'us-ascii//TRANSLIT', $name);
156 11
        }
157
        // remove unwanted characters
158 11
        $name = preg_replace('~[^-\w]+~', '', strtolower($name));
159 11
        if (empty($name)) {
160
            return 'n-a';
161
        }
162 11
        return $name;
163
    }
164
}
165