Completed
Pull Request — master (#5948)
by Lukas
17:30
created
lib/public/AppFramework/Middleware.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
 	 *                           the controller
54 54
 	 * @since 6.0.0
55 55
 	 */
56
-	public function beforeController($controller, $methodName){
56
+	public function beforeController($controller, $methodName) {
57 57
 
58 58
 	}
59 59
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return Response a Response object in case that the exception was handled
74 74
 	 * @since 6.0.0
75 75
 	 */
76
-	public function afterException($controller, $methodName, \Exception $exception){
76
+	public function afterException($controller, $methodName, \Exception $exception) {
77 77
 		throw $exception;
78 78
 	}
79 79
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @return Response a Response object
90 90
 	 * @since 6.0.0
91 91
 	 */
92
-	public function afterController($controller, $methodName, Response $response){
92
+	public function afterController($controller, $methodName, Response $response) {
93 93
 		return $response;
94 94
 	}
95 95
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @return string the output that should be printed
106 106
 	 * @since 6.0.0
107 107
 	 */
108
-	public function beforeOutput($controller, $methodName, $output){
108
+	public function beforeOutput($controller, $methodName, $output) {
109 109
 		return $output;
110 110
 	}
111 111
 
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/CORSMiddleware.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 * @throws SecurityException
81 81
 	 * @since 6.0.0
82 82
 	 */
83
-	public function beforeController($controller, $methodName){
83
+	public function beforeController($controller, $methodName) {
84 84
 		// ensure that @CORS annotated API routes are not used in conjunction
85 85
 		// with session authentication since this enables CSRF attack vectors
86 86
 		if ($this->reflector->hasAnnotation('CORS') &&
87
-			!$this->reflector->hasAnnotation('PublicPage'))  {
87
+			!$this->reflector->hasAnnotation('PublicPage')) {
88 88
 			$user = $this->request->server['PHP_AUTH_USER'];
89 89
 			$pass = $this->request->server['PHP_AUTH_PW'];
90 90
 
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 	 * @return Response a Response object
111 111
 	 * @throws SecurityException
112 112
 	 */
113
-	public function afterController($controller, $methodName, Response $response){
113
+	public function afterController($controller, $methodName, Response $response) {
114 114
 		// only react if its a CORS request and if the request sends origin and
115 115
 
116
-		if(isset($this->request->server['HTTP_ORIGIN']) &&
116
+		if (isset($this->request->server['HTTP_ORIGIN']) &&
117 117
 			$this->reflector->hasAnnotation('CORS')) {
118 118
 
119 119
 			// allow credentials headers must not be true or CSRF is possible
120 120
 			// otherwise
121
-			foreach($response->getHeaders() as $header => $value) {
122
-				if(strtolower($header) === 'access-control-allow-credentials' &&
121
+			foreach ($response->getHeaders() as $header => $value) {
122
+				if (strtolower($header) === 'access-control-allow-credentials' &&
123 123
 				   strtolower(trim($value)) === 'true') {
124 124
 					$msg = 'Access-Control-Allow-Credentials must not be '.
125 125
 						   'set to true in order to prevent CSRF';
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 	 * @throws \Exception the passed in exception if it can't handle it
144 144
 	 * @return Response a Response object or null in case that the exception could not be handled
145 145
 	 */
146
-	public function afterException($controller, $methodName, \Exception $exception){
147
-		if($exception instanceof SecurityException){
148
-			$response =  new JSONResponse(['message' => $exception->getMessage()]);
149
-			if($exception->getCode() !== 0) {
146
+	public function afterException($controller, $methodName, \Exception $exception) {
147
+		if ($exception instanceof SecurityException) {
148
+			$response = new JSONResponse(['message' => $exception->getMessage()]);
149
+			if ($exception->getCode() !== 0) {
150 150
 				$response->setStatus($exception->getCode());
151 151
 			} else {
152 152
 				$response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/SessionMiddleware.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
 	 * @param Response $response
72 72
 	 * @return Response
73 73
 	 */
74
-	public function afterController($controller, $methodName, Response $response){
74
+	public function afterController($controller, $methodName, Response $response) {
75 75
 		$useSession = $this->reflector->hasAnnotation('UseSession');
76 76
 		if ($useSession) {
77 77
 			$this->session->close();
Please login to merge, or discard this patch.
settings/Middleware/SubadminMiddleware.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 	 * @throws \Exception
60 60
 	 */
61 61
 	public function beforeController($controller, $methodName) {
62
-		if(!$this->reflector->hasAnnotation('NoSubadminRequired')) {
63
-			if(!$this->isSubAdmin) {
62
+		if (!$this->reflector->hasAnnotation('NoSubadminRequired')) {
63
+			if (!$this->isSubAdmin) {
64 64
 				throw new NotAdminException('Logged in user must be a subadmin');
65 65
 			}
66 66
 		}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @throws \Exception
76 76
 	 */
77 77
 	public function afterException($controller, $methodName, \Exception $exception) {
78
-		if($exception instanceof NotAdminException) {
78
+		if ($exception instanceof NotAdminException) {
79 79
 			$response = new TemplateResponse('core', '403', array(), 'guest');
80 80
 			$response->setStatus(Http::STATUS_FORBIDDEN);
81 81
 			return $response;
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 		$anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period');
85 85
 		$userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit');
86 86
 		$userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period');
87
-		$rateLimitIdentifier = get_class($controller) . '::' . $methodName;
88
-		if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
87
+		$rateLimitIdentifier = get_class($controller).'::'.$methodName;
88
+		if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
89 89
 			$this->limiter->registerUserRequest(
90 90
 				$rateLimitIdentifier,
91 91
 				$userLimit,
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	 * {@inheritDoc}
107 107
 	 */
108 108
 	public function afterException($controller, $methodName, \Exception $exception) {
109
-		if($exception instanceof RateLimitExceededException) {
110
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
109
+		if ($exception instanceof RateLimitExceededException) {
110
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
111 111
 				$response = new JSONResponse(
112 112
 					[
113 113
 						'message' => $exception->getMessage(),
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	public function beforeController($controller, $methodName) {
62 62
 		parent::beforeController($controller, $methodName);
63 63
 
64
-		if($this->reflector->hasAnnotation('BruteForceProtection')) {
64
+		if ($this->reflector->hasAnnotation('BruteForceProtection')) {
65 65
 			$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
66 66
 			$this->throttler->sleepDelay($this->request->getRemoteAddress(), $action);
67 67
 		}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * {@inheritDoc}
72 72
 	 */
73 73
 	public function afterController($controller, $methodName, Response $response) {
74
-		if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) {
74
+		if ($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) {
75 75
 			$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
76 76
 			$ip = $this->request->getRemoteAddress();
77 77
 			$this->throttler->sleepDelay($ip, $action);
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
 
145 145
 		// security checks
146 146
 		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
147
-		if(!$isPublicPage) {
148
-			if(!$this->isLoggedIn) {
147
+		if (!$isPublicPage) {
148
+			if (!$this->isLoggedIn) {
149 149
 				throw new NotLoggedInException();
150 150
 			}
151 151
 
152
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
153
-				if(!$this->isAdminUser) {
152
+			if (!$this->reflector->hasAnnotation('NoAdminRequired')) {
153
+				if (!$this->isAdminUser) {
154 154
 					throw new NotAdminException();
155 155
 				}
156 156
 			}
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
 		}
165 165
 
166 166
 		// Check for strict cookie requirement
167
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
168
-			if(!$this->request->passesStrictCookieCheck()) {
167
+		if ($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
168
+			if (!$this->request->passesStrictCookieCheck()) {
169 169
 				throw new StrictCookieMissingException();
170 170
 			}
171 171
 		}
172 172
 		// CSRF check - also registers the CSRF token since the session may be closed later
173 173
 		Util::callRegister();
174
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
174
+		if (!$this->reflector->hasAnnotation('NoCSRFRequired')) {
175 175
 			/*
176 176
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
177 177
 			 * hacks around that we have no full token auth in place yet and we
178 178
 			 * do want to offer CSRF checks for web requests.
179 179
 			 */
180
-			if(!$this->request->passesCSRFCheck() && !(
180
+			if (!$this->request->passesCSRFCheck() && !(
181 181
 					$controller instanceof OCSController &&
182 182
 					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
183 183
 				throw new CrossSiteRequestForgeryException();
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		 * The getAppPath() check is here since components such as settings also use the AppFramework and
191 191
 		 * therefore won't pass this check.
192 192
 		 */
193
-		if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
193
+		if (\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
194 194
 			throw new AppNotEnabledException();
195 195
 		}
196 196
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
216 216
 		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
217 217
 
218
-		if($this->cspNonceManager->browserSupportsCspV3()) {
218
+		if ($this->cspNonceManager->browserSupportsCspV3()) {
219 219
 			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
220 220
 		}
221 221
 
@@ -235,17 +235,17 @@  discard block
 block discarded – undo
235 235
 	 * @return Response a Response object or null in case that the exception could not be handled
236 236
 	 */
237 237
 	public function afterException($controller, $methodName, \Exception $exception) {
238
-		if($exception instanceof SecurityException) {
239
-			if($exception instanceof StrictCookieMissingException) {
238
+		if ($exception instanceof SecurityException) {
239
+			if ($exception instanceof StrictCookieMissingException) {
240 240
 				return new RedirectResponse(\OC::$WEBROOT);
241 241
  			}
242
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
242
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
243 243
 				$response = new JSONResponse(
244 244
 					array('message' => $exception->getMessage()),
245 245
 					$exception->getCode()
246 246
 				);
247 247
 			} else {
248
-				if($exception instanceof NotLoggedInException) {
248
+				if ($exception instanceof NotLoggedInException) {
249 249
 					$params = [];
250 250
 					if (isset($this->request->server['REQUEST_URI'])) {
251 251
 						$params['redirect_url'] = $this->request->server['REQUEST_URI'];
Please login to merge, or discard this patch.
apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @throws ShareNotFound
93 93
 	 */
94 94
 	public function beforeController($controller, $methodName) {
95
-		if(!$this->isSharingEnabled()) {
95
+		if (!$this->isSharingEnabled()) {
96 96
 			throw new NotFoundException('Sharing is disabled.');
97 97
 		}
98 98
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @throws \Exception
120 120
 	 */
121 121
 	public function afterException($controller, $methodName, \Exception $exception) {
122
-		if(is_a($exception, '\OCP\Files\NotFoundException')) {
122
+		if (is_a($exception, '\OCP\Files\NotFoundException')) {
123 123
 			return new NotFoundResponse();
124 124
 		}
125 125
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	private function isSharingEnabled() {
157 157
 		// FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
158 158
 		// Check whether the sharing application is enabled
159
-		if(!$this->appManager->isEnabledForUser($this->appName)) {
159
+		if (!$this->appManager->isEnabledForUser($this->appName)) {
160 160
 			return false;
161 161
 		}
162 162
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 		}
175 175
 
176 176
 		// Check whether public sharing is enabled
177
-		if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
177
+		if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
178 178
 			return false;
179 179
 		}
180 180
 
Please login to merge, or discard this patch.