Completed
Push — master ( b1dd17...a00e03 )
by cam
05:16
created
config/ecran_securite.php 1 patch
Braces   +84 added lines, -49 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
@@ -243,18 +244,21 @@  discard block
 block discarded – undo
243 244
  * (id_base est une variable de la config des widgets de WordPress)
244 245
  */
245 246
 $_exceptions = array('id_table','id_base','id_parent','id_article_pdf');
246
-foreach ($_GET as $var => $val)
247
+foreach ($_GET as $var => $val) {
247 248
 	if ($_GET[$var] and strncmp($var, "id_", 3) == 0
248 249
 		and !in_array($var, $_exceptions))
249 250
 		$_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]);
250
-foreach ($_POST as $var => $val)
251
+}
252
+foreach ($_POST as $var => $val) {
251 253
 	if ($_POST[$var] and strncmp($var, "id_", 3) == 0
252 254
 		and !in_array($var, $_exceptions))
253 255
 		$_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]);
254
-foreach ($GLOBALS as $var => $val)
256
+}
257
+foreach ($GLOBALS as $var => $val) {
255 258
 	if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0
256 259
 		and !in_array($var, $_exceptions))
257 260
 		$GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]);
261
+}
258 262
 
259 263
 /*
260 264
  * Interdit la variable $cjpeg_command, qui était utilisée sans
@@ -266,11 +270,13 @@  discard block
 block discarded – undo
266 270
  * Contrôle de quelques variables (XSS)
267 271
  */
268 272
 foreach(array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) {
269
-	if (isset($_GET[$var]))
270
-		$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
271
-	if (isset($_POST[$var]))
272
-		$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
273
-}
273
+	if (isset($_GET[$var])) {
274
+			$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
275
+	}
276
+	if (isset($_POST[$var])) {
277
+			$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
278
+	}
279
+	}
274 280
 
275 281
 /*
276 282
  * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x)
@@ -286,41 +292,49 @@  discard block
 block discarded – undo
286 292
  */
287 293
 if (isset($_REQUEST['mode']) and isset($_REQUEST['page'])
288 294
 and !in_array($_REQUEST['mode'], array("6forum", "1comite"))
289
-and $_REQUEST['page'] == "identifiants")
295
+and $_REQUEST['page'] == "identifiants") {
290 296
 	$ecran_securite_raison = "identifiants";
297
+}
291 298
 
292 299
 /*
293 300
  * Agenda joue à l'injection php
294 301
  */
295 302
 if (isset($_REQUEST['partie_cal'])
296
-and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal']))
303
+and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])) {
297 304
 	$ecran_securite_raison = "partie_cal";
305
+}
298 306
 if (isset($_REQUEST['echelle'])
299
-and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle']))
307
+and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])) {
300 308
 	$ecran_securite_raison = "echelle";
309
+}
301 310
 
302 311
 /*
303 312
  * Espace privé
304 313
  */
305 314
 if (isset($_REQUEST['exec'])
306
-and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec']))
315
+and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])) {
307 316
 	$ecran_securite_raison = "exec";
317
+}
308 318
 if (isset($_REQUEST['cherche_auteur'])
309
-and preg_match(',[<],', (string)$_REQUEST['cherche_auteur']))
319
+and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])) {
310 320
 	$ecran_securite_raison = "cherche_auteur";
321
+}
311 322
 if (isset($_REQUEST['exec'])
312 323
 and $_REQUEST['exec'] == 'auteurs'
313
-and preg_match(',[<],', (string)$_REQUEST['recherche']))
324
+and preg_match(',[<],', (string)$_REQUEST['recherche'])) {
314 325
 	$ecran_securite_raison = "recherche";
326
+}
315 327
 if (isset($_REQUEST['exec'])
316 328
 and $_REQUEST['exec'] == 'info_plugin'
317
-and preg_match(',[<],', (string)$_REQUEST['plugin']))
329
+and preg_match(',[<],', (string)$_REQUEST['plugin'])) {
318 330
 	$ecran_securite_raison = "plugin";
331
+}
319 332
 if (isset($_REQUEST['exec'])
320 333
 and $_REQUEST['exec'] == 'puce_statut'
321 334
 and isset($_REQUEST['id'])
322
-and !intval($_REQUEST['id']))
335
+and !intval($_REQUEST['id'])) {
323 336
 	$ecran_securite_raison = "puce_statut";
337
+}
324 338
 if (isset($_REQUEST['action'])
325 339
 and $_REQUEST['action'] == 'configurer') {
326 340
 	if (@file_exists('inc_version.php')
@@ -352,21 +366,24 @@  discard block
 block discarded – undo
352 366
 	(function_exists('get_magic_quotes_gpc') and @get_magic_quotes_gpc()) ?
353 367
 		stripslashes(serialize($_REQUEST)) : serialize($_REQUEST),
354 368
 	chr(0)
355
-) !== false)
369
+) !== false) {
356 370
 	$ecran_securite_raison = "%00";
371
+}
357 372
 
