Completed
Push — spip-3.0 ( ab100a...484b62 )
by cam
06:49
created
config/ecran_securite.php 1 patch
Braces   +80 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
 /*
15 15
  * Test utilisateur
16 16
  */
17
-if (isset($_GET['test_ecran_securite']))
17
+if (isset($_GET['test_ecran_securite'])) {
18 18
 	$ecran_securite_raison = 'test '._ECRAN_SECURITE;
19
+}
19 20
 
20 21
 /*
21 22
  * Monitoring
@@ -198,18 +199,21 @@  discard block
 block discarded – undo
198 199
  * (id_base est une variable de la config des widgets de WordPress)
199 200
  */
200 201
 $_exceptions = array('id_table','id_base','id_parent','id_article_pdf');
201
-foreach ($_GET as $var => $val)
202
+foreach ($_GET as $var => $val) {
202 203
 	if ($_GET[$var] and strncmp($var, "id_", 3) == 0
203 204
 		and !in_array($var, $_exceptions))
204 205
 		$_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]);
205
-foreach ($_POST as $var => $val)
206
+}
207
+foreach ($_POST as $var => $val) {
206 208
 	if ($_POST[$var] and strncmp($var, "id_", 3) == 0
207 209
 		and !in_array($var, $_exceptions))
208 210
 		$_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]);
209
-foreach ($GLOBALS as $var => $val)
211
+}
212
+foreach ($GLOBALS as $var => $val) {
210 213
 	if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0
211 214
 		and !in_array($var, $_exceptions))
212 215
 		$GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]);
216
+}
213 217
 
214 218
 /*
215 219
  * Interdit la variable $cjpeg_command, qui était utilisée sans
@@ -221,11 +225,13 @@  discard block
 block discarded – undo
221 225
  * Contrôle de quelques variables (XSS)
222 226
  */
223 227
 foreach(array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) {
224
-	if (isset($_GET[$var]))
225
-		$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
226
-	if (isset($_POST[$var]))
227
-		$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
228
-}
228
+	if (isset($_GET[$var])) {
229
+			$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
230
+	}
231
+	if (isset($_POST[$var])) {
232
+			$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
233
+	}
234
+	}
229 235
 
230 236
 /*
231 237
  * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x)
@@ -239,41 +245,49 @@  discard block
 block discarded – undo
239 245
  */
240 246
 if (isset($_REQUEST['mode']) and isset($_REQUEST['page'])
241 247
 and !in_array($_REQUEST['mode'], array("6forum", "1comite"))
242
-and $_REQUEST['page'] == "identifiants")
248
+and $_REQUEST['page'] == "identifiants") {
243 249
 	$ecran_securite_raison = "identifiants";
250
+}
244 251
 
245 252
 /*
246 253
  * Agenda joue à l'injection php
247 254
  */
248 255
 if (isset($_REQUEST['partie_cal'])
249
-and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal']))
256
+and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])) {
250 257
 	$ecran_securite_raison = "partie_cal";
258
+}
251 259
 if (isset($_REQUEST['echelle'])
252
-and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle']))
260
+and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])) {
253 261
 	$ecran_securite_raison = "echelle";
262
+}
254 263
 
255 264
 /*
256 265
  * Espace privé
257 266
  */
258 267
 if (isset($_REQUEST['exec'])
259
-and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec']))
268
+and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])) {
260 269
 	$ecran_securite_raison = "exec";
270
+}
261 271
 if (isset($_REQUEST['cherche_auteur'])
262
-and preg_match(',[<],', (string)$_REQUEST['cherche_auteur']))
272
+and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])) {
263 273
 	$ecran_securite_raison = "cherche_auteur";
274
+}
264 275
 if (isset($_REQUEST['exec'])
265 276
 and $_REQUEST['exec'] == 'auteurs'
266
-and preg_match(',[<],', (string)$_REQUEST['recherche']))
277
+and preg_match(',[<],', (string)$_REQUEST['recherche'])) {
267 278
 	$ecran_securite_raison = "recherche";
279
+}
268 280
 if (isset($_REQUEST['exec'])
269 281
 and $_REQUEST['exec'] == 'info_plugin'
270
-and preg_match(',[<],', (string)$_REQUEST['plugin']))
282
+and preg_match(',[<],', (string)$_REQUEST['plugin'])) {
271 283
 	$ecran_securite_raison = "plugin";
284
+}
272 285
 if (isset($_REQUEST['exec'])
273 286
 and $_REQUEST['exec'] == 'puce_statut'
274 287
 and isset($_REQUEST['id'])
275
-and !intval($_REQUEST['id']))
288
+and !intval($_REQUEST['id'])) {
276 289
 	$ecran_securite_raison = "puce_statut";
290
+}
277 291
 if (isset($_REQUEST['action'])
278 292
 and $_REQUEST['action'] == 'configurer') {
279 293
 	if (@file_exists('inc_version.php')
@@ -298,21 +312,24 @@  discard block
 block discarded – undo
298 312
 	@get_magic_quotes_gpc() ?
299 313
 		stripslashes(serialize($_REQUEST)) : serialize($_REQUEST),
300 314
 	chr(0)
301
-) !== false)
315
+) !== false) {
302 316
 	$ecran_securite_raison = "%00";
317
+}
303 318
 
