This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace fkooman\RemoteStorage; |
||
4 | |||
5 | use DateTime; |
||
6 | use fkooman\RemoteStorage\Http\Exception\HttpException; |
||
7 | use fkooman\RemoteStorage\Http\FormAuthentication; |
||
8 | use fkooman\RemoteStorage\Http\Request; |
||
9 | use fkooman\RemoteStorage\Http\Response; |
||
10 | use fkooman\RemoteStorage\Http\SessionInterface; |
||
11 | use fkooman\RemoteStorage\OAuth\BearerAuthentication; |
||
12 | use fkooman\RemoteStorage\OAuth\OAuthModule; |
||
13 | use fkooman\RemoteStorage\OAuth\TokenStorage; |
||
14 | use PDO; |
||
15 | |||
16 | class Controller |
||
17 | { |
||
18 | /** @var TwigTpl */ |
||
19 | private $templateManager; |
||
20 | |||
21 | /** @var ApiModule */ |
||
22 | private $apiModule; |
||
23 | |||
24 | /** @var UiModule */ |
||
25 | private $uiModule; |
||
26 | |||
27 | /** @var WebfingerModule */ |
||
28 | private $webfingerModule; |
||
29 | |||
30 | /** @var OAuthModule */ |
||
31 | private $oauthModule; |
||
32 | |||
33 | /** @var array */ |
||
34 | private $auth = []; |
||
35 | |||
36 | /** |
||
37 | * @param string $configFile |
||
0 ignored issues
–
show
|
|||
38 | * @param string $storageRoot |
||
0 ignored issues
–
show
There is no parameter named
$storageRoot . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
39 | * @param string $dbDsn |
||
0 ignored issues
–
show
There is no parameter named
$dbDsn . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
40 | * @param array $templateFolders |
||
0 ignored issues
–
show
There is no parameter named
$templateFolders . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
41 | */ |
||
42 | public function __construct($appDir, SessionInterface $session, RandomInterface $random, DateTime $dateTime) |
||
43 | { |
||
44 | $config = Config::fromFile(sprintf('%s/config/server.yaml', $appDir)); |
||
45 | $serverMode = $config->serverMode; |
||
0 ignored issues
–
show
The property
serverMode does not seem to exist in fkooman\RemoteStorage\Config .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
46 | |||
47 | $this->templateManager = new TwigTpl( |
||
48 | [ |
||
49 | sprintf('%s/views', $appDir), |
||
50 | sprintf('%s/config/views', $appDir), |
||
51 | ], |
||
52 | 'development' !== $serverMode ? sprintf('%s/data/tpl', $appDir) : null |
||
53 | ); |
||
54 | $this->templateManager->setDefault( |
||
55 | [ |
||
56 | 'serverMode' => $serverMode, |
||
57 | ] |
||
58 | ); |
||
59 | |||
60 | $db = new PDO(sprintf('sqlite:%s/data/rs.sqlite', $appDir)); |
||
61 | $metaDataStorage = new MetadataStorage($db); |
||
62 | $metaDataStorage->init(); |
||
63 | |||
64 | $tokenStorage = new TokenStorage($db); |
||
65 | $tokenStorage->init(); |
||
66 | |||
67 | $remoteStorage = new RemoteStorage( |
||
68 | $metaDataStorage, |
||
69 | new DocumentStorage(sprintf('%s/data/storage', $appDir)) |
||
70 | ); |
||
71 | |||
72 | $this->apiModule = new ApiModule($remoteStorage, $config->serverMode); |
||
0 ignored issues
–
show
The property
serverMode does not exist on object<fkooman\RemoteStorage\Config> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
73 | $this->uiModule = new UiModule($remoteStorage, $this->templateManager, $tokenStorage); |
||
74 | $this->webfingerModule = new WebfingerModule($config->serverMode); |
||
0 ignored issues
–
show
The property
serverMode does not exist on object<fkooman\RemoteStorage\Config> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
75 | $this->oauthModule = new OAuthModule($this->templateManager, $tokenStorage, $random, $dateTime); |
||
76 | |||
77 | $session->setSecureOnly('development' !== $serverMode); |
||
78 | $this->auth['form'] = new FormAuthentication($session, $this->templateManager, $config->Users->asArray()); |
||
0 ignored issues
–
show
The property
Users does not exist on object<fkooman\RemoteStorage\Config> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
79 | $this->auth['bearer'] = new BearerAuthentication($tokenStorage); |
||
80 | } |
||
81 | |||
82 | public function run(Request $request) |
||
83 | { |
||
84 | try { |
||
85 | switch ($request->getRequestMethod()) { |
||
86 | case 'GET': |
||
87 | return $this->handleGet($request); |
||
88 | case 'POST': |
||
89 | return $this->handlePost($request); |
||
90 | View Code Duplication | case 'PUT': |
|
0 ignored issues
–
show
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. ![]() |
|||
91 | $tokenInfo = $this->auth['bearer']->requireAuth($request); |
||
92 | |||
93 | return $this->apiModule->put($request, $tokenInfo); |
||
94 | View Code Duplication | case 'DELETE': |
|
0 ignored issues
–
show
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. ![]() |
|||
95 | $tokenInfo = $this->auth['bearer']->requireAuth($request); |
||
96 | |||
97 | return $this->apiModule->delete($request, $tokenInfo); |
||
98 | case 'OPTIONS': |
||
99 | return $this->apiModule->options($request); |
||
100 | View Code Duplication | case 'HEAD': |
|
0 ignored issues
–
show
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. ![]() |
|||
101 | $tokenInfo = $this->auth['bearer']->optionalAuth($request); |
||
102 | |||
103 | return $this->apiModule->head($request, $tokenInfo); |
||
104 | default: |
||
105 | throw new HttpException('method not allowed', 405); |
||
106 | } |
||
107 | } catch (HttpException $e) { |
||
108 | if ($request->isBrowser()) { |
||
109 | $response = new Response($e->getCode(), 'text/html'); |
||
110 | $response->setBody( |
||
111 | $this->templateManager->render( |
||
112 | 'error', |
||
113 | [ |
||
114 | 'code' => $e->getCode(), |
||
115 | 'message' => $e->getMessage(), |
||
116 | ] |
||
117 | ) |
||
118 | ); |
||
119 | } else { |
||
120 | // not a browser |
||
121 | $response = new Response($e->getCode(), 'application/json'); |
||
122 | $response->setBody(json_encode(['error' => $e->getMessage()])); |
||
123 | } |
||
124 | |||
125 | foreach ($e->getResponseHeaders() as $key => $value) { |
||
126 | $response->addHeader($key, $value); |
||
127 | } |
||
128 | |||
129 | return $response; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | private function handleGet(Request $request) |
||
134 | { |
||
135 | switch ($request->getPathInfo()) { |
||
136 | case '/.well-known/webfinger': |
||
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
137 | |||
138 | return $this->webfingerModule->getWebfinger($request); |
||
139 | View Code Duplication | case '/authorize': |
|
0 ignored issues
–
show
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. ![]() |
|||
140 | $userId = $this->auth['form']->requireAuth($request); |
||
141 | if ($userId instanceof Response) { |
||
142 | return $userId; |
||
143 | } |
||
144 | |||
145 | return $this->oauthModule->getAuthorize($request, $userId); |
||
146 | View Code Duplication | case '/': |
|
0 ignored issues
–
show
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. ![]() |
|||
147 | $userId = $this->auth['form']->requireAuth($request); |
||
148 | if ($userId instanceof Response) { |
||
149 | return $userId; |
||
150 | } |
||
151 | |||
152 | return $this->uiModule->getHome($request, $userId); |
||
153 | case '/logout': |
||
154 | return $this->auth['form']->logout($request); |
||
155 | default: |
||
156 | $tokenInfo = $this->auth['bearer']->optionalAuth($request); |
||
157 | |||
158 | return $this->apiModule->get($request, $tokenInfo); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | private function handlePost(Request $request) |
||
163 | { |
||
164 | switch ($request->getPathInfo()) { |
||
165 | case '/': |
||
166 | $userId = $this->auth['form']->requireAuth($request); |
||
167 | |||
168 | return $this->uiModule->postHome($request, $userId); |
||
169 | case '/authorize': |
||
170 | $userId = $this->auth['form']->requireAuth($request); |
||
171 | |||
172 | return $this->oauthModule->postAuthorize($request, $userId); |
||
173 | case '/authenticate': |
||
174 | return $this->auth['form']->verifyAuth($request); |
||
175 | case '/logout': |
||
176 | return $this->auth['form']->logout($request); |
||
177 | default: |
||
178 | throw new HttpException('not found', 404); |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.