From 2669eb7ddb20749fd6d1e99e611f6d199daa5580 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Thu, 3 Jul 2008 23:08:26 +0200 Subject: [PATCH] Adds XSRF protection to the Lists module. Signed-off-by: Vincent Zanotti --- modules/lists.php | 38 ++++++++++++++++++++++++++++++++++++++ templates/lists/admin.tpl | 5 ++++- templates/lists/annu.tpl | 4 ++-- templates/lists/check.tpl | 1 + templates/lists/create.tpl | 1 + templates/lists/delete.tpl | 1 + templates/lists/index.tpl | 1 + templates/lists/liste.inc.tpl | 20 ++++++++++---------- templates/lists/members.tpl | 4 ++-- templates/lists/moderate.tpl | 11 ++++++----- templates/lists/moderate_sub.tpl | 1 + templates/lists/options.tpl | 4 +++- templates/lists/soptions.tpl | 1 + 13 files changed, 71 insertions(+), 21 deletions(-) diff --git a/modules/lists.php b/modules/lists.php index 95efd3f..22fe67e 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -98,14 +98,18 @@ class ListsModule extends PLModule if (Get::has('del')) { + S::assert_xsrf_token(); $this->client->unsubscribe(Get::v('del')); pl_redirect('lists'); } if (Get::has('add')) { + S::assert_xsrf_token(); $this->client->subscribe(Get::v('add')); pl_redirect('lists'); } if (Post::has('promo_add')) { + S::assert_xsrf_token(); + $promo = Post::i('promo_add'); if ($promo >= 1900 and $promo < 2100) { $this->client->subscribe("promo$promo"); @@ -113,6 +117,7 @@ class ListsModule extends PLModule $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres."); } } + $listes = $this->client->get_lists(); $owner = array_filter($listes, 'filter_owner'); $listes = array_diff_key($listes, $owner); @@ -134,6 +139,8 @@ class ListsModule extends PLModule header('Content-Type: text/html; charset="UTF-8"'); $domain = $this->prepare_client($page); $page->changeTpl('lists/liste.inc.tpl', NO_SKIN); + S::assert_xsrf_token(); + if (Get::has('unsubscribe')) { $this->client->unsubscribe($list); } @@ -213,6 +220,8 @@ class ListsModule extends PLModule if (!Post::has('submit')) { return; + } else { + S::assert_xsrf_token(); } $asso = Post::v('asso'); @@ -295,11 +304,13 @@ class ListsModule extends PLModule $page->changeTpl('lists/members.tpl'); if (Get::has('del')) { + S::assert_xsrf_token(); $this->client->unsubscribe($liste); pl_redirect('lists/members/'.$liste); } if (Get::has('add')) { + S::assert_xsrf_token(); $this->client->subscribe($liste); pl_redirect('lists/members/'.$liste); } @@ -330,10 +341,12 @@ class ListsModule extends PLModule $this->prepare_client($page); if (Get::has('del')) { + S::assert_xsrf_token(); $this->client->unsubscribe($liste); pl_redirect('lists/annu/'.$liste); } if (Get::has('add')) { + S::assert_xsrf_token(); $this->client->subscribe($liste); pl_redirect('lists/annu/'.$liste); } @@ -454,6 +467,8 @@ class ListsModule extends PLModule $page->register_modifier('hdc', 'list_header_decode'); if (Env::has('sadd') || Env::has('sdel')) { + S::assert_xsrf_token(); + if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ $sub = $this->client->get_pending_sub($liste, Env::v('sadd')); $this->client->handle_request($liste,Env::v('sadd'),4,''); @@ -484,6 +499,8 @@ class ListsModule extends PLModule } if (Post::has('moderate_mails') && Post::has('select_mails')) { + S::assert_xsrf_token(); + $mails = array_keys(Post::v('select_mails')); foreach($mails as $mail) { $this->moderate_mail($domain, $liste, $mail); @@ -568,6 +585,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/admin.tpl'); if (Env::has('send_mark')) { + S::assert_xsrf_token(); + $actions = Env::v('mk_action'); $uids = Env::v('mk_uid'); $mails = Env::v('mk_email'); @@ -598,6 +617,8 @@ class ListsModule extends PLModule } if (Env::has('add_member')) { + S::assert_xsrf_token(); + require_once('user.func.inc.php'); $members = get_users_forlife_list(Env::v('add_member'), false, @@ -611,6 +632,8 @@ class ListsModule extends PLModule } if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) { + S::assert_xsrf_token(); + $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true); if (!$upload) { $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier'); @@ -628,6 +651,8 @@ class ListsModule extends PLModule } if (Env::has('del_member')) { + S::assert_xsrf_token(); + if (strpos(Env::v('del_member'), '@') === false) { $this->client->mass_unsubscribe( $liste, array(Env::v('del_member').'@'.$globals->mail->domain)); @@ -638,6 +663,8 @@ class ListsModule extends PLModule } if (Env::has('add_owner')) { + S::assert_xsrf_token(); + require_once('user.func.inc.php'); $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback')); if ($owners) { @@ -650,6 +677,8 @@ class ListsModule extends PLModule } if (Env::has('del_owner')) { + S::assert_xsrf_token(); + if (strpos(Env::v('del_owner'), '@') === false) { $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain); } else { @@ -689,6 +718,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/options.tpl'); if (Post::has('submit')) { + S::assert_xsrf_token(); + $values = $_POST; $values = array_map('utf8_decode', $values); $spamlevel = intval($values['bogo_level']); @@ -724,8 +755,10 @@ class ListsModule extends PLModule } $this->client->set_owner_options($liste, $values); } elseif (isvalid_email(Post::v('atn_add'))) { + S::assert_xsrf_token(); $this->client->add_to_wl($liste, Post::v('atn_add')); } elseif (Get::has('atn_del')) { + S::assert_xsrf_token(); $this->client->del_from_wl($liste, Get::v('atn_del')); pl_redirect('lists/options/'.$liste); } @@ -761,6 +794,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/delete.tpl'); if (Post::v('valid') == 'OUI') { + S::assert_xsrf_token(); + if ($this->client->delete_list($liste, Post::b('del_archive'))) { foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) { XDB::execute("DELETE FROM $table @@ -793,6 +828,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/soptions.tpl'); if (Post::has('submit')) { + S::assert_xsrf_token(); + $values = $_POST; $values = array_map('utf8_decode', $values); unset($values['submit']); @@ -820,6 +857,7 @@ class ListsModule extends PLModule $page->changeTpl('lists/check.tpl'); if (Post::has('correct')) { + S::assert_xsrf_token(); $this->client->check_options($liste, true); } diff --git a/templates/lists/admin.tpl b/templates/lists/admin.tpl index 0adaf22..ff1276c 100644 --- a/templates/lists/admin.tpl +++ b/templates/lists/admin.tpl @@ -60,6 +60,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la
+ {xsrf_token_field} {foreach from=$unregistered key=login item=it} @@ -103,6 +104,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la + {xsrf_token_field}
{foreach from=$owners item=xs key=promo} @@ -140,6 +142,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la + {xsrf_token_field}
{foreach from=$members item=xs key=promo} @@ -155,7 +158,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la {else} {$x.l} {/if} - {icon name=cross title='retirer membre'} + {icon name=cross title='retirer membre'}
{/foreach} diff --git a/templates/lists/annu.tpl b/templates/lists/annu.tpl index e03022c..1390e1f 100644 --- a/templates/lists/annu.tpl +++ b/templates/lists/annu.tpl @@ -54,13 +54,13 @@ {if $details.sub>1} Tu es inscrit sur la liste.
Te désinscrire : - {icon name=cross title="me désinscrire"} + {icon name=cross title="me désinscrire"} {elseif $details.sub eq 1} Ta demande d'inscription est en cours de validation. {else} Tu n'es pas inscrit.
Demander ton inscription : - {icon name=add title="demander mon inscription"} + {icon name=add title="demander mon inscription"} {/if} diff --git a/templates/lists/check.tpl b/templates/lists/check.tpl index 609b2f8..522fdee 100644 --- a/templates/lists/check.tpl +++ b/templates/lists/check.tpl @@ -36,6 +36,7 @@ {/foreach}
+ {xsrf_token_field}

diff --git a/templates/lists/create.tpl b/templates/lists/create.tpl index d642394..81437b7 100644 --- a/templates/lists/create.tpl +++ b/templates/lists/create.tpl @@ -38,6 +38,7 @@ liste :

+ {xsrf_token_field} diff --git a/templates/lists/delete.tpl b/templates/lists/delete.tpl index 1796e7d..65c25d6 100644 --- a/templates/lists/delete.tpl +++ b/templates/lists/delete.tpl @@ -41,6 +41,7 @@ Tu n'es pas administrateur de la liste, mais du site. + {xsrf_token_field}
Caractéristiques de la liste
diff --git a/templates/lists/index.tpl b/templates/lists/index.tpl index 731a570..bd00c1e 100644 --- a/templates/lists/index.tpl +++ b/templates/lists/index.tpl @@ -93,6 +93,7 @@ Les listes de diffusion publiques sont visibles par tous les X inscrits à Polyt {/if} + {xsrf_token_field} diff --git a/templates/lists/liste.inc.tpl b/templates/lists/liste.inc.tpl index a6ae99e..2ebb469 100644 --- a/templates/lists/liste.inc.tpl +++ b/templates/lists/liste.inc.tpl @@ -37,8 +37,8 @@ {if $liste.subscriptions|@count} • Demandes d'inscription
{foreach from=$liste.subscriptions item=s} - + {icon name=add title="Accepter"} @@ -55,12 +55,12 @@ • Demandes de modération
{foreach from=$liste.mails item=m} -
+ {icon name=add title="Valider le mail"} - + {icon name=delete title="Spam"} De : {$m.sender}
@@ -81,15 +81,15 @@ diff --git a/templates/lists/moderate.tpl b/templates/lists/moderate.tpl index 7bd86d0..704c34f 100644 --- a/templates/lists/moderate.tpl +++ b/templates/lists/moderate.tpl @@ -42,7 +42,7 @@ @@ -93,6 +93,7 @@ function toggleAll() { //]]> +{xsrf_token_field} {if $with_fromx}
Inscription à une liste de diffusion promo {$liste.nbsub} {if $liste.sub eq 2} - + {icon name=cross title="me désinscrire"} {elseif $liste.sub eq 1} {icon name=flag_orange title='inscription en attente de modération'} {else} - + {icon name=add title="m'inscrire"} {/if} diff --git a/templates/lists/members.tpl b/templates/lists/members.tpl index 135b6b8..b75548a 100644 --- a/templates/lists/members.tpl +++ b/templates/lists/members.tpl @@ -58,13 +58,13 @@ {if $details.sub>1} Tu es inscrit sur la liste.
Te désinscrire : - {icon name=cross title="me désinscrire"} + {icon name=cross title="me désinscrire"} {elseif $details.sub eq 1} Ta demande d'inscription est en cours de validation. {else} Tu n'es pas inscrit.
Demander ton inscription : - {icon name=add title="demander mon inscription"} + {icon name=add title="demander mon inscription"} {/if}
{$s.addr} - {icon name=add title="Valider l'inscription"} + {icon name=add title="Valider l'inscription"} {icon name=delete title="Refuser l'inscription"}
@@ -125,11 +126,11 @@ function toggleAll() { {$m.size} octets {/if} @@ -167,11 +168,11 @@ function toggleAll() { {$m.size} octets {/if} diff --git a/templates/lists/moderate_sub.tpl b/templates/lists/moderate_sub.tpl index f0a6c85..b1066cc 100644 --- a/templates/lists/moderate_sub.tpl +++ b/templates/lists/moderate_sub.tpl @@ -23,6 +23,7 @@

Refuser l'inscription d'un utilisateur

+ {xsrf_token_field}
- {icon name=add title="Accepter le message"} + {icon name=add title="Accepter le message"} {icon name=magnifier title="Voir le message"}
- {icon name=delete title="Spam !"} + {icon name=delete title="Spam !"}
- {icon name=add title="Accepter le message"} + {icon name=add title="Accepter le message"} {icon name=magnifier title="Voir le message"}
- {icon name=delete title="Spam !"} + {icon name=delete title="Spam !"}
diff --git a/templates/lists/options.tpl b/templates/lists/options.tpl index e329b6f..9dd310f 100644 --- a/templates/lists/options.tpl +++ b/templates/lists/options.tpl @@ -34,6 +34,7 @@ Tu n'es pas administrateur de la liste, mais du site. + {xsrf_token_field}
refuser l'inscription de :
@@ -195,13 +196,14 @@ redirection en mode 'inactif'. le logiciel de mailing list saura se débrouiller

+ {xsrf_token_field}
Options de la liste {$details.addr}
Adresses non modérées
{if $options.accept_these_nonmembers|@count} {foreach from=$options.accept_these_nonmembers item=addr} - {$addr} + {$addr} {icon name=cross title="retirer de la whitelist"}
{/foreach} diff --git a/templates/lists/soptions.tpl b/templates/lists/soptions.tpl index b2a3d1b..f2896af 100644 --- a/templates/lists/soptions.tpl +++ b/templates/lists/soptions.tpl @@ -28,6 +28,7 @@ + {xsrf_token_field} -- 2.1.4
Options de la liste {$details.addr}