From e6bf921624e50f7abdd9a1862d0b7ef4f1053090 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Sun, 18 May 2008 19:11:06 +0200 Subject: [PATCH] Adds XSRF protection to the Carnet module. Signed-off-by: Vincent Zanotti --- include/rss.inc.php | 1 + modules/carnet.php | 34 +++++++++++++++++++++++++++------- templates/carnet/mescontacts.tpl | 1 + templates/carnet/notifs.tpl | 6 +++++- templates/carnet/panel.tpl | 2 +- templates/carnet/rss.tpl | 2 +- templates/gadgets/ig-minifiche.tpl | 8 ++++---- templates/include/minifiche.tpl | 8 ++++---- templates/profile/profile.tpl | 4 ++-- 9 files changed, 46 insertions(+), 20 deletions(-) diff --git a/include/rss.inc.php b/include/rss.inc.php index 89d63ca..0117fc0 100644 --- a/include/rss.inc.php +++ b/include/rss.inc.php @@ -51,6 +51,7 @@ function init_rss($template, $alias, $hash, $require_uid = true) } if ($template) { + $page->assign('rss_hash', $hash); header('Content-Type: application/rss+xml; charset=utf8'); } return $uid; diff --git a/modules/carnet.php b/modules/carnet.php index 4dbb162..194d866 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -127,6 +127,10 @@ class CarnetModule extends PLModule $promo_sortie = $res->fetchOneCell(); $page->assign('promo_sortie', $promo_sortie); + if ($action && !S::has_xsrf_token()) { + $page->trig("La mise à jour des notifications a échouée, merci de réessayer."); + $action = false; + } switch ($action) { case 'add_promo': case 'del_promo': @@ -142,14 +146,24 @@ class CarnetModule extends PLModule break; } - if (Env::has('subs')) $watch->_subs->update('sub'); - if (Env::has('flags_contacts')) { + if (Env::has('subs') && S::has_xsrf_token()) { + $watch->_subs->update('sub'); + } elseif (Env::has('subs')) { + $page->trig("La mise à jour des notifications a échouée, merci de réessayer."); + } + + if (Env::has('flags_contacts') && S::has_xsrf_token()) { $watch->watch_contacts = Env::b('contacts'); $watch->saveFlags(); + } elseif (Env::has('flags_contacts')) { + $page->trig("La mise à jour des notifications a échouée, merci de réessayer."); } - if (Env::has('flags_mail')) { - $watch->watch_mail = Env::b('mail'); + + if (Env::has('flags_mail') && S::has_xsrf_token()) { + $watch->watch_mail = Env::b('mail'); $watch->saveFlags(); + } elseif (Env::has('flags_mail')) { + $page->trig("La mise à jour des notifications a échouée, merci de réessayer."); } $page->assign_by_ref('watch', $watch); @@ -198,8 +212,11 @@ class CarnetModule extends PLModule $uid = S::v('uid'); $user = Env::v('user'); - switch (Env::v('action')) { - case 'retirer': + // For XSRF protection, checks both the normal xsrf token, and the special RSS token. + // It allows direct linking to contact adding in the RSS feed. + if (Env::v('action') && (S::has_xsrf_token() || Env::v('token') === S::v('core_rss_hash'))) { + switch (Env::v('action')) { + case 'retirer': if (is_numeric($user)) { if (XDB::execute('DELETE FROM contacts WHERE uid = {?} AND contact = {?}', @@ -219,7 +236,7 @@ class CarnetModule extends PLModule } break; - case 'ajouter': + case 'ajouter': require_once('user.func.inc.php'); if (($login = get_user_login($user)) !== false) { if (XDB::execute( @@ -233,6 +250,9 @@ class CarnetModule extends PLModule $page->trig('Contact déjà dans la liste !'); } } + } + } elseif (Env::v('action')) { + $page->trig("La modification du contact a échouée, merci de réessayer."); } $search = false; diff --git a/templates/carnet/mescontacts.tpl b/templates/carnet/mescontacts.tpl index 65c9ef9..7264691 100644 --- a/templates/carnet/mescontacts.tpl +++ b/templates/carnet/mescontacts.tpl @@ -30,6 +30,7 @@ Ajouter la personne suivante à ma liste de contacts :
+ {xsrf_token_field}
+ {xsrf_token_field}
Mail watch_mail}checked="checked"{/if} /> @@ -36,6 +37,7 @@ S'il n'y a rien à te signaler le mail ne t'est pas envoyé.

+ {xsrf_token_field}
Événements à surveiller {foreach from=$watch->cats() item=s key=i} @@ -55,6 +57,7 @@ S'il n'y a rien à te signaler le mail ne t'est pas envoyé.

Surveiller ses contacts

+ {xsrf_token_field}
Contacts watch_contacts}checked="checked"{/if} /> Surveiller mes contacts
@@ -71,6 +74,7 @@ Attention : pour les promos, tu n'es pas notifié des événements trop fr

+ {xsrf_token_field}
Ajouter une promo Tu peux surveiller des promos (mettre la promo sur 4 chiffres), @@ -114,7 +118,7 @@ et cliquer sur les icones {icon name=add} pour les ajouter à cette liste. diff --git a/templates/carnet/panel.tpl b/templates/carnet/panel.tpl index 541a5da..446d644 100644 --- a/templates/carnet/panel.tpl +++ b/templates/carnet/panel.tpl @@ -73,7 +73,7 @@ Il faut pour cela se rendre sur la page de configuration {$promo[row].prenom} {$promo[row].nom} {if !$promo[row].contact} - {* + {* *}{icon name=add title="ajouter à mes contacts"} {/if} {else} diff --git a/templates/carnet/rss.tpl b/templates/carnet/rss.tpl index d279c87..0ec701e 100644 --- a/templates/carnet/rss.tpl +++ b/templates/carnet/rss.tpl @@ -44,7 +44,7 @@ {$x.data}
{/if} {if !$x.contact and !$x.dcd} - + {icon name=add title="Ajouter" full=true} Ajouter à mes contacts
{/if} diff --git a/templates/gadgets/ig-minifiche.tpl b/templates/gadgets/ig-minifiche.tpl index b04a21d..244fda4 100644 --- a/templates/gadgets/ig-minifiche.tpl +++ b/templates/gadgets/ig-minifiche.tpl @@ -37,20 +37,20 @@ {if $smarty.session.auth ge AUTH_COOKIE} {if !$c.wasinscrit && !$c.dcd} {if $show_action eq ajouter} - {* + {* *}{icon name=add title="Ajouter à la liste de mes surveillances"} {else} - {* + {* *}{icon name=cross title="Retirer de la liste de mes surveillances"} {/if} {elseif $c.wasinscrit && !$c.dcd} {* *}{icon name=vcard title="Afficher la carte de visite"} {if $show_action eq ajouter} - {* + {* *}{icon name=add title="Ajouter à mes contacts"} {else} - {* + {* *}{icon name=cross title="Retirer de mes contacts"} {/if} {/if} diff --git a/templates/include/minifiche.tpl b/templates/include/minifiche.tpl index f739586..a355e14 100644 --- a/templates/include/minifiche.tpl +++ b/templates/include/minifiche.tpl @@ -57,10 +57,10 @@
{if !$c.wasinscrit && !$c.dcd} {if $show_action eq ajouter} - {* + {* *}{icon name=add title="Ajouter à la liste de mes surveillances"} {else} - {* + {* *}{icon name=cross title="Retirer de la liste de mes surveillances"} {/if} {elseif $c.wasinscrit} @@ -70,10 +70,10 @@ {* *}{icon name=vcard title="Afficher la carte de visite"} {if $show_action eq ajouter} - {* + {* *}{icon name=add title="Ajouter à mes contacts"} {else} - {* + {* *}{icon name=cross title="Retirer de mes contacts"} {/if} {/if} diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index d4572fb..68ce962 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -65,10 +65,10 @@ function chgMainWinLoc(strPage)  {if !$x.dcd}{* *}{icon name=vcard title="Afficher la carte de visite"}{/if} {if !$x.is_contact} - + {icon name=add title="Ajouter à mes contacts"} {else} - + {icon name=cross title="Retirer de mes contacts"} {/if} {if hasPerm('admin')} -- 2.1.4