Ignore:
Timestamp:
Dec 24, 2005, 4:31:25 PM (18 years ago)
Author:
plg
Message:

bug 245 fixed : GET parameters "since", "sort_by", "sort_order",
"items_number", and "cat" are now checked before being used in SQL queries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_5/comments.php

    r946 r987  
    6262  );
    6363
    64 $page['since'] = isset($_GET['since']) ? $_GET['since'] : 1;
     64// since
     65//
     66$page['since'] = 1;
     67if (isset($_GET['since']))
     68{
     69  if (!isset($since_options{ $_GET['since'] }))
     70  {
     71    die('Hacking attempt on "since" GET parameter');
     72  }
     73  else
     74  {
     75    $page['since'] = $_GET['since'];
     76  }
     77}
    6578
    6679// on which field sorting
     
    7083if (isset($_GET['sort_by']))
    7184{
    72   $page['sort_by'] = $_GET['sort_by'];
     85  if (!isset($sort_by{ $_GET['sort_by'] }))
     86  {
     87    die('Hacking attempt on "sort_by" GET parameter');
     88  }
     89  else
     90  {
     91    $page['sort_by'] = $_GET['sort_by'];
     92  }
    7393}
    7494
     
    7999if (isset($_GET['sort_order']))
    80100{
    81   $page['sort_order'] = $sort_order[$_GET['sort_order']];
     101  if (!isset($sort_order{ $_GET['sort_order'] }))
     102  {
     103    die('Hacking attempt on "sort_order" GET parameter');
     104  }
     105  else
     106  {
     107    $page['sort_order'] = $sort_order[$_GET['sort_order']];
     108  }
    82109}
    83110
     
    87114if (isset($_GET['items_number']))
    88115{
    89   $page['items_number'] = $_GET['items_number'];
     116  if (!in_array($_GET['items_number'], $items_number))
     117  {
     118    die('Hacking attempt on "items_number" GET parameter');
     119  }
     120  else
     121  {
     122    $page['items_number'] = $_GET['items_number'];
     123  }
    90124}
    91125
    92126// which category to filter on ?
    93127$page['cat_clause'] = '1=1';
    94 if (isset($_GET['cat']) and 0 != $_GET['cat'])
    95 {
    96   $page['cat_clause'] =
    97     'category_id IN ('.implode(',', get_subcat_ids(array($_GET['cat']))).')';
     128if (isset($_GET['cat']))
     129{
     130  if (''.intval($_GET['cat']) != ''.$_GET['cat'])
     131  {
     132    die('Hacking attempt on "cat" GET parameter');
     133  }
     134  else if (0 != $_GET['cat'])
     135  {
     136    $page['cat_clause'] =
     137      'category_id IN ('.
     138      implode(
     139        ',',
     140        get_subcat_ids(array($_GET['cat']))
     141        ).
     142      ')'
     143      ;
     144  }
    98145}
    99146
     
    128175  $page['keyword_clause'] =
    129176    '('.
    130     implode(' AND ',
    131             array_map(
    132               create_function(
    133                 '$s',
    134                 'return "content LIKE \'%$s%\'";'
    135                 ),
    136               preg_split('/[\s,;]+/', $keyword)
    137               )
     177    implode(
     178      ' AND ',
     179      array_map(
     180        create_function(
     181          '$s',
     182          'return "content LIKE \'%$s%\'";'
     183          ),
     184        preg_split('/[\s,;]+/', $keyword)
     185        )
    138186      ).
    139     ')';
     187    ')'
     188    ;
    140189}
    141190
Note: See TracChangeset for help on using the changeset viewer.