Completed
Push — spip-3.0 ( ab100a...484b62 )
by cam
06:49
created
config/ecran_securite.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -23,18 +23,18 @@  discard block
 block discarded – undo
23 23
  * var_isbot=1 peut etre utilise pour monitorer la disponibilite pour les bots (sujets a 503 de delestage si
24 24
  * le load depasse ECRAN_SECURITE_LOAD)
25 25
  */
26
-if (!defined('_IS_BOT') and isset($_GET['var_isbot'])){
26
+if (!defined('_IS_BOT') and isset($_GET['var_isbot'])) {
27 27
 	define('_IS_BOT', $_GET['var_isbot'] ? true : false);
28 28
 }
29 29
 
30 30
 /*
31 31
  * Détecteur de robot d'indexation
32 32
  */
33
-if (!defined('_IS_BOT')){
33
+if (!defined('_IS_BOT')) {
34 34
 	define('_IS_BOT',
35 35
 		isset($_SERVER['HTTP_USER_AGENT'])
36 36
 		and preg_match(','
37
-		. implode ('|', array(
37
+		. implode('|', array(
38 38
 			// mots generiques
39 39
 			'bot',
40 40
 			'slurp',
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
 			'yats',
220 220
 			'yeti',
221 221
 			'zeerch'
222
-		)) . ',i',
223
-		(string)$_SERVER['HTTP_USER_AGENT'])
222
+		)).',i',
223
+		(string) $_SERVER['HTTP_USER_AGENT'])
224 224
 	);
225 225
 }
226
-if (!defined('_IS_BOT_FRIEND')){
226
+if (!defined('_IS_BOT_FRIEND')) {
227 227
 	define('_IS_BOT_FRIEND',
228 228
 		isset($_SERVER['HTTP_USER_AGENT'])
229
-		and preg_match(',' . implode ('|', array(
229
+		and preg_match(','.implode('|', array(
230 230
 			'facebookexternalhit',
231 231
 			'flipboardproxy',
232 232
 			'wordpress'
233
-		)) . ',i',
234
-		(string)$_SERVER['HTTP_USER_AGENT'])
233
+		)).',i',
234
+		(string) $_SERVER['HTTP_USER_AGENT'])
235 235
 	);
236 236
 }
237 237
 
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
  * (sauf pour id_table, qui n'est pas numérique jusqu'à [5743])
243 243
  * (id_base est une variable de la config des widgets de WordPress)
244 244
  */
245
-$_exceptions = array('id_table','id_base','id_parent','id_article_pdf');
245
+$_exceptions = array('id_table', 'id_base', 'id_parent', 'id_article_pdf');
246 246
 foreach ($_GET as $var => $val)
247 247
 	if ($_GET[$var] and strncmp($var, "id_", 3) == 0
248 248
 		and !in_array($var, $_exceptions))
249
-		$_GET[$var] = is_array($_GET[$var])?@array_map('intval', $_GET[$var]):intval($_GET[$var]);
249
+		$_GET[$var] = is_array($_GET[$var]) ? @array_map('intval', $_GET[$var]) : intval($_GET[$var]);
250 250
 foreach ($_POST as $var => $val)
251 251
 	if ($_POST[$var] and strncmp($var, "id_", 3) == 0
252 252
 		and !in_array($var, $_exceptions))
253
-		$_POST[$var] = is_array($_POST[$var])?@array_map('intval', $_POST[$var]):intval($_POST[$var]);
253
+		$_POST[$var] = is_array($_POST[$var]) ? @array_map('intval', $_POST[$var]) : intval($_POST[$var]);
254 254
 foreach ($GLOBALS as $var => $val)
255 255
 	if ($GLOBALS[$var] and strncmp($var, "id_", 3) == 0
256 256
 		and !in_array($var, $_exceptions))
257
-		$GLOBALS[$var] = is_array($GLOBALS[$var])?@array_map('intval', $GLOBALS[$var]):intval($GLOBALS[$var]);
257
+		$GLOBALS[$var] = is_array($GLOBALS[$var]) ? @array_map('intval', $GLOBALS[$var]) : intval($GLOBALS[$var]);
258 258
 
259 259
 /*
260 260
  * Interdit la variable $cjpeg_command, qui était utilisée sans
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 /*
266 266
  * Contrôle de quelques variables (XSS)
267 267
  */
268
-foreach(array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) {
268
+foreach (array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) {
269 269
 	if (isset($_GET[$var]))
270
-		$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
270
+		$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string) $_GET[$var]);
271 271
 	if (isset($_POST[$var]))
272
-		$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
272
+		$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string) $_POST[$var]);
273 273
 }
