Changeset 1742

Show
Ignore:
Timestamp:
09/03/2008 04:34:25 PM (3 months ago)
Author:
driehle
Message:

prevent response splitting + code cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/admin/login.php

    r1737 r1742  
    77### adapted for Jlog by Jeena Paradies 
    88 
    9  ini_set("session.use_trans_sid", false); 
     9ini_set("session.use_trans_sid", false); 
    1010 
    11  define("JLOG_ADMIN", true); 
    12  define("JLOG_LOGIN", true); 
    13  require_once('..'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'prepend.inc.php'); 
    14  require(JLOG_BASEPATH.'admin'.DIRECTORY_SEPARATOR.'blog.func.php'); 
     11define("JLOG_ADMIN", true); 
     12define("JLOG_LOGIN", true); 
     13require_once('..'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'prepend.inc.php'); 
     14require(JLOG_BASEPATH.'admin'.DIRECTORY_SEPARATOR.'blog.func.php'); 
    1515 
    16  $false_password = ""; 
    17  $get = strip($_GET); 
    18  $post = strip($_POST); 
     16$false_password = ""; 
     17$get = strip($_GET); 
     18$post = strip($_POST); 
    1919 
    20         ### Plugin Hook 
    21     $dispatch_login = $plugins->callHook('dispatchLogin', true); 
    22      
    23         if ($_SERVER['REQUEST_METHOD'] == 'POST' AND $dispatch_login) { 
    24                 session_start(); 
    25                 $passwort = $post['password']; 
    26                 $url = !empty($post['url']) ? $post['url'] : ""; 
    27                 $hostname = $_SERVER['HTTP_HOST']; 
    28                 $path = dirname($_SERVER['SCRIPT_NAME']) . "/"; 
     20### Plugin Hook 
     21$dispatch_login = $plugins->callHook('dispatchLogin', true); 
     22 
     23if ($_SERVER['REQUEST_METHOD'] == 'POST' AND $dispatch_login) { 
     24        session_start(); 
     25        $passwort = $post['password']; 
     26        $url      = !empty($post['url']) ? $post['url'] : ''; 
     27        $hostname = $_SERVER['HTTP_HOST']; 
     28        $path     = dirname($_SERVER['SCRIPT_NAME']) . '/'; 
     29         
     30        if (strpos($url, "\n") !== false or strpos($url, "\r") !== false) { 
     31            die('Somebody tried to hack Jlog with Response-Splitting.'); 
     32        } 
     33         
     34        if (md5($passwort) == JLOG_ADMIN_PASSWORD) { 
     35        $_SESSION['logged_in'] = true; 
     36                session_regenerate_id();        // neue SID 
     37         
     38        if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1') { 
     39                if (php_sapi_name() == 'cgi') header('Status: 303 See Other'); 
     40                else header('HTTP/1.1 303 See Other'); 
     41        } 
     42         
     43                if ($path == $url) $url = $path . 'new.php';             
     44                if (!empty($url)) $path = $url; 
    2945                 
    30                 if ( md5( $passwort ) == JLOG_ADMIN_PASSWORD) { 
    31                         $_SESSION['logged_in'] = true; 
    32                         session_regenerate_id();        // neue SID 
    33                  
    34                 if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1') { 
    35                         if (php_sapi_name() == 'cgi') header('Status: 303 See Other'); 
    36                         else header('HTTP/1.1 303 See Other'); 
    37                 } 
    38                  
    39                         if($path == $url) $url = $path."new.php";                
    40                         if(!empty($url)) $path = $url; 
    41                          
    42                         header('Location: ' . add_session_id_to_url("http://".$hostname.$path)); 
    43                         exit; 
    44                 } 
    45                 else { 
    46                         $false_password = "  <p class='error'>".$l['admin']['login_false_pw']."</p>\n"; 
    47                 } 
    48   } 
    49   else { 
    50       setcookie("cookieallowed", "true", time() + 180); 
    51   } 
    52        
    53  $c['meta']['title'] = $l['admin']['login_headline']; 
    54  $c['main'] = ' 
     46                header('Location: ' . add_session_id_to_url("http://".$hostname.$path)); 
     47                exit; 
     48        } 
     49        else { 
     50                $false_password = "  <p class='error'>".$l['admin']['login_false_pw']."</p>\n"; 
     51        } 
     52
     53else { 
     54    setcookie("cookieallowed", "true", time() + 180); 
     55
     56 
     57$c['meta']['title'] = $l['admin']['login_headline']; 
     58$c['main'] = ' 
    5559  <h2>'.$l['admin']['login_headline'].'</h2> 
    56   '.$false_password.
     60  ' . $false_password .
    5761  <form action="login.php" method="post" accept-charset="UTF-8"> 
    58    <p><label for="password">'.$l['admin']['login_password'].'</label> 
     62   <p><label for="password">' . $l['admin']['login_password'] . '</label> 
    5963      <input class="userdata" id="password" type="password" name="password" /> 
    6064      <input style="display: none;" name="username" type="text" value="do-not-change" /></p> 
    61    <p><input type="hidden" name="url" value="'.htmlspecialchars(!empty($get['url']) ? $get['url'] : $post['url']).'" /> 
    62       <input type="submit" value="'.$l['admin']['login_send'].'" /></p> 
     65   <p><input type="hidden" name="url" value="' . htmlspecialchars(!empty($get['url']) ? $get['url'] : '') . '" /> 
     66      <input type="submit" value="' . $l['admin']['login_send'] . '" /></p> 
    6367  </form> 
    6468';