Passed
Branch v1.3 (5b46b6)
by Mostafa Abd El-Salam
02:58
created

HasRoles::convertToRoleModels()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Maklad\Permission\Traits;
5
6
use Illuminate\Support\Collection;
7
use Jenssegers\Mongodb\Eloquent\Builder;
8
use Jenssegers\Mongodb\Eloquent\Model;
9
use Jenssegers\Mongodb\Relations\BelongsToMany;
10
use Maklad\Permission\Contracts\PermissionInterface as Permission;
11
use Maklad\Permission\Contracts\RoleInterface as Role;
12
13
/**
14
 * Trait HasRoles
15
 * @package Maklad\Permission\Traits
16
 */
17
trait HasRoles
18
{
19
    use HasPermissions;
20
21
    public static function bootHasRoles()
22
    {
23 110
        static::deleting(function (Model $model) {
24 2
            foreach ($model->roles as $role) {
25 1
                $role->users()->detach($model);
26
            }
27 2
            foreach ($model->permissions as $permission) {
28 1
                $permission->users()->detach($model);
29
            }
30 110
        });
31 110
    }
32
33
    /**
34
     * A model may have multiple roles.
35
     */
36 63
    public function roles(): BelongsToMany
37
    {
38 63
        return $this->belongsToMany(\config('permission.models.role'))->withTimestamps();
0 ignored issues
show
Bug introduced by
It seems like belongsToMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Security Code Execution introduced by
\config('permission.models.role') can contain request data and is used in code execution context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_SERVER, and $server is assigned
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  2. Data is passed through array_replace()
    in vendor/Request.php on line 360
  3. Data is passed through call_user_func()
    in vendor/Request.php on line 2019
  4. \Illuminate\Http\Request::create($uri, 'GET', array(), array(), array(), $server) is passed to Container::instance()
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 31
  5. Container::$instances is assigned
    in vendor/src/Illuminate/Container/Container.php on line 371
  6. Tainted property Container::$instances is read
    in vendor/src/Illuminate/Container/Container.php on line 597
  7. Container::resolve() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 575
  8. Container::make() returns tainted data
    in vendor/src/Illuminate/Foundation/helpers.php on line 106
  9. app() returns tainted data
    in vendor/src/Illuminate/Foundation/helpers.php on line 262
  10. config() returns tainted data
    in src/Traits/HasRoles.php on line 38

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
39
    }
40
41
    /**
42
     * A model may have multiple direct permissions.
43
     */
44 30
    public function permissions(): BelongsToMany
45
    {
46 30
        return $this->belongsToMany(\config('permission.models.permission'))->withTimestamps();
0 ignored issues
show
Bug introduced by
It seems like belongsToMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Security Code Execution introduced by
\config('permission.models.permission') can contain request data and is used in code execution context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_SERVER, and $server is assigned
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  2. Data is passed through array_replace()
    in vendor/Request.php on line 360
  3. Data is passed through call_user_func()
    in vendor/Request.php on line 2019
  4. \Illuminate\Http\Request::create($uri, 'GET', array(), array(), array(), $server) is passed to Container::instance()
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 31
  5. Container::$instances is assigned
    in vendor/src/Illuminate/Container/Container.php on line 371
  6. Tainted property Container::$instances is read
    in vendor/src/Illuminate/Container/Container.php on line 597
  7. Container::resolve() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 575
  8. Container::make() returns tainted data
    in vendor/src/Illuminate/Foundation/helpers.php on line 106
  9. app() returns tainted data
    in vendor/src/Illuminate/Foundation/helpers.php on line 262
  10. config() returns tainted data
    in src/Traits/HasRoles.php on line 46

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
47
    }
48
49
    /**
50
     * Scope the model query to certain roles only.
51
     *
52
     * @param Builder $query
53
     * @param string|array|Role|Collection $roles
54
     *
55
     * @return Builder
56
     */
57 4
    public function scopeRole(Builder $query, $roles): Builder
58
    {
59 4
        $roles = $this->convertToRoleModels($roles);
60
61 4
        return $query->whereIn('role_ids', $roles->pluck('_id'));
62
    }
63
64
    /**
65
     * Scope the model query to certain permissions only.
66
     *
67
     * @param Builder $query
68
     * @param string|array|Permission|Collection $permissions
69
     *
70
     * @return Builder
71
     */
72 7
    public function scopePermission(Builder $query, $permissions): Builder
73
    {
74 7
        $permissions = $this->convertToPermissionModels($permissions);
75
76 6
        $roles = \collect([]);
77
78 6
        foreach ($permissions as $permission) {
79 6
            $roles = $roles->merge($permission->roles);
80
        }
81 6
        $roles = $roles->unique();
82
83 6
        return $query->orWhereIn('permission_ids', $permissions->pluck('_id'))
84 6
                     ->orWhereIn('role_ids', $roles->pluck('_id'));
85
    }
86
87
    /**
88
     * Assign the given role to the model.
89
     *
90
     * @param array|string|Role ...$roles
91
     *
92
     * @return $this
93
     */
94 50 View Code Duplication
    public function assignRole(...$roles)
0 ignored issues
show
Duplication introduced by
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...
95
    {
96 50
        $roles = \collect($roles)
97 50
            ->flatten()
98 50
            ->map(function ($role) {
99 50
                return $this->getStoredRole($role);
100 50
            })
101 48
            ->each(function ($role) {
102 48
                $this->ensureModelSharesGuard($role);
103 48
            })
104 46
            ->all();
105
106 46
        $this->roles()->saveMany($roles);
0 ignored issues
show
Security File Exposure introduced by
$roles can contain request data and is used in file inclusion context(s) leading to a potential security vulnerability.

9 paths for user data to reach this point

  1. Path: $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned in ServerBag.php on line 62
  1. $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
    in vendor/ServerBag.php on line 62
  2. ParameterBag::$parameters is assigned
    in vendor/ServerBag.php on line 77
  3. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  4. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  5. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  6. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  7. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  8. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  9. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  2. Path: Read from $_POST, and $_POST is passed to Request::createRequestFromFactory() in Request.php on line 317
  1. Read from $_POST, and $_POST is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  2. $request is passed to Request::__construct()
    in vendor/Request.php on line 2028
  3. $request is passed to Request::initialize()
    in vendor/Request.php on line 258
  4. $request is passed to ParameterBag::__construct()
    in vendor/Request.php on line 276
  5. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  6. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  7. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  8. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  9. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  10. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  11. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  12. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  3. Path: Read from $_SERVER, and $server is assigned in Request.php on line 307
  1. Read from $_SERVER, and $server is assigned
    in vendor/Request.php on line 307
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  4. Path: Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned in Request.php on line 310
  1. Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned
    in vendor/Request.php on line 310
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  5. Path: Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned in Request.php on line 313
  1. Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned
    in vendor/Request.php on line 313
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  6. Path: $server['HTTP_HOST'] seems to return tainted data, and $server is assigned in Request.php on line 383
  1. $server['HTTP_HOST'] seems to return tainted data, and $server is assigned
    in vendor/Request.php on line 383
  2. $server is assigned
    in vendor/Request.php on line 431
  3. $server is assigned
    in vendor/Request.php on line 432
  4. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 434
  5. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  6. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  7. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  8. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  9. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  10. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  11. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  12. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  13. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  14. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  15. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  7. Path: $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 43
  1. $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 43
  2. $headers is assigned
    in vendor/ServerBag.php on line 44
  3. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  4. $values is assigned
    in vendor/HeaderBag.php on line 31
  5. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  6. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  7. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  8. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  9. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  10. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  11. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  12. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  13. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  14. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  15. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  16. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  17. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  18. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  19. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  8. Path: $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 44
  1. $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 44
  2. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  3. $values is assigned
    in vendor/HeaderBag.php on line 31
  4. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  5. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  6. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  7. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  8. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  9. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  10. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  11. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  12. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  13. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  14. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  15. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  16. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  17. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  18. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  9. Path: Read from $_SERVER, and $server is assigned in src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  1. Read from $_SERVER, and $server is assigned
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  2. Data is passed through array_replace()
    in vendor/Request.php on line 360
  3. Data is passed through call_user_func()
    in vendor/Request.php on line 2019
  4. \Illuminate\Http\Request::create($uri, 'GET', array(), array(), array(), $server) is passed to Container::instance()
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 31
  5. Container::$instances is assigned
    in vendor/src/Illuminate/Container/Container.php on line 371
  6. Tainted property Container::$instances is read
    in vendor/src/Illuminate/Container/Container.php on line 597
  7. Container::resolve() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 575
  8. Container::make() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 1172
  9. Container::offsetGet() returns tainted data, and $table is assigned
    in vendor/src/Illuminate/Session/SessionManager.php on line 74
  10. $table is passed to DatabaseSessionHandler::__construct()
    in vendor/src/Illuminate/Session/SessionManager.php on line 79
  11. DatabaseSessionHandler::$table is assigned
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 61
  12. Tainted property DatabaseSessionHandler::$table is read, and $this->table is passed to Connection::table()
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 274
  13. $table is passed to Builder::from()
    in vendor/src/Illuminate/Database/Connection.php on line 258
  14. Builder::$from is assigned
    in vendor/src/Illuminate/Database/Query/Builder.php on line 327
  15. Tainted property Builder::$from is read, and $query->from is passed to Grammar::wrapTable()
    in vendor/src/Illuminate/Database/Query/Grammars/Grammar.php on line 772
  16. $this->tablePrefix . $table is passed to Grammar::wrap()
    in vendor/src/Illuminate/Database/Grammar.php on line 36
  17. $value is passed through explode(), and explode('.', $value) is passed to Grammar::wrapSegments()
    in vendor/src/Illuminate/Database/Grammar.php on line 62
  18. $segments is passed to collect()
    in vendor/src/Illuminate/Database/Grammar.php on line 96
  19. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  20. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  21. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  22. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96

Used in path-read context

  1. BelongsToMany::saveMany() uses Arr::get() ($key)
    in vendor/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php on line 727
  2. Arr::get() uses Repository::offsetGet() ($key)
    in vendor/src/Illuminate/Support/Arr.php on line 285
  3. Repository::offsetGet() uses Repository::get() ($key)
    in vendor/src/Illuminate/Cache/Repository.php on line 454
  4. Repository::get() uses FileStore::get() ($key)
    in vendor/src/Illuminate/Cache/Repository.php on line 84
  5. FileStore::get() uses FileStore::getPayload() ($key)
    in vendor/src/Illuminate/Cache/FileStore.php on line 50
  6. FileStore::getPayload() uses Filesystem::get() ($path)
    in vendor/src/Illuminate/Cache/FileStore.php on line 173
  7. Filesystem::get() uses file_get_contents() ($filename)
    in vendor/src/Illuminate/Filesystem/Filesystem.php on line 38

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
Security File Manipulation introduced by
$roles can contain request data and is used in file manipulation context(s) leading to a potential security vulnerability.

9 paths for user data to reach this point

  1. Path: $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned in ServerBag.php on line 62
  1. $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
    in vendor/ServerBag.php on line 62
  2. ParameterBag::$parameters is assigned
    in vendor/ServerBag.php on line 77
  3. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  4. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  5. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  6. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  7. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  8. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  9. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  2. Path: Read from $_POST, and $_POST is passed to Request::createRequestFromFactory() in Request.php on line 317
  1. Read from $_POST, and $_POST is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  2. $request is passed to Request::__construct()
    in vendor/Request.php on line 2028
  3. $request is passed to Request::initialize()
    in vendor/Request.php on line 258
  4. $request is passed to ParameterBag::__construct()
    in vendor/Request.php on line 276
  5. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  6. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  7. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  8. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  9. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  10. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  11. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  12. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  3. Path: Read from $_SERVER, and $server is assigned in Request.php on line 307
  1. Read from $_SERVER, and $server is assigned
    in vendor/Request.php on line 307
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  4. Path: Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned in Request.php on line 310
  1. Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned
    in vendor/Request.php on line 310
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  5. Path: Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned in Request.php on line 313
  1. Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned
    in vendor/Request.php on line 313
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  6. Path: $server['HTTP_HOST'] seems to return tainted data, and $server is assigned in Request.php on line 383
  1. $server['HTTP_HOST'] seems to return tainted data, and $server is assigned
    in vendor/Request.php on line 383
  2. $server is assigned
    in vendor/Request.php on line 431
  3. $server is assigned
    in vendor/Request.php on line 432
  4. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 434
  5. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  6. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  7. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  8. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  9. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  10. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  11. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  12. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  13. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  14. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  15. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  7. Path: $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 43
  1. $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 43
  2. $headers is assigned
    in vendor/ServerBag.php on line 44
  3. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  4. $values is assigned
    in vendor/HeaderBag.php on line 31
  5. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  6. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  7. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  8. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  9. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  10. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  11. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  12. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  13. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  14. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  15. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  16. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  17. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  18. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  19. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  8. Path: $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 44
  1. $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 44
  2. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  3. $values is assigned
    in vendor/HeaderBag.php on line 31
  4. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  5. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  6. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  7. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  8. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  9. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  10. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  11. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  12. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  13. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  14. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  15. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  16. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  17. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  18. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  9. Path: Read from $_SERVER, and $server is assigned in src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  1. Read from $_SERVER, and $server is assigned
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  2. Data is passed through array_replace()
    in vendor/Request.php on line 360
  3. Data is passed through call_user_func()
    in vendor/Request.php on line 2019
  4. \Illuminate\Http\Request::create($uri, 'GET', array(), array(), array(), $server) is passed to Container::instance()
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 31
  5. Container::$instances is assigned
    in vendor/src/Illuminate/Container/Container.php on line 371
  6. Tainted property Container::$instances is read
    in vendor/src/Illuminate/Container/Container.php on line 597
  7. Container::resolve() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 575
  8. Container::make() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 1172
  9. Container::offsetGet() returns tainted data, and $table is assigned
    in vendor/src/Illuminate/Session/SessionManager.php on line 74
  10. $table is passed to DatabaseSessionHandler::__construct()
    in vendor/src/Illuminate/Session/SessionManager.php on line 79
  11. DatabaseSessionHandler::$table is assigned
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 61
  12. Tainted property DatabaseSessionHandler::$table is read, and $this->table is passed to Connection::table()
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 274
  13. $table is passed to Builder::from()
    in vendor/src/Illuminate/Database/Connection.php on line 258
  14. Builder::$from is assigned
    in vendor/src/Illuminate/Database/Query/Builder.php on line 327
  15. Tainted property Builder::$from is read, and $query->from is passed to Grammar::wrapTable()
    in vendor/src/Illuminate/Database/Query/Grammars/Grammar.php on line 772
  16. $this->tablePrefix . $table is passed to Grammar::wrap()
    in vendor/src/Illuminate/Database/Grammar.php on line 36
  17. $value is passed through explode(), and explode('.', $value) is passed to Grammar::wrapSegments()
    in vendor/src/Illuminate/Database/Grammar.php on line 62
  18. $segments is passed to collect()
    in vendor/src/Illuminate/Database/Grammar.php on line 96
  19. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  20. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  21. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  22. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96

Used in path-write context

  1. BelongsToMany::saveMany() uses Arr::get() ($key)
    in vendor/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php on line 727
  2. Arr::get() uses Repository::offsetGet() ($key)
    in vendor/src/Illuminate/Support/Arr.php on line 285
  3. Repository::offsetGet() uses Repository::get() ($key)
    in vendor/src/Illuminate/Cache/Repository.php on line 454
  4. Repository::get() uses FileStore::get() ($key)
    in vendor/src/Illuminate/Cache/Repository.php on line 84
  5. FileStore::get() uses FileStore::getPayload() ($key)
    in vendor/src/Illuminate/Cache/FileStore.php on line 50
  6. FileStore::getPayload() uses FileStore::forget() ($key)
    in vendor/src/Illuminate/Cache/FileStore.php on line 183
  7. FileStore::forget() uses Filesystem::delete() ($paths)
    in vendor/src/Illuminate/Cache/FileStore.php on line 132
  8. Filesystem::delete() uses unlink() ($filename)
    in vendor/src/Illuminate/Filesystem/Filesystem.php on line 183

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
Security Object Injection introduced by
$roles can contain request data and is used in unserialized context(s) leading to a potential security vulnerability.

9 paths for user data to reach this point

  1. Path: $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned in ServerBag.php on line 62
  1. $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
    in vendor/ServerBag.php on line 62
  2. ParameterBag::$parameters is assigned
    in vendor/ServerBag.php on line 77
  3. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  4. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  5. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  6. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  7. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  8. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  9. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  2. Path: Read from $_POST, and $_POST is passed to Request::createRequestFromFactory() in Request.php on line 317
  1. Read from $_POST, and $_POST is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  2. $request is passed to Request::__construct()
    in vendor/Request.php on line 2028
  3. $request is passed to Request::initialize()
    in vendor/Request.php on line 258
  4. $request is passed to ParameterBag::__construct()
    in vendor/Request.php on line 276
  5. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  6. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  7. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  8. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  9. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  10. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  11. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  12. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  3. Path: Read from $_SERVER, and $server is assigned in Request.php on line 307
  1. Read from $_SERVER, and $server is assigned
    in vendor/Request.php on line 307
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  4. Path: Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned in Request.php on line 310
  1. Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned
    in vendor/Request.php on line 310
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  5. Path: Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned in Request.php on line 313
  1. Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned
    in vendor/Request.php on line 313
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  6. Path: $server['HTTP_HOST'] seems to return tainted data, and $server is assigned in Request.php on line 383
  1. $server['HTTP_HOST'] seems to return tainted data, and $server is assigned
    in vendor/Request.php on line 383
  2. $server is assigned
    in vendor/Request.php on line 431
  3. $server is assigned
    in vendor/Request.php on line 432
  4. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 434
  5. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  6. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  7. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  8. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  9. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  10. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  11. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  12. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  13. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  14. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  15. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  7. Path: $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 43
  1. $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 43
  2. $headers is assigned
    in vendor/ServerBag.php on line 44
  3. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  4. $values is assigned
    in vendor/HeaderBag.php on line 31
  5. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  6. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  7. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  8. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  9. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  10. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  11. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  12. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  13. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  14. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  15. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  16. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  17. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  18. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  19. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  8. Path: $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 44
  1. $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 44
  2. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  3. $values is assigned
    in vendor/HeaderBag.php on line 31
  4. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  5. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  6. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  7. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  8. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  9. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  10. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  11. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  12. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  13. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  14. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  15. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  16. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  17. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  18. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  9. Path: Read from $_SERVER, and $server is assigned in src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  1. Read from $_SERVER, and $server is assigned
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  2. Data is passed through array_replace()
    in vendor/Request.php on line 360
  3. Data is passed through call_user_func()
    in vendor/Request.php on line 2019
  4. \Illuminate\Http\Request::create($uri, 'GET', array(), array(), array(), $server) is passed to Container::instance()
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 31
  5. Container::$instances is assigned
    in vendor/src/Illuminate/Container/Container.php on line 371
  6. Tainted property Container::$instances is read
    in vendor/src/Illuminate/Container/Container.php on line 597
  7. Container::resolve() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 575
  8. Container::make() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 1172
  9. Container::offsetGet() returns tainted data, and $table is assigned
    in vendor/src/Illuminate/Session/SessionManager.php on line 74
  10. $table is passed to DatabaseSessionHandler::__construct()
    in vendor/src/Illuminate/Session/SessionManager.php on line 79
  11. DatabaseSessionHandler::$table is assigned
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 61
  12. Tainted property DatabaseSessionHandler::$table is read, and $this->table is passed to Connection::table()
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 274
  13. $table is passed to Builder::from()
    in vendor/src/Illuminate/Database/Connection.php on line 258
  14. Builder::$from is assigned
    in vendor/src/Illuminate/Database/Query/Builder.php on line 327
  15. Tainted property Builder::$from is read, and $query->from is passed to Grammar::wrapTable()
    in vendor/src/Illuminate/Database/Query/Grammars/Grammar.php on line 772
  16. $this->tablePrefix . $table is passed to Grammar::wrap()
    in vendor/src/Illuminate/Database/Grammar.php on line 36
  17. $value is passed through explode(), and explode('.', $value) is passed to Grammar::wrapSegments()
    in vendor/src/Illuminate/Database/Grammar.php on line 62
  18. $segments is passed to collect()
    in vendor/src/Illuminate/Database/Grammar.php on line 96
  19. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  20. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  21. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  22. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96

Used in unserialized context

  1. BelongsToMany::saveMany() uses Arr::get() ($key)
    in vendor/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php on line 727
  2. Arr::get() uses Repository::offsetGet() ($key)
    in vendor/src/Illuminate/Support/Arr.php on line 285
  3. Repository::offsetGet() uses Repository::get() ($key)
    in vendor/src/Illuminate/Cache/Repository.php on line 454
  4. Repository::get() uses FileStore::get() ($key)
    in vendor/src/Illuminate/Cache/Repository.php on line 84
  5. FileStore::get() uses FileStore::getPayload() ($key)
    in vendor/src/Illuminate/Cache/FileStore.php on line 50
  6. FileStore::getPayload() uses unserialize() ($str)
    in vendor/src/Illuminate/Cache/FileStore.php on line 188

Preventing Object Injection Attacks

If you pass raw user-data to unserialize() for example, this can be used to create an object of any class that is available in your local filesystem. For an attacker, classes that have magic methods like __destruct or __wakeup are particularly interesting in such a case, as they can be exploited very easily.

We recommend to not pass user data to such a function. In case of unserialize, better use JSON to transfer data.

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
Security Code Execution introduced by
$roles can contain request data and is used in code execution context(s) leading to a potential security vulnerability.

9 paths for user data to reach this point

  1. Path: $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned in ServerBag.php on line 62
  1. $this->parameters['HTTP_AUTHORIZATION'] seems to return tainted data, and $authorizationHeader is assigned
    in vendor/ServerBag.php on line 62
  2. ParameterBag::$parameters is assigned
    in vendor/ServerBag.php on line 77
  3. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  4. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  5. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  6. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  7. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  8. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  9. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  2. Path: Read from $_POST, and $_POST is passed to Request::createRequestFromFactory() in Request.php on line 317
  1. Read from $_POST, and $_POST is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  2. $request is passed to Request::__construct()
    in vendor/Request.php on line 2028
  3. $request is passed to Request::initialize()
    in vendor/Request.php on line 258
  4. $request is passed to ParameterBag::__construct()
    in vendor/Request.php on line 276
  5. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  6. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  7. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  8. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  9. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  10. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  11. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  12. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  3. Path: Read from $_SERVER, and $server is assigned in Request.php on line 307
  1. Read from $_SERVER, and $server is assigned
    in vendor/Request.php on line 307
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  4. Path: Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned in Request.php on line 310
  1. Fetching key HTTP_CONTENT_LENGTH from $_SERVER, and $server is assigned
    in vendor/Request.php on line 310
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  5. Path: Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned in Request.php on line 313
  1. Fetching key HTTP_CONTENT_TYPE from $_SERVER, and $server is assigned
    in vendor/Request.php on line 313
  2. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 317
  3. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  4. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  5. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  6. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  7. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  8. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  9. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  10. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  11. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  12. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  13. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  6. Path: $server['HTTP_HOST'] seems to return tainted data, and $server is assigned in Request.php on line 383
  1. $server['HTTP_HOST'] seems to return tainted data, and $server is assigned
    in vendor/Request.php on line 383
  2. $server is assigned
    in vendor/Request.php on line 431
  3. $server is assigned
    in vendor/Request.php on line 432
  4. $server is passed to Request::createRequestFromFactory()
    in vendor/Request.php on line 434
  5. $server is passed to Request::__construct()
    in vendor/Request.php on line 2028
  6. $server is passed to Request::initialize()
    in vendor/Request.php on line 258
  7. $server is passed to ParameterBag::__construct()
    in vendor/Request.php on line 281
  8. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 35
  9. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  10. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  11. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  12. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  13. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  14. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  15. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  7. Path: $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 43
  1. $this->parameters['PHP_AUTH_USER'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 43
  2. $headers is assigned
    in vendor/ServerBag.php on line 44
  3. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  4. $values is assigned
    in vendor/HeaderBag.php on line 31
  5. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  6. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  7. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  8. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  9. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  10. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  11. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  12. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  13. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  14. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  15. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  16. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  17. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  18. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  19. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  8. Path: $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned in ServerBag.php on line 44
  1. $this->parameters['PHP_AUTH_PW'] seems to return tainted data, and $headers is assigned
    in vendor/ServerBag.php on line 44
  2. ServerBag::getHeaders() returns tainted data, and $this->server->getHeaders() is passed to HeaderBag::__construct()
    in vendor/Request.php on line 282
  3. $values is assigned
    in vendor/HeaderBag.php on line 31
  4. $values is passed to HeaderBag::set()
    in vendor/HeaderBag.php on line 32
  5. (array) $values is passed through array_values(), and $values is assigned
    in vendor/HeaderBag.php on line 143
  6. HeaderBag::$headers is assigned
    in vendor/HeaderBag.php on line 146
  7. Tainted property HeaderBag::$headers is read
    in vendor/HeaderBag.php on line 67
  8. HeaderBag::all() returns tainted data, and $headers is assigned
    in vendor/HeaderBag.php on line 115
  9. HeaderBag::get() returns tainted data, and $requestUri is assigned
    in vendor/Request.php on line 1798
  10. $requestUri is passed to ParameterBag::set()
    in vendor/Request.php on line 1829
  11. ParameterBag::$parameters is assigned
    in vendor/ParameterBag.php on line 99
  12. Tainted property ParameterBag::$parameters is read
    in vendor/ParameterBag.php on line 45
  13. ParameterBag::all() returns tainted data, and $bag->all() is passed to TransformsRequest::cleanArray()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 58
  14. $data is passed to collect()
    in vendor/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php on line 69
  15. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  16. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  17. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  18. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96
  9. Path: Read from $_SERVER, and $server is assigned in src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  1. Read from $_SERVER, and $server is assigned
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 22
  2. Data is passed through array_replace()
    in vendor/Request.php on line 360
  3. Data is passed through call_user_func()
    in vendor/Request.php on line 2019
  4. \Illuminate\Http\Request::create($uri, 'GET', array(), array(), array(), $server) is passed to Container::instance()
    in vendor/src/Illuminate/Foundation/Bootstrap/SetRequestForConsole.php on line 31
  5. Container::$instances is assigned
    in vendor/src/Illuminate/Container/Container.php on line 371
  6. Tainted property Container::$instances is read
    in vendor/src/Illuminate/Container/Container.php on line 597
  7. Container::resolve() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 575
  8. Container::make() returns tainted data
    in vendor/src/Illuminate/Container/Container.php on line 1172
  9. Container::offsetGet() returns tainted data, and $table is assigned
    in vendor/src/Illuminate/Session/SessionManager.php on line 74
  10. $table is passed to DatabaseSessionHandler::__construct()
    in vendor/src/Illuminate/Session/SessionManager.php on line 79
  11. DatabaseSessionHandler::$table is assigned
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 61
  12. Tainted property DatabaseSessionHandler::$table is read, and $this->table is passed to Connection::table()
    in vendor/src/Illuminate/Session/DatabaseSessionHandler.php on line 274
  13. $table is passed to Builder::from()
    in vendor/src/Illuminate/Database/Connection.php on line 258
  14. Builder::$from is assigned
    in vendor/src/Illuminate/Database/Query/Builder.php on line 327
  15. Tainted property Builder::$from is read, and $query->from is passed to Grammar::wrapTable()
    in vendor/src/Illuminate/Database/Query/Grammars/Grammar.php on line 772
  16. $this->tablePrefix . $table is passed to Grammar::wrap()
    in vendor/src/Illuminate/Database/Grammar.php on line 36
  17. $value is passed through explode(), and explode('.', $value) is passed to Grammar::wrapSegments()
    in vendor/src/Illuminate/Database/Grammar.php on line 62
  18. $segments is passed to collect()
    in vendor/src/Illuminate/Database/Grammar.php on line 96
  19. $value is passed to Collection::__construct()
    in vendor/src/Illuminate/Support/helpers.php on line 393
  20. Collection::$items is assigned
    in vendor/src/Illuminate/Support/Collection.php on line 46
  21. Tainted property Collection::$items is read
    in vendor/src/Illuminate/Support/Collection.php on line 87
  22. Collection::all() returns tainted data, and $roles is assigned
    in src/Traits/HasRoles.php on line 96

Used in code-execution context

  1. BelongsToMany::saveMany() uses Arr::get() ($key)
    in vendor/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php on line 727
  2. Arr::get() uses Container::offsetGet() ($key)
    in vendor/src/Illuminate/Support/Arr.php on line 285
  3. Container::offsetGet() uses Container::make() ($abstract)
    in vendor/src/Illuminate/Container/Container.php on line 1172
  4. Container::make() uses Container::resolve() ($abstract)
    in vendor/src/Illuminate/Container/Container.php on line 575
  5. Container::resolve() uses Container::build() ($concrete)
    in vendor/src/Illuminate/Container/Container.php on line 608
  6. Container::build() uses dynamic function name
    in vendor/src/Illuminate/Container/Container.php on line 726

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
107
108 46
        $this->forgetCachedPermissions();
109
110 46
        return $this;
111
    }
112
113
    /**
114
     * Revoke the given role from the model.
115
     *
116
     * @param string|Role $role
117
     */
118 1
    public function removeRole($role)
119
    {
120 1
        $this->roles()->detach($this->getStoredRole($role));
0 ignored issues
show
Documentation introduced by
$this->getStoredRole($role) is of type object<Maklad\Permission\Contracts\RoleInterface>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
121 1
    }
122
123
    /**
124
     * Remove all current roles and set the given ones.
125
     *
126
     * @param array ...$roles
127
     *
128
     * @return $this
129
     */
130 5
    public function syncRoles(...$roles)
131
    {
132 5
        $this->roles()->detach();
133
134 5
        return $this->assignRole($roles);
135
    }
136
137
    /**
138
     * Determine if the model has (one of) the given role(s).
139
     *
140
     * @param string|array|Role|\Illuminate\Support\Collection $roles
141
     *
142
     * @return bool
143
     */
144 39
    public function hasRole($roles): bool
145
    {
146 39 View Code Duplication
        if (\is_string($roles) && false !== \strpos($roles, '|')) {
0 ignored issues
show
Duplication introduced by
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...
147 3
            $roles = \explode('|', $roles);
148
        }
149
150 39
        if (\is_string($roles)) {
151 23
            return $this->roles->contains('name', $roles);
0 ignored issues
show
Bug introduced by
The property roles does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
152
        }
153
154 28
        if ($roles instanceof Role) {
155 3
            return $this->roles->contains('id', $roles->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Maklad\Permission\Contracts\RoleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
156
        }
157
158 26
        if (\is_array($roles)) {
159 11
            foreach ($roles as $role) {
160 11
                if ($this->hasRole($role)) {
161 7
                    return true;
162
                }
163
            }
164
165 5
            return false;
166
        }
167
168 16
        return $roles->intersect($this->roles)->isNotEmpty();
169
    }
170
171
    /**
172
     * Determine if the model has any of the given role(s).
173
     *
174
     * @param string|array|Role|\Illuminate\Support\Collection $roles
175
     *
176
     * @return bool
177
     */
178 12
    public function hasAnyRole($roles): bool
179
    {
180 12
        return $this->hasRole($roles);
181
    }
182
183
    /**
184
     * Determine if the model has all of the given role(s).
185
     *
186
     * @param string|Role|\Illuminate\Support\Collection $roles
187
     *
188
     * @return bool
189
     */
190 7
    public function hasAllRoles($roles): bool
191
    {
192 7 View Code Duplication
        if (\is_string($roles) && false !== strpos($roles, '|')) {
0 ignored issues
show
Duplication introduced by
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...
193 4
            $roles = \explode('|', $roles);
194
        }
195
196 7
        if (\is_string($roles)) {
197 2
            return $this->roles->contains('name', $roles);
198
        }
199
200 6
        if ($roles instanceof Role) {
201 1
            return $this->roles->contains('id', $roles->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Maklad\Permission\Contracts\RoleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
202
        }
203
204 6
        $roles = \collect()->make($roles)->map(function ($role) {
205 6
            return $role instanceof Role ? $role->name : $role;
0 ignored issues
show
Bug introduced by
Accessing name on the interface Maklad\Permission\Contracts\RoleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
206 6
        });
207
208 6
        return $roles->intersect($this->roles->pluck('name')) == $roles;
209
    }
210
211
    /**
212
     * Determine if the model may perform the given permission.
213
     *
214
     * @param string|Permission $permission
215
     * @param string|null $guardName
216
     *
217
     * @return bool
218
     */
219 21
    public function hasPermissionTo($permission, $guardName = null): bool
220
    {
221 21
        if (\is_string($permission)) {
222 13
            $permission = \app(Permission::class)->findByName(
223 13
                $permission,
224 13
                $guardName ?? $this->getDefaultGuardName()
225
            );
226
        }
227
228 19
        return $this->hasDirectPermission($permission) || $this->hasPermissionViaRole($permission);
229
    }
230
231
    /**
232
     * Determine if the model has any of the given permissions.
233
     *
234
     * @param array ...$permissions
235
     *
236
     * @return bool
237
     */
238 7
    public function hasAnyPermission(...$permissions): bool
239
    {
240 7
        if (\is_array($permissions[0])) {
241 5
            $permissions = $permissions[0];
242
        }
243
244 7
        foreach ($permissions as $permission) {
245 7
            if ($this->hasPermissionTo($permission)) {
246 5
                return true;
247
            }
248
        }
249
250 4
        return false;
251
    }
252
253
    /**
254
     * Determine if the model has, via roles, the given permission.
255
     *
256
     * @param Permission $permission
257
     *
258
     * @return bool
259
     */
260 15
    protected function hasPermissionViaRole(Permission $permission): bool
261
    {
262 15
        return $this->hasRole($permission->roles);
0 ignored issues
show
Bug introduced by
Accessing roles on the interface Maklad\Permission\Contracts\PermissionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
263
    }
264
265
    /**
266
     * Determine if the model has the given permission.
267
     *
268
     * @param string|Permission $permission
269
     *
270
     * @return bool
271
     */
272 20
    public function hasDirectPermission($permission): bool
273
    {
274 20
        if (\is_string($permission)) {
275 1
            $permission = \app(Permission::class)->findByName($permission, $this->getDefaultGuardName());
276
        }
277
278 20
        return $this->permissions->contains('id', $permission->id);
0 ignored issues
show
Bug introduced by
The property permissions does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
279
    }
280
281
    /**
282
     * Return all permissions the directory coupled to the model.
283
     */
284 1
    public function getDirectPermissions(): Collection
285
    {
286 1
        return $this->permissions;
287
    }
288
289
    /**
290
     * Return all the permissions the model has via roles.
291
     */
292 3
    public function getPermissionsViaRoles(): Collection
293
    {
294 3
        return $this->load('roles', 'roles.permissions')
0 ignored issues
show
Bug introduced by
It seems like load() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
295 3
            ->roles->flatMap(function (Role $role) {
296 2
                return $role->permissions;
0 ignored issues
show
Bug introduced by
Accessing permissions on the interface Maklad\Permission\Contracts\RoleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
297 3
            })->sort()->values();
298
    }
299
300
    /**
301
     * Return all the permissions the model has, both directly and via roles.
302
     */
303 2
    public function getAllPermissions(): Collection
304
    {
305 2
        return $this->permissions
306 2
            ->merge($this->getPermissionsViaRoles())
307 2
            ->sort()
308 2
            ->values();
309
    }
310
311
    /**
312
     * Return Role object
313
     *
314
     * @param String|Role $role role name
315
     *
316
     * @return Role
317
     */
318 50
    protected function getStoredRole($role): Role
319
    {
320 50
        if (\is_string($role)) {
321 43
            return \app(Role::class)->findByName($role, $this->getDefaultGuardName());
322
        }
323
324 12
        return $role;
325
    }
326
327
    /**
328
     * Return a collection of role names associated with this user.
329
     *
330
     * @return Collection
331
     */
332 1
    public function getRoleNames(): Collection
333
    {
334 1
        return $this->roles->pluck('name');
335
    }
336
337
338
    /**
339
     * Return a collection of permission names associated with this user.
340
     *
341
     * @return Collection
342
     */
343 1
    public function getPermissionNames(): Collection
344
    {
345 1
        return $this->getAllPermissions()->pluck('name');
346
    }
347
348
    /**
349
     * Convert to Role Models
350
     *
351
     * @param $roles
352
     *
353
     * @return Collection
354
     */
355 4 View Code Duplication
    private function convertToRoleModels($roles): Collection
0 ignored issues
show
Duplication introduced by
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...
356
    {
357 4
        if (\is_array($roles)) {
358 2
            $roles = \collect($roles);
359
        }
360
361 4
        if (! $roles instanceof Collection) {
362 2
            $roles = \collect([$roles]);
363
        }
364
365 4
        $roles = $roles->map(function ($role) {
366 4
            return $this->getStoredRole($role);
367 4
        });
368
369
        return $roles;
370
    }
371
}
372