274 274
 
275 275
 /*
276 276
  * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x)
277 277
  */
278
-if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) {
279
-	$file = addslashes((string)$_GET['file']);
278
+if (preg_match(',^(.*/)?spip_acces_doc\.,', (string) $_SERVER['REQUEST_URI'])) {
279
+	$file = addslashes((string) $_GET['file']);
280 280
 }
281 281
 
282 282
 /*
@@ -291,28 +291,28 @@  discard block
 block discarded – undo
291 291
  * Agenda joue à l'injection php
292 292
  */
293 293
 if (isset($_REQUEST['partie_cal'])
294
-and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal']))
294
+and $_REQUEST['partie_cal'] !== htmlentities((string) $_REQUEST['partie_cal']))
295 295
 	$ecran_securite_raison = "partie_cal";
296 296
 if (isset($_REQUEST['echelle'])
297
-and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle']))
297
+and $_REQUEST['echelle'] !== htmlentities((string) $_REQUEST['echelle']))
298 298
 	$ecran_securite_raison = "echelle";
299 299
 
300 300
 /*
301 301
  * Espace privé
302 302
  */
303 303
 if (isset($_REQUEST['exec'])
304
-and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec']))
304
+and !preg_match(',^[\w-]+$,', (string) $_REQUEST['exec']))
305 305
 	$ecran_securite_raison = "exec";
306 306
 if (isset($_REQUEST['cherche_auteur'])
307
-and preg_match(',[<],', (string)$_REQUEST['cherche_auteur']))
307
+and preg_match(',[<],', (string) $_REQUEST['cherche_auteur']))
308 308
 	$ecran_securite_raison = "cherche_auteur";
309 309
 if (isset($_REQUEST['exec'])
310 310
 and $_REQUEST['exec'] == 'auteurs'
311
-and preg_match(',[<],', (string)$_REQUEST['recherche']))
311
+and preg_match(',[<],', (string) $_REQUEST['recherche']))
312 312
 	$ecran_securite_raison = "recherche";
313 313
 if (isset($_REQUEST['exec'])
314 314
 and $_REQUEST['exec'] == 'info_plugin'
315
-and preg_match(',[<],', (string)$_REQUEST['plugin']))
315
+and preg_match(',[<],', (string) $_REQUEST['plugin']))
316 316
 	$ecran_securite_raison = "plugin";