358 373
 /*
359 374
  * Bloque les requêtes fond=formulaire_
360 375
  */
361 376
 if (isset($_REQUEST['fond'])
362
-and preg_match(',^formulaire_,i', $_REQUEST['fond']))
377
+and preg_match(',^formulaire_,i', $_REQUEST['fond'])) {
363 378
 	$ecran_securite_raison = "fond=formulaire_";
379
+}
364 380
 
365 381
 /*
366 382
  * Bloque les requêtes du type ?GLOBALS[type_urls]=toto (bug vieux php)
367 383
  */
368
-if (isset($_REQUEST['GLOBALS']))
384
+if (isset($_REQUEST['GLOBALS'])) {
369 385
 	$ecran_securite_raison = "GLOBALS[GLOBALS]";
386
+}
370 387
 
371 388
 /*
372 389
  * Bloque les requêtes des bots sur:
@@ -379,29 +396,34 @@  discard block
 block discarded – undo
379 396
 		or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_') )
380 397
 		or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI']))
381 398
 )
382
-)
399
+) {
383 400
 	$ecran_securite_raison = "robot agenda/double pagination";
401
+}
384 402
 
385 403
 /*
386 404
  * Bloque une vieille page de tests de CFG (<1.11)
387 405
  * Bloque un XSS sur une page inexistante
388 406
  */
389 407
 if (isset($_REQUEST['page'])) {
390
-	if ($_REQUEST['page'] == 'test_cfg')
391
-		$ecran_securite_raison = "test_cfg";
392
-	if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page']))
393
-		$ecran_securite_raison = "xsspage";
408
+	if ($_REQUEST['page'] == 'test_cfg') {
409
+			$ecran_securite_raison = "test_cfg";
410
+	}
411
+	if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) {
412
+			$ecran_securite_raison = "xsspage";
413
+	}
394 414
 	if ($_REQUEST['page'] == '404'
395
-	and isset($_REQUEST['erreur']))
396
-		$ecran_securite_raison = "xss404";
397
-}
415
+	and isset($_REQUEST['erreur'])) {
416
+			$ecran_securite_raison = "xss404";
417
+	}
418
+	}
398 419
 
399 420
 /*
400 421
  * XSS par array
401 422
  */
402
-foreach (array('var_login') as $var)
403
-if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var]))
423
+foreach (array('var_login') as $var) {
424
+    if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var]))
404 425
 	$ecran_securite_raison = "xss ".$var;
426
+}
405 427
 
406 428
 /*
407 429
  * Parade antivirale contre un cheval de troie
@@ -411,18 +433,21 @@  discard block
 block discarded – undo
411 433
 	function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) {
412 434
 		// si jamais on est arrivé ici sur une erreur php
413 435
 		// et qu'un autre gestionnaire d'erreur est défini, l'appeller
414
-		if ($b && $GLOBALS['tmp_xhgfjokl'])
415
-			call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d);
436
+		if ($b && $GLOBALS['tmp_xhgfjokl']) {
437
+					call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d);
438
+		}
416 439
 	}
417 440
 }
418
-if (isset($_POST['tmp_lkojfghx3']))
441
+if (isset($_POST['tmp_lkojfghx3'])) {
419 442
 	$ecran_securite_raison = "gumblar";
443
+}
420 444
 
421 445
 /*
422 446
  * Outils XML mal sécurisés < 2.0.9
423 447
  */
424
-if (isset($_REQUEST['transformer_xml']))
448
+if (isset($_REQUEST['transformer_xml'])) {
425 449
 	$ecran_securite_raison = "transformer_xml";
450
+}
426 451
 
427 452
 /*
428 453
  * Outils XML mal sécurisés again
@@ -441,11 +466,13 @@  discard block
 block discarded – undo
441 466
  * Sauvegarde mal securisée < 2.0.9
442 467
  */
