Passed
Pull Request — master (#15)
by Mostafa Abd El-Salam
03:53
created

HasRoles::getPermissionNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Maklad\Permission\Traits;
4
5
use Illuminate\Support\Collection;
6
use Jenssegers\Mongodb\Eloquent\Builder;
7
use Jenssegers\Mongodb\Eloquent\Model;
8
use Jenssegers\Mongodb\Relations\BelongsToMany;
9
use Maklad\Permission\Contracts\PermissionInterface as Permission;
10
use Maklad\Permission\Contracts\RoleInterface as Role;
11
12
trait HasRoles
13
{
14
    use HasPermissions;
15
16
    public static function bootHasRoles()
17
    {
18 105
        static::deleting(function (Model $model) {
19 2
            foreach ($model->roles as $role) {
20 1
                $role->users()->detach($model);
21
            }
22 2
            foreach ($model->permissions as $permissions) {
23 1
                $permissions->users()->detach($model);
24
            }
25 105
        });
26 105
    }
27
28
    /**
29
     * A model may have multiple roles.
30
     */
31 58
    public function roles(): BelongsToMany
32
    {
33 58
        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 33

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...
34
    }
35
36
    /**
37
     * A model may have multiple direct permissions.
38
     */
39 25
    public function permissions(): BelongsToMany
40
    {
41 25
        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 41

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...
42
    }
43
44
    /**
45
     * Scope the model query to certain roles only.
46
     *
47
     * @param Builder $query
48
     * @param string|array|Role|\Illuminate\Support\Collection $roles
49
     *
50
     * @return Builder
51
     */
52 5
    public function scopeRole(Builder $query, $roles): Builder
53
    {
54 5
        if (is_array($roles)) {
55 2
            $roles = collect($roles);
56
        }
57
58 5
        if (! $roles instanceof Collection) {
59 3
            $roles = collect([$roles]);
60
        }
61
62 5 View Code Duplication
        $roles = $roles->map(function ($role) {
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...
63 5
            if ($role instanceof Role) {
64 3
                return $role;
65
            }
66
67 4
            return app(Role::class)->findByName($role, $this->getDefaultGuardName());
68 5
        });
69
70 4
        return $query->whereIn('role_ids', $roles->pluck('_id'));
71
    }
72
73
    /**
74
     * Assign the given role to the model.
75
     *
76
     * @param array|string|Role ...$roles
77
     *
78
     * @return $this
79
     */
80 46 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...
81
    {
82 46
        $roles = collect($roles)
83 46
            ->flatten()
84 46
            ->map(function ($role) {
85 46
                return $this->getStoredRole($role);
86 46
            })
87 43
            ->each(function ($role) {
88 43
                $this->ensureModelSharesGuard($role);
89 43
            })
90 42
            ->all();
91
92 42
        $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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82

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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82

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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82

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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82
  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 82

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...
93
94 42
        $this->forgetCachedPermissions();
95
96 42
        return $this;
97
    }
98
99
    /**
100
     * Revoke the given role from the model.
101
     *
102
     * @param string|Role $role
103
     */
104 1
    public function removeRole($role)
105
    {
106 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...
107 1
    }
108
109
    /**
110
     * Remove all current roles and set the given ones.
111
     *
112
     * @param array ...$roles
113
     *
114
     * @return $this
115
     */
116 5
    public function syncRoles(...$roles)
117
    {
118 5
        $this->roles()->detach();
119
120 5
        return $this->assignRole($roles);
121
    }
122
123
    /**
124
     * Determine if the model has (one of) the given role(s).
125
     *
126
     * @param string|array|Role|\Illuminate\Support\Collection $roles
127
     *
128
     * @return bool
129
     */
130 38
    public function hasRole($roles): bool
131
    {
132 38 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...
133 3
            $roles = explode('|', $roles);
134
        }
135
136 38
        if (is_string($roles)) {
137 24
            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...
138
        }
139
140 26
        if ($roles instanceof Role) {
141 2
            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...
142
        }
143
144 25
        if (is_array($roles)) {
145 11
            foreach ($roles as $role) {
146 11
                if ($this->hasRole($role)) {
147 7
                    return true;
148
                }
149
            }
150
151 5
            return false;
152
        }
153
154 15
        return $roles->intersect($this->roles)->isNotEmpty();
155
    }
156
157
    /**
158
     * Determine if the model has any of the given role(s).
159
     *
160
     * @param string|array|Role|\Illuminate\Support\Collection $roles
161
     *
162
     * @return bool
163
     */
164 12
    public function hasAnyRole($roles): bool
165
    {
166 12
        return $this->hasRole($roles);
167
    }
168
169
    /**
170
     * Determine if the model has all of the given role(s).
171
     *
172
     * @param string|Role|\Illuminate\Support\Collection $roles
173
     *
174
     * @return bool
175
     */
176 7
    public function hasAllRoles($roles): bool
177
    {
178 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...
179 4
            $roles = explode('|', $roles);
180
        }
181
182 7
        if (is_string($roles)) {
183 2
            return $this->roles->contains('name', $roles);
184
        }
185
186 6
        if ($roles instanceof Role) {
187 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...
188
        }
189
190 6
        $roles = collect()->make($roles)->map(function ($role) {
191 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...
192 6
        });
193
194 6
        return $roles->intersect($this->roles->pluck('name')) == $roles;
195
    }