317 317
 if (isset($_REQUEST['exec'])
318 318
 and $_REQUEST['exec'] == 'puce_statut'
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	or @file_exists('ecrire/inc_version.php')) {
326 326
 		function action_configurer() {
327 327
 			include_spip('inc/autoriser');
328
-			if(!autoriser('configurer', _request('configuration'))) {
328
+			if (!autoriser('configurer', _request('configuration'))) {
329 329
 				include_spip('inc/minipres');
330 330
 				echo minipres(_T('info_acces_interdit'));
331 331
 				exit;
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
  */
367 367
 if (_IS_BOT and (
368 368
 	(isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type']))
369
-	or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI']))
370
-		or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_') )
371
-		or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI']))
369
+	or (strpos((string) $_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string) $_SERVER['REQUEST_URI']))
370
+		or (isset($_REQUEST['calendrier_annee']) and strpos((string) $_SERVER['REQUEST_URI'], 'debut_'))
371
+		or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string) $_SERVER['REQUEST_URI']))
372 372
 )
373 373
 )
374 374
 	$ecran_securite_raison = "robot agenda/double pagination";
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 if (isset($_REQUEST['page'])) {
381 381
 	if ($_REQUEST['page'] == 'test_cfg')
382 382
 		$ecran_securite_raison = "test_cfg";
383
-	if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page']))
383
+	if ($_REQUEST['page'] !== htmlspecialchars((string) $_REQUEST['page']))
384 384
 		$ecran_securite_raison = "xsspage";
385 385
 	if ($_REQUEST['page'] == '404'
386 386
 	and isset($_REQUEST['erreur']))
@@ -418,12 +418,12 @@  discard block
 block discarded – undo
418 418
 /*
419 419
  * Outils XML mal sécurisés again
420 420
  */
421
-if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec']=='valider_xml'){
421
+if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec'] == 'valider_xml') {
422 422
 	$url = trim($_REQUEST['var_url']);
423
-	if (strncmp($url,'/',1)==0
424
-	  or (($p=strpos($url,'..'))!==false AND strpos($url,'..',$p+3)!==false)
425
-	  or (($p=strpos($url,'..'))!==false AND strpos($url,'IMG',$p+3)!==false)
426
-		or (strpos($url,'://')!==false or strpos($url,':\\')!==false)) {
423
+	if (strncmp($url, '/', 1) == 0
424
+	  or (($p = strpos($url, '..')) !== false AND strpos($url, '..', $p + 3) !== false)
425
+	  or (($p = strpos($url, '..')) !== false AND strpos($url, 'IMG', $p + 3) !== false)
426
+		or (strpos($url, '://') !== false or strpos($url, ':\\') !== false)) {
427 427
 		$ecran_securite_raison = 'URL interdite pour var_url';
428 428
 	}
429 429
 }
@@ -432,10 +432,10 @@  discard block
 block discarded – undo
432 432
  * Sauvegarde mal securisée < 2.0.9
433 433
  */
434 434
 if (isset($_REQUEST['nom_sauvegarde'])
435
-and strstr((string)$_REQUEST['nom_sauvegarde'], '/'))
435
+and strstr((string) $_REQUEST['nom_sauvegarde'], '/'))
436 436
 	$ecran_securite_raison = 'nom_sauvegarde manipulee';
437 437
 if (isset($_REQUEST['znom_sauvegarde'])
438
-and strstr((string)$_REQUEST['znom_sauvegarde'], '/'))
438
+and strstr((string) $_REQUEST['znom_sauvegarde'], '/'))
439 439
 	$ecran_securite_raison = 'znom_sauvegarde manipulee';
440 440
 
441 441
 
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 /*
451 451
  * Forms & Table ne se méfiait pas assez des uploads de fichiers
452 452
  */
453
-if (count($_FILES)){
454
-	foreach($_FILES as $k => $v){
453
+if (count($_FILES)) {
454
+	foreach ($_FILES as $k => $v) {
455 455
 		 if (preg_match(',^fichier_\d+$,', $k)
456 456
 		 and preg_match(',\.php,i', $v['name']))
457 457
 		 	unset($_FILES[$k]);
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
  * et Contact trop laxiste avec une variable externe
462 462
  * on bloque pas le post pour eviter de perdre des donnees mais on unset la variable et c'est tout
463 463
  */
464
-if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']){
464
+if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']) {
465 465
 	unset($_REQUEST['pj_enregistrees_nom']);
466 466
 	unset($_GET['pj_enregistrees_nom']);
467 467
 	unset($_POST['pj_enregistrees_nom']);
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 /*
492 492
  * Réinjection des clés en html dans l'admin r19561
493 493
  */
494
-if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false){
494
+if (strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false) {
495 495
 	$zzzz = implode("", array_keys($_REQUEST));
496 496
 	if (strlen($zzzz) != strcspn($zzzz, '<>"\''))
497 497
 		$ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
Please login to merge, or discard this patch.