Changeset 1560

Show
Ignore:
Timestamp:
03/17/08 20:56:15 (2 months ago)
Author:
Neal
Message:

Added CSRF protection to subscribe/unsubscribe links.
Made CSRF protection more strict for deleting avatars/marking forums as read.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/punbb-1.3-dev/upload/include/functions.php

    r1549 r1560  
    14711471                                        $mail_message = str_replace('<replier>', $post_info['poster'], $mail_message); 
    14721472                                        $mail_message = str_replace('<post_url>', pun_link($pun_url['post'], $new_pid), $mail_message); 
    1473                                         $mail_message = str_replace('<unsubscribe_url>', pun_link($pun_url['unsubscribe'], $post_info['topic_id']), $mail_message); 
     1473                                        $mail_message = str_replace('<unsubscribe_url>', pun_link($pun_url['unsubscribe'], array($post_info['topic_id'], generate_form_token('unsubscribe'.$post_info['topic_id'].$cur_subscriber['id']))), $mail_message); 
    14741474                                        $mail_message = str_replace('<board_mailer>', sprintf($lang_common['Forum mailer'], $pun_config['o_board_title']), $mail_message); 
    14751475 
     
    14791479                                        $mail_message_full = str_replace('<message>', $post_info['message'], $mail_message_full); 
    14801480                                        $mail_message_full = str_replace('<post_url>', pun_link($pun_url['post'], $new_pid), $mail_message_full); 
    1481                                         $mail_message_full = str_replace('<unsubscribe_url>', pun_link($pun_url['unsubscribe'], $post_info['topic_id']), $mail_message_full); 
     1481                                        $mail_message_full = str_replace('<unsubscribe_url>', pun_link($pun_url['unsubscribe'], array($post_info['topic_id'], generate_form_token('unsubscribe'.$post_info['topic_id'].$cur_subscriber['id']))), $mail_message_full); 
    14821482                                        $mail_message_full = str_replace('<board_mailer>', sprintf($lang_common['Forum mailer'], $pun_config['o_board_title']), $mail_message_full); 
    14831483 
  • branches/punbb-1.3-dev/upload/include/rewrite_rules.php

    r1559 r1560  
    5353        '/^users(\.html?|\/)?$/i'                                                                                                                                                                                               =>      'userlist.php', 
    5454        '/^users\/(.*)\/([0-9-]+)\/?([a-z_]+)[\/_-]([a-zA-Z]+)[\/_-]p(age)?[\/_-]?([0-9]+)(\.html?|\/)?$/i'                                             =>      'userlist.php?username=$1&show_group=$2&sort_by=$3&sort_dir=$4&p=$6', 
    55         '/^(email|report|subscribe|unsubscribe)[\/_-]?([0-9]+)(\.html?|\/)?$/i'                                                                                                        =>      'misc.php?$1=$2', 
     55        '/^(email|report|subscribe|unsubscribe)[\/_-]?([0-9]+)[\/_-]?([a-z0-9]+)?(\.html?|\/)?$/i'                                                             =>      'misc.php?$1=$2&csrf_token=$3', 
    5656        '/^(mark|rules)[\/_-]?(read)?[\/_-]?([a-z0-9]+)?(\.html?|\/)?$/i'                                                                                                               =>      'misc.php?action=$1$2&csrf_token=$3', 
    5757        '/^mark[\/_-](forum)[\/_-]?([0-9]+)[\/_-](read)[\/_-]([a-z0-9]+)(\.html?|\/)?$/i'                                                                               =>      'misc.php?action=markforumread&fid=$2&csrf_token=$4', 
  • branches/punbb-1.3-dev/upload/include/url/Default.php

    r1557 r1560  
    7474        'search_user_posts'                             =>      'search.php?action=show_user_posts&amp;user_id=$1', 
    7575        'search_user_topics'                    =>      'search.php?action=show_user_topics&amp;user_id=$1', 
    76         'subscribe'                                             =>      'misc.php?subscribe=$1', 
     76        'subscribe'                                             =>      'misc.php?subscribe=$1&amp;csrf_token=$2', 
    7777        'topic'                                                 =>      'viewtopic.php?id=$1', 
    7878        'topic_rss'                                             =>      'extern.php?action=feed&amp;tid=$1&amp;type=rss', 
     
    8080        'topic_new_posts'                               =>      'viewtopic.php?id=$1&amp;action=new', 
    8181        'topic_last_post'                               =>      'viewtopic.php?id=$1&amp;action=last', 
    82         'unsubscribe'                                   =>      'misc.php?unsubscribe=$1', 
     82        'unsubscribe'                                   =>      'misc.php?unsubscribe=$1&amp;csrf_token=$2', 
    8383        'upload_avatar'                                 =>      'profile.php?action=upload_avatar&amp;id=$1', 
    8484        'user'                                                  =>      'profile.php?id=$1', 
  • branches/punbb-1.3-dev/upload/include/url/File_based.php

    r1557 r1560  
    7373        'search_user_posts'                             =>      'search-posts-user$1.html', 
    7474        'search_user_topics'                    =>      'search-topics-user$1.html', 
    75         'subscribe'                                             =>      'subscribe$1.html', 
     75        'subscribe'                                             =>      'subscribe$1-$2.html', 
    7676        'topic'                                                 =>      'topic$1.html', 
    7777        'topic_rss'                                             =>      'topic$1-rss.html', 
     
    7979        'topic_new_posts'                               =>      'topic$1new-posts.html', 
    8080        'topic_last_post'                               =>      'topic$1last-post.html', 
    81         'unsubscribe'                                   =>      'unsubscribe$1.html', 
     81        'unsubscribe'                                   =>      'unsubscribe$1-$2.html', 
    8282        'upload_avatar'                                 =>      'upload-avatar$1.html', 
    8383        'user'                                                  =>      'user$1.html', 
  • branches/punbb-1.3-dev/upload/include/url/File_based_(fancy).php

    r1557 r1560  
    7373        'search_user_posts'                             =>      'search-posts-user$1.html', 
    7474        'search_user_topics'                    =>      'search-topics-user$1.html', 
    75         'subscribe'                                             =>      'subscribe$1.html', 
     75        'subscribe'                                             =>      'subscribe$1-$2.html', 
    7676        'topic'                                                 =>      'topic$1-$2.html', 
    7777        'topic_rss'                                             =>      'topic$1-rss.html', 
     
    7979        'topic_new_posts'                               =>      'topic$1-$2-new-posts.html', 
    8080        'topic_last_post'                               =>      'topic$1last-post.html', 
    81         'unsubscribe'                                   =>      'unsubscribe$1.html', 
     81        'unsubscribe'                                   =>      'unsubscribe$1-$2.html', 
    8282        'upload_avatar'                                 =>      'upload-avatar$1.html', 
    8383        'user'                                                  =>      'user$1.html', 
  • branches/punbb-1.3-dev/upload/include/url/Folder_based.php

    r1557 r1560  
    7171        'search_user_posts'                             =>      'search/posts/user/$1/', 
    7272        'search_user_topics'                    =>      'search/topics/user/$1/', 
    73         'subscribe'                                             =>      'subscribe/$1/', 
     73        'subscribe'                                             =>      'subscribe/$1/$2/', 
    7474        'topic'                                                 =>      'topic/$1/', 
    7575        'topic_rss'                                             =>      'topic/$1/rss/', 
     
    7777        'topic_new_posts'                               =>      'topic/$1/new/posts/', 
    7878        'topic_last_post'                               =>      'topic/$1/last/post/', 
    79         'unsubscribe'                                   =>      'unsubscribe/$1/', 
     79        'unsubscribe'                                   =>      'unsubscribe/$1/$2/', 
    8080        'upload_avatar'                                 =>      'upload/avatar/$1/', 
    8181        'user'                                                  =>      'user/$1/', 
  • branches/punbb-1.3-dev/upload/include/url/Folder_based_(fancy).php

    r1557 r1560  
    7171        'search_user_posts'                             =>      'search/posts/user/$1/', 
    7272        'search_user_topics'                    =>      'search/topics/user/$1/', 
    73         'subscribe'                                             =>      'subscribe/$1/', 
     73        'subscribe'                                             =>      'subscribe/$1/$2/', 
    7474        'topic'                                                 =>      'topic/$1/$2/', 
    7575        'topic_rss'                                             =>      'topic/$1/rss/', 
     
    7777        'topic_new_posts'                               =>      'topic/$1/$2/new/posts/', 
    7878        'topic_last_post'                               =>      'topic/$1/last/post/', 
    79         'unsubscribe'                                   =>      'unsubscribe/$1/', 
     79        'unsubscribe'                                   =>      'unsubscribe/$1/$2/', 
    8080        'upload_avatar'                                 =>      'upload/avatar/$1/', 
    8181        'user'                                                  =>      'user/$1/', 
  • branches/punbb-1.3-dev/upload/misc.php

    r1556 r1560  
    116116        // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid. 
    117117        // If it's in GET, we need to make sure it's valid. 
    118         if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('markforumread'.$pun_user['id']))) 
     118        if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('markforumread'.intval($_GET['fid']).$pun_user['id']))) 
    119119                csrf_confirm_form(); 
    120120 
     
    452452                message($lang_common['No permission']); 
    453453 
     454        // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid. 
     455        // If it's in GET, we need to make sure it's valid. 
     456        if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('subscribe'.intval($_GET['subscribe']).$pun_user['id']))) 
     457                csrf_confirm_form(); 
     458 
    454459        ($hook = get_hook('mi_subscribe_selected')) ? eval($hook) : null; 
    455460 
     
    507512                message($lang_common['No permission']); 
    508513 
     514        // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid. 
     515        // If it's in GET, we need to make sure it's valid. 
     516        if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('unsubscribe'.intval($_GET['unsubscribe']).$pun_user['id']))) 
     517                csrf_confirm_form(); 
     518 
    509519        ($hook = get_hook('mi_unsubscribe_selected')) ? eval($hook) : null; 
    510520 
  • branches/punbb-1.3-dev/upload/profile.php

    r1558 r1560  
    693693        // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid. 
    694694        // If it's in GET, we need to make sure it's valid. 
    695         if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('delete_avatar'.$pun_user['id']))) 
     695        if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('delete_avatar'.$id.$pun_user['id']))) 
    696696                csrf_confirm_form(); 
    697697 
     
    21462146                                <?php echo implode("\n\t\t\t\t", $pun_page['hidden_fields'])."\n" ?> 
    21472147                        </div> 
    2148 <?php if ($pun_page['avatar_format'] != ''): ?>                         <p class="frm-fld link"><span class="fld-label"><a href="<?php echo pun_link($pun_url['delete_avatar'], array($id, generate_form_token('delete_avatar'.$pun_user['id']))) ?>"><?php echo $lang_profile['Delete avatar'] ?></a>:</span> <span class="fm-input"><?php echo $lang_profile['Avatar info remove'] ?></span></p> 
     2148<?php if ($pun_page['avatar_format'] != ''): ?>                         <p class="frm-fld link"><span class="fld-label"><a href="<?php echo pun_link($pun_url['delete_avatar'], array($id, generate_form_token('delete_avatar'.$id.$pun_user['id']))) ?>"><?php echo $lang_profile['Delete avatar'] ?></a>:</span> <span class="fm-input"><?php echo $lang_profile['Avatar info remove'] ?></span></p> 
    21492149<?php endif; ?>                 <fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>"> 
    21502150                                <legend class="frm-legend"><strong><?php echo $lang_profile['Avatar'] ?></strong></legend> 
  • branches/punbb-1.3-dev/upload/viewforum.php

    r1556 r1560  
    158158if (!$pun_user['is_guest'] && $db->num_rows($result)) 
    159159{ 
    160         $pun_page['main_foot_options'][] = '<a class="user-option" href="'.pun_link($pun_url['mark_forum_read'], array($id, generate_form_token('markforumread'.$pun_user['id']))).'"><span>'.$lang_forum['Mark forum read'].'</span></a>'; 
     160        $pun_page['main_foot_options'][] = '<a class="user-option" href="'.pun_link($pun_url['mark_forum_read'], array($id, generate_form_token('markforumread'.$id.$pun_user['id']))).'"><span>'.$lang_forum['Mark forum read'].'</span></a>'; 
    161161 
    162162        if ($pun_page['is_admmod']) 
  • branches/punbb-1.3-dev/upload/viewtopic.php

    r1555 r1560  
    209209{ 
    210210        if ($cur_topic['is_subscribed']) 
    211                 $pun_page['main_head_options'][] = '<a class="sub-option" href="'.pun_link($pun_url['unsubscribe'], $id).'"><em>'.$lang_topic['Cancel subscription'].'</em></a>'; 
     211                $pun_page['main_head_options'][] = '<a class="sub-option" href="'.pun_link($pun_url['unsubscribe'], array($id, generate_form_token('unsubscribe'.$id.$pun_user['id']))).'"><em>'.$lang_topic['Cancel subscription'].'</em></a>'; 
    212212        else 
    213                 $pun_page['main_head_options'][] = '<a class="sub-option" href="'.pun_link($pun_url['subscribe'], $id).'">'.$lang_topic['Subscription'].'</a>'; 
     213                $pun_page['main_head_options'][] = '<a class="sub-option" href="'.pun_link($pun_url['subscribe'], array($id, generate_form_token('subscribe'.$id.$pun_user['id']))).'">'.$lang_topic['Subscription'].'</a>'; 
    214214} 
    215215