196
197
    /**
198
     * Determine if the model may perform the given permission.
199
     *
200
     * @param string|Permission $permission
201
     * @param string|null $guardName
202
     *
203
     * @return bool
204
     */
205 21
    public function hasPermissionTo($permission, $guardName = null): bool
206
    {
207 21
        if (is_string($permission)) {
208 13
            $permission = app(Permission::class)->findByName(
209 13
                $permission,
210 13
                $guardName ?? $this->getDefaultGuardName()
211
            );
212
        }
213
214 19
        return $this->hasDirectPermission($permission) || $this->hasPermissionViaRole($permission);
215
    }
216
217
    /**
218
     * Determine if the model has any of the given permissions.
219
     *
220
     * @param array ...$permissions
221
     *
222
     * @return bool
223
     */
224 7
    public function hasAnyPermission(...$permissions): bool
225
    {
226 7
        if (is_array($permissions[0])) {
227 1
            $permissions = $permissions[0];
228
        }
229
230 7
        foreach ($permissions as $permission) {
231 7
            if ($this->hasPermissionTo($permission)) {
232 5
                return true;
233
            }
234
        }
235
236 4
        return false;
237
    }
238
239
    /**
240
     * Determine if the model has, via roles, the given permission.
241
     *
242
     * @param Permission $permission
243
     *
244
     * @return bool
245
     */
246 14
    protected function hasPermissionViaRole(Permission $permission): bool
247
    {
248 14
        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...
249
    }
250
251
    /**
252
     * Determine if the model has the given permission.
253
     *
254
     * @param string|Permission $permission
255
     *
256
     * @return bool
257
     */
258 20
    public function hasDirectPermission($permission): bool
259
    {
260 20
        if (is_string($permission)) {
261 1
            $permission = app(Permission::class)->findByName($permission, $this->getDefaultGuardName());
262
        }
263
264 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...
265
    }
266
267
    /**
268
     * Return all permissions the directory coupled to the model.
269
     */
270 1
    public function getDirectPermissions(): Collection
271
    {
272 1
        return $this->permissions;
273
    }
274
275
    /**
276
     * Return all the permissions the model has via roles.
277
     */
278 3
    public function getPermissionsViaRoles(): Collection
279
    {
280 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...
281 3
            ->roles->flatMap(function (Role $role) {
282 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...
283 3
            })->sort()->values();
284
    }
285
286
    /**
287
     * Return all the permissions the model has, both directly and via roles.
288
     */
289 2
    public function getAllPermissions(): Collection
290
    {
291 2
        return $this->permissions
292 2
            ->merge($this->getPermissionsViaRoles())
293 2
            ->sort()
294 2
            ->values();
295
    }
296
297
    /**
298
     * Return Role object
299
     *
300
     * @param $role role name
301
     *
302
     * @return Role
303
     */
304 46 View Code Duplication
    protected function getStoredRole($role): Role
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...
305
    {
306 46
        if (is_string($role)) {
307 40
            return app(Role::class)->findByName($role, $this->getDefaultGuardName());
308
        }
309
310 10
        return $role;
311
    }
312
313
    /**
314
     * Return a collection of role names associated with this user.
315
     *
316
     * @return Collection
317
     */
318 1
    public function getRoleNames(): Collection
319
    {
320 1
        return $this->roles->pluck('name');
321
    }
322
323
324
    /**
325
     * Return a collection of permission names associated with this user.
326
     *
327
     * @return Collection
328
     */
329 1
    public function getPermissionNames(): Collection
330
    {
331 1
        return $this->getAllPermissions()->pluck('name');
332
    }
333
}
334