/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2017 *
+ * Copyright (c) 2001-2019 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
return false; # n'affecte pas $c
}
+/**
+ * Sanitizer une valeur *SI* elle provient du GET ou POST
+ * Utile dans les squelettes pour les valeurs qu'on attrape dans le env,
+ * dont on veut permettre à un squelette de confiance appelant de fournir une valeur complexe
+ * mais qui doit etre nettoyee si elle provient de l'URL
+ *
+ * On peut sanitizer
+ * - une valeur simple : `$where = spip_sanitize_from_request($value, 'where')`
+ * - un tableau en partie : `$env = spip_sanitize_from_request($env, ['key1','key2'])`
+ * - un tableau complet : `$env = spip_sanitize_from_request($env, '*')`
+ *
+ * @param string|array $value
+ * @param string|array $key
+ * @param string $sanitize_function
+ * @return array|mixed|string
+ */
+function spip_sanitize_from_request($value, $key, $sanitize_function='entites_html') {
+ if (is_array($value)) {
+ if ($key=='*') {
+ $key = array_keys($value);
+ }
+ if (!is_array($key)) {
+ $key = [$key];
+ }
+ foreach ($key as $k) {
+ if (!empty($value[$k])) {
+ $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
+ }
+ }
+ return $value;
+ }
+ // si la valeur vient des GET ou POST on la sanitize
+ if (!empty($value) and $value == _request($key)) {
+ $value = $sanitize_function($value);
+ }
+ return $value;
+}
/**
* Tester si une URL est absolue
include_spip('inc/filtres_mini');
$url = spip_htmlspecialchars($url);
- $url = str_replace(array("'", '"', '<', '[', ']'), array('%27', '%22', '%3C', '%5B', '%5D'), $url);
+ $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
// & ?
if ($amp != '&') {
$options = $defaut_options;
}
- if (is_array($args)) {
+ if (is_array($args) and count($args)) {
if (!function_exists('interdire_scripts')) {
include_spip('inc/texte');
}
/**
* Prédicat sur les scripts de ecrire qui n'authentifient pas par cookie
+ * et beneficient d'une exception
+ *
* @param string $nom
+ * @param bool $strict
* @return bool
*/
-function autoriser_sans_cookie($nom) {
+function autoriser_sans_cookie($nom, $strict = false) {
static $autsanscookie = array('install', 'base_repair');
- $nom = preg_replace('/.php[3]?$/', '', basename($nom));
- return in_array($nom, $autsanscookie);
+ if (in_array($nom, $autsanscookie)) {
+ if (test_espace_prive()){
+ include_spip('base/connect_sql');
+ if (!$strict or !spip_connect()){
+ return true;
+ }
+ }
+ }
+ return false;
}
/**
if (isset($GLOBALS['meta']['adresse_site'])) {
$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
- $uri_ref = $uri_ref['path'] . '/';
+ $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
} else {
$uri_ref = "";
}
} elseif (in_array('calcul', $var_mode)) {
define('_VAR_MODE', 'calcul');
}
- $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
}
+ $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
if ($var_mode) {
include_spip('inc/autoriser');
// autoriser preview si preview seulement, et sinon autoriser debug
include_spip('inc/autoriser');
if (autoriser('webmestre')) {
+ $cookies_masques = ['spip_session', 'PHPSESSID'];
+ $cookies_backup = [];
+ foreach ($cookies_masques as $k) {
+ if (!empty($_COOKIE[$k])) {
+ $cookies_backup[$k] = $_COOKIE[$k];
+ $_COOKIE[$k] = '******************************';
+ }
+ }
phpinfo();
+ foreach ($cookies_backup as $k => $v) {
+ $_COOKIE[$k] = $v;
+ }
} else {
include_spip('inc/filtres');
sinon_interdire_acces();
}
}
+}
+
+/**
+ * Nettoie une chaine pour servir comme classes CSS.
+ *
+ * @note
+ * les classes CSS acceptent théoriquement tous les caractères sauf NUL.
+ * Ici, on limite (enlève) les caractères autres qu’alphanumérique, espace, - + _ @
+ *
+ * @param string|string[] $classes
+ * @return string|string[]
+ */
+function spip_sanitize_classname($classes) {
+ if (is_array($classes)) {
+ return array_map('spip_sanitize_classname', $classes);
+ }
+ return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes);
}
\ No newline at end of file