aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
authornicosomb <nicolas@loeuillet.org>2013-04-15 14:09:58 +0200
committernicosomb <nicolas@loeuillet.org>2013-04-15 14:09:58 +0200
commitcf3180f6b8c552bbf7214d1ba72fbf1fc90ef861 (patch)
tree86d0cad24ed4891165d720a3bb19fffe6f55c73b /inc
parent358ab47957de18183aa3d3f7a62b631cd131f41f (diff)
downloadwallabag-cf3180f6b8c552bbf7214d1ba72fbf1fc90ef861.tar.gz
wallabag-cf3180f6b8c552bbf7214d1ba72fbf1fc90ef861.tar.zst
wallabag-cf3180f6b8c552bbf7214d1ba72fbf1fc90ef861.zip
vérificatio CSRF et mise en page
Diffstat (limited to 'inc')
-rw-r--r--inc/config.php10
-rwxr-xr-xinc/functions.php30
2 files changed, 36 insertions, 4 deletions
diff --git a/inc/config.php b/inc/config.php
index 29a22507..84b86998 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -22,4 +22,12 @@ raintpl::$cache_dir = './cache/';
22raintpl::$base_url = get_poche_url(); 22raintpl::$base_url = get_poche_url();
23raintpl::configure('path_replace', false); 23raintpl::configure('path_replace', false);
24raintpl::configure('debug', false); 24raintpl::configure('debug', false);
25$tpl = new raintpl(); \ No newline at end of file 25$tpl = new raintpl();
26
27session_start();
28
29if (!isset($_SESSION['token_poche'])) {
30 $token = md5(uniqid(rand(), TRUE));
31 $_SESSION['token_poche'] = $token;
32 $_SESSION['token_time_poche'] = time();
33} \ No newline at end of file
diff --git a/inc/functions.php b/inc/functions.php
index 45828bf2..30e00393 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -125,7 +125,7 @@ function prepare_url($url)
125/** 125/**
126 * Appel d'une action (mark as fav, archive, delete) 126 * Appel d'une action (mark as fav, archive, delete)
127 */ 127 */
128function action_to_do($action, $id) 128function action_to_do($action, $id, $url, $token)
129{ 129{
130 global $db; 130 global $db;
131 131
@@ -140,8 +140,11 @@ function action_to_do($action, $id)
140 $params_action = array($url, $parametres_url['title'], $parametres_url['content']); 140 $params_action = array($url, $parametres_url['title'], $parametres_url['content']);
141 break; 141 break;
142 case 'delete': 142 case 'delete':
143 $sql_action = "DELETE FROM entries WHERE id=?"; 143 if (verif_token($token)) {
144 $params_action = array($id); 144 $sql_action = "DELETE FROM entries WHERE id=?";
145 $params_action = array($id);
146 }
147 else die('CSRF problem');
145 break; 148 break;
146 default: 149 default:
147 break; 150 break;
@@ -224,4 +227,25 @@ function get_article($id)
224 } 227 }
225 228
226 return $entry; 229 return $entry;
230}
231
232/**
233 * Vérifie si le jeton passé en $_POST correspond à celui en session
234 */
235function verif_token($token)
236{
237 if(isset($_SESSION['token_poche']) && isset($_SESSION['token_time_poche']) && isset($token))
238 {
239 if($_SESSION['token_poche'] == $token)
240 {
241 $old_timestamp = time() - (15*60);
242 if($_SESSION['token_time_poche'] >= $old_timestamp)
243 {
244 return TRUE;
245 }
246 else return FALSE;
247 }
248 else return FALSE;
249 }
250 else return FALSE;
227} \ No newline at end of file 251} \ No newline at end of file