443 468
 if (isset($_REQUEST['nom_sauvegarde'])
444
-and strstr((string)$_REQUEST['nom_sauvegarde'], '/'))
469
+and strstr((string)$_REQUEST['nom_sauvegarde'], '/')) {
445 470
 	$ecran_securite_raison = 'nom_sauvegarde manipulee';
471
+}
446 472
 if (isset($_REQUEST['znom_sauvegarde'])
447
-and strstr((string)$_REQUEST['znom_sauvegarde'], '/'))
473
+and strstr((string)$_REQUEST['znom_sauvegarde'], '/')) {
448 474
 	$ecran_securite_raison = 'znom_sauvegarde manipulee';
475
+}
449 476
 
450 477
 
451 478
 /*
@@ -453,8 +480,9 @@  discard block
 block discarded – undo
453 480
  * on vérifie 'page' pour ne pas bloquer ... drupal
454 481
  */
455 482
 if (isset($_REQUEST['op']) and isset($_REQUEST['page'])
456
-and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op']))
483
+and $_REQUEST['op'] !== preg_replace('/[^\-\w]/', '', $_REQUEST['op'])) {
457 484
 	$ecran_securite_raison = 'op';
485
+}
458 486
 
459 487
 /*
460 488
  * Forms & Table ne se méfiait pas assez des uploads de fichiers
@@ -462,8 +490,9 @@  discard block
 block discarded – undo
462 490
 if (count($_FILES)){
463 491
 	foreach($_FILES as $k => $v){
464 492
 		 if (preg_match(',^fichier_\d+$,', $k)
465
-		 and preg_match(',\.php,i', $v['name']))
466
-		 	unset($_FILES[$k]);
493
+		 and preg_match(',\.php,i', $v['name'])) {
494
+		 		 	unset($_FILES[$k]);
495
+		 }
467 496
 	}
468 497
 }
469 498
 /*
@@ -480,8 +509,9 @@  discard block
 block discarded – undo
480 509
  * reinstall=oui un peu trop permissif
481 510
  */
482 511
 if (isset($_REQUEST['reinstall'])
483
-and $_REQUEST['reinstall'] == 'oui')
512
+and $_REQUEST['reinstall'] == 'oui') {
484 513
 	$ecran_securite_raison = 'reinstall=oui';
514
+}
485 515
 
486 516
 /*
487 517
  * Pas d'action pendant l'install
@@ -493,24 +523,27 @@  discard block
 block discarded – undo
493 523
 /*
494 524
  * Échappement xss referer
495 525
  */
496
-if (isset($_SERVER['HTTP_REFERER']))
526
+if (isset($_SERVER['HTTP_REFERER'])) {
497 527
 	$_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##');
528
+}
498 529
 
499 530
 
500 531
 /*
501 532
  * Echappement HTTP_X_FORWARDED_HOST
502 533
  */
503
-if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
534
+if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
504 535
 	$_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________');
536
+}
505 537
 
506 538
 
507 539
 /*
508 540
  * Pas d'erreur dans l'erreur
509 541
  */
510 542
 if (isset($_REQUEST['var_erreur']) and isset($_REQUEST['page']) and $_REQUEST['page'] === 'login') {
511
-	if (strlen($_REQUEST['var_erreur']) !== strcspn($_REQUEST['var_erreur'], '<>'))
512
-		$ecran_securite_raison = 'var_erreur incorrecte';
513
-}
543
+	if (strlen($_REQUEST['var_erreur']) !== strcspn($_REQUEST['var_erreur'], '<>')) {
544
+			$ecran_securite_raison = 'var_erreur incorrecte';
545
+	}
546
+	}
514 547
 
515 548
 
516 549
 /*
@@ -521,9 +554,10 @@  discard block
 block discarded – undo
521 554
 	or isset($_REQUEST['var_memotri'])
522 555
 ){
523 556
 	$zzzz = implode("", array_keys($_REQUEST));
524
-	if (strlen($zzzz) != strcspn($zzzz, '<>"\''))
525
-		$ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
526
-}
557
+	if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) {
558
+			$ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
559
+	}
560
+	}
527 561
 
528 562
 /*
529 563
  * Injection par connect
@@ -572,8 +606,9 @@  discard block
 block discarded – undo
572 606
 /*
573 607
  * Bloque les bots quand le load déborde
574 608
  */
575
-if (!defined('_ECRAN_SECURITE_LOAD'))
609
+if (!defined('_ECRAN_SECURITE_LOAD')) {
576 610
 	define('_ECRAN_SECURITE_LOAD', 4);
611
+}
577 612
 
578 613
 if (
579 614
 	defined('_ECRAN_SECURITE_LOAD')
Please login to merge, or discard this patch.