304 319
 /*
305 320
  * Bloque les requêtes fond=formulaire_
306 321
  */
307 322
 if (isset($_REQUEST['fond'])
308
-and preg_match(',^formulaire_,i', $_REQUEST['fond']))
323
+and preg_match(',^formulaire_,i', $_REQUEST['fond'])) {
309 324
 	$ecran_securite_raison = "fond=formulaire_";
325
+}
310 326
 
311 327
 /*
312 328
  * Bloque les requêtes du type ?GLOBALS[type_urls]=toto (bug vieux php)
313 329
  */
314
-if (isset($_REQUEST['GLOBALS']))
330
+if (isset($_REQUEST['GLOBALS'])) {
315 331
 	$ecran_securite_raison = "GLOBALS[GLOBALS]";
332
+}
316 333
 
317 334
 /*
318 335
  * Bloque les requêtes des bots sur:
@@ -325,29 +342,34 @@  discard block
 block discarded – undo
325 342
 		or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_') )
326 343
 		or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI']))
327 344
 )
328
-)
345
+) {
329 346
 	$ecran_securite_raison = "robot agenda/double pagination";
347
+}
330 348
 
331 349
 /*
332 350
  * Bloque une vieille page de tests de CFG (<1.11)
333 351
  * Bloque un XSS sur une page inexistante
334 352
  */
335 353
 if (isset($_REQUEST['page'])) {
336
-	if ($_REQUEST['page'] == 'test_cfg')
337
-		$ecran_securite_raison = "test_cfg";
338
-	if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page']))
339
-		$ecran_securite_raison = "xsspage";
354
+	if ($_REQUEST['page'] == 'test_cfg') {
355
+			$ecran_securite_raison = "test_cfg";
356
+	}
357
+	if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) {
358
+			$ecran_securite_raison = "xsspage";
359
+	}
340 360
 	if ($_REQUEST['page'] == '404'
341
-	and isset($_REQUEST['erreur']))
342
-		$ecran_securite_raison = "xss404";
343
-}
361
+	and isset($_REQUEST['erreur'])) {
362
+			$ecran_securite_raison = "xss404";
363
+	}
364
+	}
344 365
 
345 366
 /*
346 367
  * XSS par array
347 368
  */
348
-foreach (array('var_login') as $var)
349
-if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var]))
369
+foreach (array('var_login') as $var) {
370
+    if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var]))
350 371
 	$ecran_securite_raison = "xss ".$var;
372
+}
351 373
 
352 374
 /*
353 375
  * Parade antivirale contre un cheval de troie
@@ -357,18 +379,21 @@  discard block
 block discarded – undo
357 379
 	function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) {
358 380
 		// si jamais on est arrivé ici sur une erreur php
359 381
 		// et qu'un autre gestionnaire d'erreur est défini, l'appeller
360
-		if ($b && $GLOBALS['tmp_xhgfjokl'])
361
-			call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d);
382
+		if ($b && $GLOBALS['tmp_xhgfjokl']) {
383
+					call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d);
384
+		}
362 385
 	}
363 386
 }
364
-if (isset($_POST['tmp_lkojfghx3']))
387
+if (isset($_POST['tmp_lkojfghx3'])) {
365 388
 	$ecran_securite_raison = "gumblar";
389
+}
366 390
 
367 391
 /*
368 392
  * Outils XML mal sécurisés < 2.0.9
369 393
  */
