Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Assembly/VotingAssembly.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace SpareParts\Overseer\Assembly;
3
4
5
use SpareParts\Overseer\Context\IVotingContext;
6
use SpareParts\Overseer\InvalidVotingResultException;
7
use SpareParts\Overseer\StrategyEnum;
8
use SpareParts\Overseer\Voter\ISingleVoterResult;
9
use SpareParts\Overseer\Voter\IVoter;
10
use SpareParts\Overseer\VotingDecisionEnum;
11
use SpareParts\Overseer\VotingResult;
12
13
class VotingAssembly implements IVotingAssembly
14
{
15
16
    /**
17
     * @var StrategyEnum
18
     */
19
    private $strategy;
20
21
    /**
22
     * @var IVoter[]
23
     */
24
    private $voters;
25
26
27
    /**
28
     * VotingAssembly constructor.
29
     * @param StrategyEnum $strategy
30
     * @param \SpareParts\Overseer\Voter\IVoter[] $voters
31
     */
32 24
    public function __construct(StrategyEnum $strategy, array $voters)
33
    {
34 24
        $this->strategy = $strategy;
35 24
        $this->voters = $voters;
36 24
    }
37
38
39
    /**
40
     * @param mixed $votingSubject
41
     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
42
     * @return null|\SpareParts\Overseer\IVotingResult
43
     * @throws \SpareParts\Overseer\InvalidVotingResultException
44
     */
45 19
    public function commenceVote($votingSubject, IVotingContext $votingContext)
46
    {
47 19
        switch ($this->strategy) {
48 19
            case StrategyEnum::FIRST_VOTE_DECIDES():
49 7
                return $this->strategyFirstVoteDecides($votingSubject, $votingContext);
50
51 12
            case StrategyEnum::ALLOW_UNLESS_DENIED():
52 3
                return $this->strategyAllowUnlessDenied($votingSubject, $votingContext);
53
54 9
            case StrategyEnum::DENY_UNLESS_ALLOWED():
55 3
                return $this->strategyDenyUnlessAllowed($votingSubject, $votingContext);
56
57 6
            case StrategyEnum::EVERYONE_MUST_ALLOW_TO_BE_ALLOWED():
58 3
                return $this->strategyEveryoneMustComply($votingSubject, $votingContext, VotingDecisionEnum::ALLOWED(), VotingDecisionEnum::DENIED());
59
60 3
            case StrategyEnum::EVERYONE_MUST_DENY_TO_BE_DENIED():
61 3
                return $this->strategyEveryoneMustComply($votingSubject, $votingContext, VotingDecisionEnum::DENIED(), VotingDecisionEnum::ALLOWED());
62
63
            default:
64
                throw new InvalidVotingResultException('Unable to decide on result, invalid strategy: '.$this->strategy);
65
        }
66
    }
67
68
69
    /**
70
     * @param mixed $votingSubject
71
     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
72
     * @return \SpareParts\Overseer\IVotingResult
73
     * @throws \SpareParts\Overseer\InvalidVotingResultException
74
     */
75 7
    private function strategyFirstVoteDecides($votingSubject, IVotingContext $votingContext)
76
    {
77 7
        foreach ($this->voters as $voter) {
78 6
            if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) {
79 5
                return new VotingResult($lastResult->getDecision(), [$lastResult]);
80
            }
81
        }
82 2
        throw new InvalidVotingResultException('Voting assembly did not decide on any result!');
83
    }
84
85
86
    /**
87
     * @param mixed $votingSubject
88
     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
89
     * @return \SpareParts\Overseer\IVotingResult
90
     */
91 3 View Code Duplication
    private function strategyAllowUnlessDenied($votingSubject, IVotingContext $votingContext)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93 3
        $results = [];
94 3
        foreach ($this->voters as $name => $voter) {
95 2
            if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) {
96 1
                $results[] = $lastResult;
97 1
                if ($lastResult->getDecision() === VotingDecisionEnum::DENIED()) {
98 1
                    return new VotingResult(VotingDecisionEnum::DENIED(), $results);
99
                }
100
            }
101
        }
102 2
        return new VotingResult(VotingDecisionEnum::ALLOWED(), $results);
103
    }
104
105
106
    /**
107
     * @param mixed $votingSubject
108
     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
109
     * @return \SpareParts\Overseer\IVotingResult
110
     */
111 3 View Code Duplication
    private function strategyDenyUnlessAllowed($votingSubject, IVotingContext $votingContext)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113 3
        $results = [];
114 3
        foreach ($this->voters as $name => $voter) {
115 2
            if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) {
116 1
                $results[] = $lastResult;
117 1
                if ($lastResult->getDecision() === VotingDecisionEnum::ALLOWED()) {
118 1
                    return new VotingResult(VotingDecisionEnum::ALLOWED(), $results);
119
                }
120
            }
121
        }
122 2
        return new VotingResult(VotingDecisionEnum::DENIED(), $results);
123
    }
124
125
126
    /**
127
     * @param mixed $votingSubject
128
     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
129
     * @param \SpareParts\Overseer\VotingDecisionEnum $defaultDecision
130
     * @param \SpareParts\Overseer\VotingDecisionEnum $counterDecision
131
     *
132
     * @return \SpareParts\Overseer\VotingResult
133
     */
134 6
    private function strategyEveryoneMustComply(
135
        $votingSubject,
136
        IVotingContext $votingContext,
137
        VotingDecisionEnum $defaultDecision,
138
        VotingDecisionEnum $counterDecision
139
    ) {
140 6
        $results = [];
141 6
        $decision = $defaultDecision;
142 6
        foreach ($this->voters as $voter) {
143 6
            $result = $voter->vote($votingSubject, $votingContext);
144 6
            if ($result instanceof ISingleVoterResult) {
145 6
                if ($result->getDecision() !== $defaultDecision) {
146 2
                    $decision = $counterDecision;
147
                }
148 6
                $results[] = $result;
149
            }
150
        }
151 6
        return new VotingResult($decision, $results);
152
    }
153
}
154