Completed
Pull Request — master (#4336)
by Lukas
17:56 queued 06:34
created
lib/private/AppFramework/Utility/ControllerMethodReflector.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,19 +40,19 @@  discard block
 block discarded – undo
40 40
 	 * @param object $object an object or classname
41 41
 	 * @param string $method the method which we want to inspect
42 42
 	 */
43
-	public function reflect($object, $method){
43
+	public function reflect($object, $method) {
44 44
 		$reflection = new \ReflectionMethod($object, $method);
45 45
 		$docs = $reflection->getDocComment();
46 46
 
47 47
 		// extract everything prefixed by @ and first letter uppercase
48 48
 		preg_match_all('/^\h+\*\h+@(?P<annotation>[A-Z]\w+)((?P<parameter>.*))?$/m', $docs, $matches);
49
-		foreach($matches['annotation'] as $key => $annontation) {
49
+		foreach ($matches['annotation'] as $key => $annontation) {
50 50
 			$annotationValue = $matches['parameter'][$key];
51
-			if($annotationValue[0] === '(' && $annotationValue[strlen($annotationValue) - 1] === ')') {
51
+			if ($annotationValue[0] === '(' && $annotationValue[strlen($annotationValue) - 1] === ')') {
52 52
 				$cutString = substr($annotationValue, 1, -1);
53 53
 				$cutString = str_replace(' ', '', $cutString);
54 54
 				$splittedArray = explode(',', $cutString);
55
-				foreach($splittedArray as $annotationValues) {
55
+				foreach ($splittedArray as $annotationValues) {
56 56
 					list($key, $value) = explode('=', $annotationValues);
57 57
 					$this->annotations[$annontation][$key] = $value;
58 58
 				}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 				}
77 77
 			}
78 78
 
79
-			if($param->isOptional()) {
79
+			if ($param->isOptional()) {
80 80
 				$default = $param->getDefaultValue();
81 81
 			} else {
82 82
 				$default = null;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * would return int or null if not existing
94 94
 	 */
95 95
 	public function getType($parameter) {
96
-		if(array_key_exists($parameter, $this->types)) {
96
+		if (array_key_exists($parameter, $this->types)) {
97 97
 			return $this->types[$parameter];
98 98
 		} else {
99 99
 			return null;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @return string
125 125
 	 */
126 126
 	public function getAnnotationParameter($name, $key) {
127
-		if(isset($this->annotations[$name][$key])) {
127
+		if (isset($this->annotations[$name][$key])) {
128 128
 			return $this->annotations[$name][$key];
129 129
 		}
130 130
 
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
 
157 157
 		// security checks
158 158
 		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
159
-		if(!$isPublicPage) {
160
-			if(!$this->userSession->isLoggedIn()) {
159
+		if (!$isPublicPage) {
160
+			if (!$this->userSession->isLoggedIn()) {
161 161
 				throw new NotLoggedInException();
162 162
 			}
163 163
 
164
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
165
-				if(!$this->isAdminUser) {
164
+			if (!$this->reflector->hasAnnotation('NoAdminRequired')) {
165
+				if (!$this->isAdminUser) {
166 166
 					throw new NotAdminException();
167 167
 				}
168 168
 			}
@@ -176,20 +176,20 @@  discard block
 block discarded – undo
176 176
 		}
177 177
 
178 178
 		// Check for strict cookie requirement
179
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
180
-			if(!$this->request->passesStrictCookieCheck()) {
179
+		if ($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
180
+			if (!$this->request->passesStrictCookieCheck()) {
181 181
 				throw new StrictCookieMissingException();
182 182
 			}
183 183
 		}
184 184
 		// CSRF check - also registers the CSRF token since the session may be closed later
185 185
 		Util::callRegister();
186
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
186
+		if (!$this->reflector->hasAnnotation('NoCSRFRequired')) {
187 187
 			/*
188 188
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
189 189
 			 * hacks around that we have no full token auth in place yet and we
190 190
 			 * do want to offer CSRF checks for web requests.
191 191
 			 */
192
-			if(!$this->request->passesCSRFCheck() && !(
192
+			if (!$this->request->passesCSRFCheck() && !(
193 193
 					$controller instanceof OCSController &&
194 194
 					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
195 195
 				throw new CrossSiteRequestForgeryException();
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 		$anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period');
201 201
 		$userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit');
202 202
 		$userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period');
203
-		$rateLimitIdentifier = get_class($controller) . '::' . $methodName;
204
-		if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
203
+		$rateLimitIdentifier = get_class($controller).'::'.$methodName;
204
+		if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
205 205
 			$this->limiter->registerUserRequest(
206 206
 				$rateLimitIdentifier,
207 207
 				$userLimit,
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 			);
218 218
 		}
219 219
 
220
-		if($this->reflector->hasAnnotation('BruteForceProtection')) {
220
+		if ($this->reflector->hasAnnotation('BruteForceProtection')) {
221 221
 			$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
222 222
 			$this->throttler->sleepDelay($this->request->getRemoteAddress(), $action);
223 223
 			$this->throttler->registerAttempt($action, $this->request->getRemoteAddress());
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		 * The getAppPath() check is here since components such as settings also use the AppFramework and
230 230
 		 * therefore won't pass this check.
231 231
 		 */
232
-		if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
232
+		if (\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
233 233
 			throw new AppNotEnabledException();
234 234
 		}
235 235
 	}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
254 254
 		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
255 255
 
256
-		if($this->cspNonceManager->browserSupportsCspV3()) {
256
+		if ($this->cspNonceManager->browserSupportsCspV3()) {
257 257
 			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
258 258
 		}
259 259
 
@@ -273,17 +273,17 @@  discard block
 block discarded – undo
273 273
 	 * @return Response a Response object or null in case that the exception could not be handled
274 274
 	 */
275 275
 	public function afterException($controller, $methodName, \Exception $exception) {
276
-		if($exception instanceof SecurityException) {
277
-			if($exception instanceof StrictCookieMissingException) {
276
+		if ($exception instanceof SecurityException) {
277
+			if ($exception instanceof StrictCookieMissingException) {
278 278
 				return new RedirectResponse(\OC::$WEBROOT);
279 279
  			}
280
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
280
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
281 281
 				$response = new JSONResponse(
282 282
 					array('message' => $exception->getMessage()),
283 283
 					$exception->getCode()
284 284
 				);
285 285
 			} else {
286
-				if($exception instanceof NotLoggedInException) {
286
+				if ($exception instanceof NotLoggedInException) {
287 287
 					$url = $this->urlGenerator->linkToRoute(
288 288
 						'core.login.showLoginForm',
289 289
 						[
Please login to merge, or discard this patch.
lib/private/AppFramework/DependencyInjection/DIContainer.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @param array $urlParams
78 78
 	 * @param ServerContainer $server
79 79
 	 */
80
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
80
+	public function __construct($appName, $urlParams = array(), ServerContainer $server = null) {
81 81
 		parent::__construct();
82 82
 		$this['AppName'] = $appName;
83 83
 		$this['urlParams'] = $urlParams;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		/**
98 98
 		 * Core services
99 99
 		 */
100
-		$this->registerService(IOutput::class, function($c){
100
+		$this->registerService(IOutput::class, function($c) {
101 101
 			return new Output($this->getServer()->getWebRoot());
102 102
 		});
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 			return $this->getServer()->getUserFolder();
106 106
 		});
107 107
 
108
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
108
+		$this->registerService(IAppData::class, function(SimpleContainer $c) {
109 109
 			return $this->getServer()->getAppDataDir($c->query('AppName'));
110 110
 		});
111 111
 
@@ -126,25 +126,25 @@  discard block
 block discarded – undo
126 126
 
127 127
 		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
128 128
 
129
-		$this->registerService(IServerContainer::class, function ($c) {
129
+		$this->registerService(IServerContainer::class, function($c) {
130 130
 			return $this->getServer();
131 131
 		});
132 132
 		$this->registerAlias('ServerContainer', IServerContainer::class);
133 133
 
134
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
134
+		$this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) {
135 135
 			return $c->query('OCA\WorkflowEngine\Manager');
136 136
 		});
137 137
 
138
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
138
+		$this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) {
139 139
 			return $c;
140 140
 		});
141 141
 
142 142
 		// commonly used attributes
143
-		$this->registerService('UserId', function ($c) {
143
+		$this->registerService('UserId', function($c) {
144 144
 			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
145 145
 		});
146 146
 
147
-		$this->registerService('WebRoot', function ($c) {
147
+		$this->registerService('WebRoot', function($c) {
148 148
 			return $c->query('ServerContainer')->getWebRoot();
149 149
 		});
150 150
 
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 			return Util::getDefaultEmailAddress('no-reply');
153 153
 		});
154 154
 
155
-		$this->registerService('OC_Defaults', function ($c) {
155
+		$this->registerService('OC_Defaults', function($c) {
156 156
 			return $c->getServer()->getThemingDefaults();
157 157
 		});
158 158
 
159
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
159
+		$this->registerService('OCP\Encryption\IManager', function($c) {
160 160
 			return $this->getServer()->getEncryptionManager();
161 161
 		});
162 162
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 			);
181 181
 		});
182 182
 
183
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
183
+		$this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) {
184 184
 			return new \OC\Security\IdentityProof\Manager(
185 185
 				$this->getServer()->getAppDataDir('identityproof'),
186 186
 				$this->getServer()->getCrypto()
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
 		/**
191 191
 		 * App Framework APIs
192 192
 		 */
193
-		$this->registerService('API', function($c){
193
+		$this->registerService('API', function($c) {
194 194
 			$c->query('OCP\\ILogger')->debug(
195
-				'Accessing the API class is deprecated! Use the appropriate ' .
195
+				'Accessing the API class is deprecated! Use the appropriate '.
196 196
 				'services instead!'
197 197
 			);
198 198
 			return new API($c['AppName']);
199 199
 		});
200 200
 
201
-		$this->registerService('Protocol', function($c){
201
+		$this->registerService('Protocol', function($c) {
202 202
 			/** @var \OC\Server $server */
203 203
 			$server = $c->query('ServerContainer');
204 204
 			$protocol = $server->getRequest()->getHttpProtocol();
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 			);
266 266
 		});
267 267
 
268
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
268
+		$this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) {
269 269
 			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
270 270
 			$userSession = $app->getServer()->getUserSession();
271 271
 			$session = $app->getServer()->getSession();
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
276 276
 		});
277 277
 
278
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
278
+		$this->registerService('OCSMiddleware', function(SimpleContainer $c) {
279 279
 			return new OCSMiddleware(
280 280
 				$c['Request']
281 281
 			);
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 			$dispatcher->registerMiddleware($c['SecurityMiddleware']);
290 290
 			$dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
291 291
 
292
-			foreach($middleWares as $middleWare) {
292
+			foreach ($middleWares as $middleWare) {
293 293
 				$dispatcher->registerMiddleware($c[$middleWare]);
294 294
 			}
295 295
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 * @return mixed
362 362
 	 */
363 363
 	function log($message, $level) {
364
-		switch($level){
364
+		switch ($level) {
365 365
 			case 'debug':
366 366
 				$level = \OCP\Util::DEBUG;
367 367
 				break;
@@ -420,12 +420,12 @@  discard block
 block discarded – undo
420 420
 				return parent::query($name);
421 421
 			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
422 422
 				return parent::query($name);
423
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
423
+			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) {
424 424
 				return parent::query($name);
425 425
 			}
426 426
 		}
427 427
 
428
-		throw new QueryException('Could not resolve ' . $name . '!' .
428
+		throw new QueryException('Could not resolve '.$name.'!'.
429 429
 			' Class can not be instantiated');
430 430
 	}
431 431
 }
Please login to merge, or discard this patch.
lib/private/Security/RateLimiting/Backend/MemoryCache.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return string
54 54
 	 */
55 55
 	private function hash($methodIdentifier, $userIdentifier) {
56
-		return hash('sha512', $methodIdentifier . $userIdentifier);
56
+		return hash('sha512', $methodIdentifier.$userIdentifier);
57 57
 	}
58 58
 
59 59
 	/**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	private function getExistingAttempts($identifier) {
64 64
 		$cachedAttempts = json_decode($this->cache->get($identifier), true);
65
-		if(is_array($cachedAttempts)) {
65
+		if (is_array($cachedAttempts)) {
66 66
 			return $cachedAttempts;
67 67
 		}
68 68
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 		$currentTime = $this->timeFactory->getTime();
81 81
 		/** @var array $existingAttempts */
82 82
 		foreach ($existingAttempts as $attempt) {
83
-			if(($attempt + $seconds) > $currentTime) {
83
+			if (($attempt + $seconds) > $currentTime) {
84 84
 				$count++;
85 85
 			}
86 86
 		}
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	public function registerAttempt($methodIdentifier, $userIdentifier, $timestamp) {
95 95
 		$identifier = $this->hash($methodIdentifier, $userIdentifier);
96 96
 		$existingAttempts = $this->getExistingAttempts($identifier);
97
-		$existingAttempts[] = (string)$timestamp;
97
+		$existingAttempts[] = (string) $timestamp;
98 98
 		$this->cache->set($identifier, json_encode($existingAttempts));
99 99
 	}
100 100
 }
Please login to merge, or discard this patch.
lib/private/Security/RateLimiting/Limiter.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 							  $userIdentifier,
61 61
 							  $period,
62 62
 							  $limit) {
63
-		$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int)$period);
64
-		if ($existingAttempts >= (int)$limit) {
63
+		$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int) $period);
64
+		if ($existingAttempts >= (int) $limit) {
65 65
 			throw new RateLimitExceededException();
66 66
 		}
67 67
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 										$ip) {
84 84
 		$ipSubnet = (new IpAddress($ip))->getSubnet();
85 85
 
86
-		$anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
86
+		$anonHashIdentifier = hash('sha512', 'anon::'.$identifier.$ipSubnet);
87 87
 		$this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit);
88 88
 	}
89 89
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 										$userLimit,
101 101
 										$userPeriod,
102 102
 										IUser $user) {
103
-		$userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
103
+		$userHashIdentifier = hash('sha512', 'user::'.$identifier.$user->getUID());
104 104
 		$this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
105 105
 	}
106 106
 }
Please login to merge, or discard this patch.
lib/private/Security/Bruteforce/Throttler.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	private function getCutoff($expire) {
80 80
 		$d1 = new \DateTime();
81 81
 		$d2 = clone $d1;
82
-		$d2->sub(new \DateInterval('PT' . $expire . 'S'));
82
+		$d2->sub(new \DateInterval('PT'.$expire.'S'));
83 83
 		return $d2->diff($d1);
84 84
 	}
85 85
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 									$ip,
95 95
 									array $metadata = []) {
96 96
 		// No need to log if the bruteforce protection is disabled
97
-		if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
97
+		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
98 98
 			return;
99 99
 		}
100 100
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		$values = [
103 103
 			'action' => $action,
104 104
 			'occurred' => $this->timeFactory->getTime(),
105
-			'ip' => (string)$ipAddress,
105
+			'ip' => (string) $ipAddress,
106 106
 			'subnet' => $ipAddress->getSubnet(),
107 107
 			'metadata' => json_encode($metadata),
108 108
 		];
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 		$qb = $this->db->getQueryBuilder();
122 122
 		$qb->insert('bruteforce_attempts');
123
-		foreach($values as $column => $value) {
123
+		foreach ($values as $column => $value) {
124 124
 			$qb->setValue($column, $qb->createNamedParameter($value));
125 125
 		}
126 126
 		$qb->execute();
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 			$cx = explode('/', $cidr);
156 156
 			$addr = $cx[0];
157
-			$mask = (int)$cx[1];
157
+			$mask = (int) $cx[1];
158 158
 
159 159
 			// Do not compare ipv4 to ipv6
160 160
 			if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 			$addr = inet_pton($addr);
166 166
 
167 167
 			$valid = true;
168
-			for($i = 0; $i < $mask; $i++) {
169
-				$part = ord($addr[(int)($i/8)]);
170
-				$orig = ord($ip[(int)($i/8)]);
168
+			for ($i = 0; $i < $mask; $i++) {
169
+				$part = ord($addr[(int) ($i / 8)]);
170
+				$orig = ord($ip[(int) ($i / 8)]);
171 171
 
172 172
 				$part = $part & (15 << (1 - ($i % 2)));
173 173
 				$orig = $orig & (15 << (1 - ($i % 2)));
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 */
197 197
 	public function getDelay($ip, $action = '') {
198 198
 		$ipAddress = new IpAddress($ip);
199
-		if ($this->isIPWhitelisted((string)$ipAddress)) {
199
+		if ($this->isIPWhitelisted((string) $ipAddress)) {
200 200
 			return 0;
201 201
 		}
202 202
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 
223 223
 		$maxDelay = 30;
224 224
 		$firstDelay = 0.1;
225
-		if ($attempts > (8 * PHP_INT_SIZE - 1))  {
225
+		if ($attempts > (8 * PHP_INT_SIZE - 1)) {
226 226
 			// Don't ever overflow. Just assume the maxDelay time:s
227 227
 			$firstDelay = $maxDelay;
228 228
 		} else {
Please login to merge, or discard this patch.