}
 
     if ($template) {
+        $page->assign('rss_hash', $hash);
         header('Content-Type: application/rss+xml; charset=utf8');
     }
     return $uid;
 
         $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':
             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);
         $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 = {?}',
                 }
                 break;
 
-            case 'ajouter':
+              case 'ajouter':
                 require_once('user.func.inc.php');
                 if (($login = get_user_login($user)) !== false) {
                     if (XDB::execute(
                         $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;
 
 Ajouter la personne suivante à ma liste de contacts :
 <div style="float: right">
 <form id="add_user" action="carnet/contacts" method="post">
+  {xsrf_token_field}
   <div>
   <input type="hidden" name="action" value="ajouter" />
   <input type="text" size="30" name="user" class="quick_search"
 
 S'il n'y a rien à te signaler le mail ne t'est pas envoyé.</p>
 
 <form action="carnet/notifs" method="post">
+  {xsrf_token_field}
   <fieldset>
     <legend>Mail</legend>
     <input type='checkbox' name='mail' onclick="this.form.submit();" {if $watch->watch_mail}checked="checked"{/if} />
 </form>
 
 <form action="carnet/notifs" method="post">
+  {xsrf_token_field}
   <fieldset>
     <legend>Événements à surveiller</legend>
     {foreach from=$watch->cats() item=s key=i}
 <h2>Surveiller ses contacts</h2>
 
 <form action="carnet/notifs#middle" method="post">
+  {xsrf_token_field}
   <fieldset>
     <legend>Contacts</legend>
     <input type='checkbox' name='contacts' onclick="this.form.submit();" {if $watch->watch_contacts}checked="checked"{/if} /> Surveiller mes contacts<br />
 </p>
 
 <form action="carnet/notifs/" method="post">
+  {xsrf_token_field}
   <fieldset>
     <legend>Ajouter une promo</legend>
     Tu peux surveiller des promos (mettre la promo sur 4 chiffres),
     <ul>
     {foreach from=$watch->nonins() item=p}
     <li>
-      {$p.prenom} {$p.nom} ({$p.promo}) <a href="carnet/notifs/del_nonins/{$p.user_id}">{icon name='cross' title='retirer'}/<>
+      {$p.prenom} {$p.nom} ({$p.promo}) <a href="carnet/notifs/del_nonins/{$p.user_id}?token={xsrf_token}">{icon name='cross' title='retirer'}</a>
     </li>
     {/foreach}
   </ul>
 
         {$promo[row].prenom} {$promo[row].nom}
       </a>
       {if !$promo[row].contact}
-      <a href="carnet/contacts?action=ajouter&user={$promo[row].bestalias}">{*
+      <a href="carnet/contacts?action=ajouter&user={$promo[row].bestalias}&token={xsrf_token}">{*
         *}{icon name=add title="ajouter à mes contacts"}</a>
       {/if}
       {else}
 
       <description><![CDATA[
         {if $x.data}{$x.prenom} {$x.nom} a mis à jours les données suivantes :<br />{$x.data}<br />{/if}
         {if !$x.contact and !$x.dcd}
-        <a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&user={$x.bestalias}">
+        <a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&user={$x.bestalias}&token={$rss_hash}">
           {icon name=add title="Ajouter" full=true} Ajouter à mes contacts
         </a><br />
         {/if}
 
     {if $smarty.session.auth ge AUTH_COOKIE}
     {if !$c.wasinscrit && !$c.dcd}
       {if $show_action eq ajouter}
-        <a href="carnet/notifs/add_nonins/{$c.user_id}" target="_top">{*
+        <a href="carnet/notifs/add_nonins/{$c.user_id}?token={xsrf_token}" target="_top">{*
         *}{icon name=add title="Ajouter à la liste de mes surveillances"}</a>
       {else}
-        <a href="carnet/notifs/del_nonins/{$c.user_id}" target="_top">{*
+        <a href="carnet/notifs/del_nonins/{$c.user_id}?token={xsrf_token}" target="_top">{*
         *}{icon name=cross title="Retirer de la liste de mes surveillances"}</a>
       {/if}
     {elseif $c.wasinscrit && !$c.dcd}
         <a href="vcard/{$c.forlife}.vcf">{*
         *}{icon name=vcard title="Afficher la carte de visite"}</a>
       {if $show_action eq ajouter}
-        <a href="carnet/contacts?action={$show_action}&user={$c.forlife}" target="_top">{*
+        <a href="carnet/contacts?action={$show_action}&user={$c.forlife}&token={xsrf_token}" target="_top">{*
         *}{icon name=add title="Ajouter à mes contacts"}</a>
       {else}
-        <a href="carnet/contacts?action={$show_action}&user={$c.forlife}" target="_top">{*
+        <a href="carnet/contacts?action={$show_action}&user={$c.forlife}&token={xsrf_token}" target="_top">{*
         *}{icon name=cross title="Retirer de mes contacts"}</a>
       {/if}
     {/if}
 
     <div>
       {if !$c.wasinscrit && !$c.dcd}
         {if $show_action eq ajouter}
-    <a href="carnet/notifs/add_nonins/{$c.user_id}">{*
+    <a href="carnet/notifs/add_nonins/{$c.user_id}?token={xsrf_token}">{*
     *}{icon name=add title="Ajouter à la liste de mes surveillances"}</a>
         {else}
-    <a href="carnet/notifs/del_nonins/{$c.user_id}">{*
+    <a href="carnet/notifs/del_nonins/{$c.user_id}?token={xsrf_token}">{*
     *}{icon name=cross title="Retirer de la liste de mes surveillances"}</a>
         {/if}
       {elseif $c.wasinscrit}
     <a href="vcard/{$c.forlife}.vcf">{*
     *}{icon name=vcard title="Afficher la carte de visite"}</a>
           {if $show_action eq ajouter}
-    <a href="carnet/contacts?action={$show_action}&user={$c.forlife}">{*
+    <a href="carnet/contacts?action={$show_action}&user={$c.forlife}&token={xsrf_token}">{*
     *}{icon name=add title="Ajouter à mes contacts"}</a>
           {else}
-    <a href="carnet/contacts?action={$show_action}&user={$c.forlife}">{*
+    <a href="carnet/contacts?action={$show_action}&user={$c.forlife}&token={xsrf_token}">{*
     *}{icon name=cross title="Retirer de mes contacts"}</a>
           {/if}
         {/if}
 
        {if !$x.dcd}<a href="vcard/{$x.forlife}.vcf">{*
         *}{icon name=vcard title="Afficher la carte de visite"}</a>{/if}
       {if !$x.is_contact}
-      <a href="javascript:chgMainWinLoc('carnet/contacts?action=ajouter&user={$x.forlife}')">
+      <a href="javascript:chgMainWinLoc('carnet/contacts?action=ajouter&user={$x.forlife}&token={xsrf_token}')">
         {icon name=add title="Ajouter à mes contacts"}</a>
       {else}
-      <a href="javascript:chgMainWinLoc('carnet/contacts?action=retirer&user={$x.forlife}')">
+      <a href="javascript:chgMainWinLoc('carnet/contacts?action=retirer&user={$x.forlife}&token={xsrf_token}')">
         {icon name=cross title="Retirer de mes contacts"}</a>
       {/if}
       {if hasPerm('admin')}