370
-if (isset($_REQUEST['transformer_xml']))
394
+if (isset($_REQUEST['transformer_xml'])) {
371 395
 	$ecran_securite_raison = "transformer_xml";
396
+}
372 397
 
373 398
 /*
374 399
  * Outils XML mal sécurisés again
@@ -387,11 +412,13 @@  discard block
 block discarded – undo
387 412
  * Sauvegarde mal securisée < 2.0.9
388 413
  */
389 414
 if (isset($_REQUEST['nom_sauvegarde'])
390
-and strstr((string)$_REQUEST['nom_sauvegarde'], '/'))
415
+and strstr((string)$_REQUEST['nom_sauvegarde'], '/')) {
391 416
 	$ecran_securite_raison = 'nom_sauvegarde manipulee';
417
+}
392 418
 if (isset($_REQUEST['znom_sauvegarde'])
393
-and strstr((string)$_REQUEST['znom_sauvegarde'], '/'))
419
+and strstr((string)$_REQUEST['znom_sauvegarde'], '/')) {
394 420
 	$ecran_securite_raison = 'znom_sauvegarde manipulee';
421
+}
395 422
 
396 423
 
397 424
 /*
@@ -399,8 +426,9 @@  discard block
 block discarded – undo
399 426
  * on vérifie 'page' pour ne pas bloquer ... drupal
400 427
  */
401 428
 if (isset($_REQUEST['op']) and isset($_REQUEST['page'])
402
-and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op']))
429
+and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op'])) {
403 430
 	$ecran_securite_raison = 'op';
431
+}
404 432
 
405 433
 /*
406 434
  * Forms & Table ne se méfiait pas assez des uploads de fichiers
@@ -408,8 +436,9 @@  discard block
 block discarded – undo
408 436
 if (count($_FILES)){
409 437
 	foreach($_FILES as $k => $v){
410 438
 		 if (preg_match(',^fichier_\d+$,', $k)
411
-		 and preg_match(',\.php,i', $v['name']))
412
-		 	unset($_FILES[$k]);
439
+		 and preg_match(',\.php,i', $v['name'])) {
440
+		 		 	unset($_FILES[$k]);
441
+		 }
413 442
 	}
414 443
 }
415 444
 /*
@@ -426,21 +455,24 @@  discard block
 block discarded – undo
426 455
  * reinstall=oui un peu trop permissif
427 456
  */
428 457
 if (isset($_REQUEST['reinstall'])
429
-and $_REQUEST['reinstall'] == 'oui')
458
+and $_REQUEST['reinstall'] == 'oui') {
430 459
 	$ecran_securite_raison = 'reinstall=oui';
460
+}
431 461
 
432 462
 /*
433 463
  * Échappement xss referer
434 464
  */
435
-if (isset($_SERVER['HTTP_REFERER']))
465
+if (isset($_SERVER['HTTP_REFERER'])) {
436 466
 	$_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##');
467
+}
437 468
 
438 469
 
439 470
 /*
440 471
  * Echappement HTTP_X_FORWARDED_HOST
441 472
  */
442
-if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
473
+if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
443 474
 	$_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________');
475
+}
444 476
 
445 477
 
446 478
 /*
@@ -448,9 +480,10 @@  discard block
 block discarded – undo
448 480
  */
449 481
 if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false){
450 482
 	$zzzz = implode("", array_keys($_REQUEST));
451
-	if (strlen($zzzz) != strcspn($zzzz, '<>"\''))
452
-		$ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
453
-}
483
+	if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) {
484
+			$ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
485
+	}
486
+	}
454 487
 
455 488
 /*
456 489
  * Injection par connect
@@ -499,8 +532,9 @@  discard block
 block discarded – undo
499 532
 /*
500 533
  * Bloque les bots quand le load déborde
501 534
  */
502
-if (!defined('_ECRAN_SECURITE_LOAD'))
535
+if (!defined('_ECRAN_SECURITE_LOAD')) {
503 536
 	define('_ECRAN_SECURITE_LOAD', 4);
537
+}
504 538
 
505 539
 if (
506 540
 	defined('_ECRAN_SECURITE_LOAD')
Please login to merge, or discard this patch.