Project

General

Profile

« Previous | Next » 

Revision 1833

Added by Dietmar over 11 years ago

  1. security fix CRLF injection/HTTP response splitting

View differences:

branches/2.8.x/CHANGELOG
13 13

  
14 14

  
15 15

  
16
10 Dez-2012 Build 1833 Dietmar Woellbrink (Luisehahne)
17
# security fix CRLF injection/HTTP response splitting
16 18
09 Dez-2012 Build 1832 Dietmar Woellbrink (Luisehahne)
17 19
# security Application error message fix in search/search.php
18 20
05 Dez-2012 Build 1831 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/admin/skel/themes/htt/login.htt
40 40
<!-- BEGIN show_smart_login_block -->
41 41
<tr>
42 42
	<td>&nbsp;</td>
43
	<td colspan="2">
44
		<input type="checkbox" name="remember" id="remember" value="true"/>
45
		<label for="remember">{TEXT_REMEMBER_ME}</label>
46
	</td>
43
	<td>&nbsp;</td>
47 44
</tr>
48 45
<!-- END show_smart_login_block -->
49 46
<tr class="submit">
......
54 51
	<p><input type="reset" name="reset" value="{TEXT_RESET}" /></p>
55 52
	</td>
56 53
	<td>
57
	<p><button type="button" value="cancel" onclick="javascript:window.location='{WB_URL}/';" >{TEXT_CANCEL}</button></p>
54
	<p><button type="button" value="cancel" onclick="javascript:window.location='{REDIRECT_URL}/';" >{TEXT_CANCEL}</button></p>
58 55
	</td>
59 56
</tr>
60 57
<tr class="row6">
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1832');
54
if(!defined('REVISION')) define('REVISION', '1833');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/admin/login/forgot/index.php
16 16
*/
17 17

  
18 18
// Include the configuration file
19
if(!defined('WB_URL') && file_exists(realpath('../../../config.php'))) {
20
	require('../../../config.php');
19
$config_file = realpath('../../../config.php');
20
if(file_exists($config_file) && !defined('WB_URL'))
21
{
22
	require_once($config_file);
21 23
}
22 24
// Include the language file
23 25
require(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
......
34 36
$website_title = $results['value'];
35 37

  
36 38
// Check if the user has already submitted the form, otherwise show it
37
if(isset($_POST['email']) AND $_POST['email'] != "") {
38 39

  
40
if(isset($_POST['email']) && is_string($_POST['email']) && $_POST['email'] != "") {
41

  
39 42
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
40 43

  
41 44
	// Check if the email exists in the database
......
159 162
				'LOGIN_DISPLAY_HIDDEN' => !$admin->is_authenticated() ? 'hidden' : '',
160 163
				'LOGIN_DISPLAY_NONE' => !$admin->is_authenticated() ? 'none' : '',
161 164
				'URL_HELP' => 'http://www.websitebaker.org/',
165
				'URL' => ADMIN_URL."/start/index.php",
162 166
				'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN']
163 167
				)
164 168
		);
branches/2.8.x/wb/account/login_form.php
24 24
/* -------------------------------------------------------- */
25 25

  
26 26
	// Generate username field name
27
$username_fieldname = 'username';
28
$password_fieldname = 'password';
27
$username_fieldname = 'username_';
28
$password_fieldname = 'password_';
29 29
$output = '';
30 30
msgQueue::clear();
31 31

  
......
37 37
		$username_fieldname .= $temp[$i];
38 38
		$password_fieldname .= $temp[$i];
39 39
	}
40
} else {
41
	$username_fieldname = 'username';
42
	$password_fieldname = 'password';
40 43
}
41 44

  
42 45
$thisApp->redirect_url = (isset($thisApp->redirect_url) && ($thisApp->redirect_url!='')  ? $thisApp->redirect_url : $_SESSION['HTTP_REFERER'] );
43

  
46
//$thisApp->redirect_url = '';
44 47
$sIncludeHeadLinkCss = '';
45 48
if( is_readable(WB_PATH .'/account/frontend.css')) {
46 49
	$sIncludeHeadLinkCss .= '<link href="'.WB_URL.'/account/frontend.css"';
......
65 68
		'WB_URL' => WB_URL,
66 69
		'THEME_URL' => THEME_URL,
67 70
		'TEMPLATE_URL' => TEMPLATE_DIR,
68
		'HTTP_REFERER' => $_SESSION['HTTP_REFERER'],
71
		'HTTP_REFERER' => $thisApp->redirect_url,
69 72
        'CSS_BLOCK'	=> $sIncludeHeadLinkCss,
70 73
		'MESSAGE_VALUE' => '',
71 74
		'ERROR_VALUE' => '',
branches/2.8.x/wb/account/login.php
70 70
$loginUrl  = WB_URL.'/account/login.php';
71 71
$loginUrl .= (!empty($redirect) ? '?redirect=' .$_SESSION['HTTP_REFERER'] : '');
72 72

  
73
$ThemeUrl  = WB_URL.$wb->correct_theme_source('warning.html');
73
$WarningUrl  = str_replace(WB_PATH,WB_URL,$wb->correct_theme_source('warning.html'));
74 74
// Setup template object, parse vars to it, then parse it
75 75
$ThemePath = realpath(WB_PATH.$wb->correct_theme_source('loginBox.htt'));
76 76

  
77 77
$thisApp = new Login(
78 78
				array(
79 79
						"MAX_ATTEMPS" => "3",
80
						"WARNING_URL" => $ThemeUrl."/warning.html",
80
						"WARNING_URL" => $WarningUrl,
81 81
						"USERNAME_FIELDNAME" => 'username',
82 82
						"PASSWORD_FIELDNAME" => 'password',
83 83
						"REMEMBER_ME_OPTION" => SMART_LOGIN,
branches/2.8.x/wb/account/htt/login.htt
11 11
	<input type="hidden" name="action" value="login" />
12 12
	<input type="hidden" name="username_fieldname" value="{USER_FIELDNAME}" />
13 13
	<input type="hidden" name="password_fieldname" value="{PASSWORD_FIELDNAME}" />
14
	<input class="none" type="hidden" name="remember" id="remember" value="true" />
14 15
	<input type="hidden" name="redirect" value="{REDIRECT_URL}" />
15 16
<h3>{TEXT_LOGIN}</h3>
16 17
<table>
......
43 44
<!-- BEGIN show_smart_login_block -->
44 45
<tr>
45 46
	<td>&nbsp;</td>
46
	<td class="input">
47
		<input type="checkbox" name="remember" id="remember" value="true"/>
48
		<label for="remember">{TEXT_REMEMBER_ME}</label>
49
	</td>
47
	<td>&nbsp;</td>
50 48
</tr>
51 49
<!-- END show_smart_login_block -->
52 50
<tr>
......
56 54
	<td colspan="2" class="button">
57 55
	<button type="submit" name="submit" value="submit">{TEXT_LOGIN}</button>
58 56
	<button type="reset" name="reset" value="reset">{TEXT_RESET}</button>
59
    <button type="button" value="cancel" onclick="javascript:window.location='{WB_URL}/';" >{TEXT_CANCEL}</button>
57
    <button type="button" value="cancel" onclick="javascript:window.location='{REDIRECT_URL}/';" >{TEXT_CANCEL}</button>
60 58
	</td>
61 59
</tr>
62 60
<tr>
branches/2.8.x/wb/account/htt/forgot.htt
37 37
	<td colspan="2" class="button">
38 38
		<button type="submit" name="submit" value="email">{TEXT_SEND_DETAILS}</button>
39 39
		<button type="reset" name="reset" value="reset">{TEXT_RESET}</button>
40
        <button type="button" value="cancel" onclick="javascript:window.location='{WB_URL}/';" >{TEXT_CANCEL}</button>
40
        <button type="button" value="cancel" onclick="javascript:window.location='{URL}/';" >{TEXT_CANCEL}</button>
41 41
	</td>
42 42
</tr>
43 43
<tr>
branches/2.8.x/wb/account/forgot_form.php
17 17

  
18 18
/* -------------------------------------------------------- */
19 19
// Must include code to stop this file being accessed directly
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
20
if(!defined('WB_PATH')) {
21
	require_once(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php');
22
	throw new IllegalFileException();
24 23
}
25 24
/* -------------------------------------------------------- */
26 25
// Check if the user has already submitted the form, otherwise show it
......
30 29
$redirect_url = (isset($redirect_url) && ($redirect_url!='')  ? $redirect_url : $_SESSION['HTTP_REFERER'] );
31 30
$redirect = (isset($redirect_url) && ($redirect_url!='')  ? '?redirect='.$redirect_url : '' );
32 31

  
33
//print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
34
//print_r( $redirect_url ); print '</pre>';
32
if(isset($_POST['email']) && is_string($_POST['email']) )
33
{
35 34

  
36
if(isset($_POST['email']) && $_POST['email'] != "" )
37
{
38
	$email = strip_tags($_POST['email']);
39
	if($admin->validate_email($email) == false)
35
    if($_POST['email'] != "" )
40 36
    {
41
		$errMsg = $MESSAGE['USERS_INVALID_EMAIL'];
42
		$email = '';
43
	} else {
44
// Check if the email exists in the database
45
	$sql  = 'SELECT `user_id`,`username`,`display_name`,`email`,`last_reset`,`password` '.
46
	        'FROM `'.TABLE_PREFIX.'users` '.
47
	        'WHERE `email`=\''.$wb->add_slashes($_POST['email']).'\'';
48
	if(($results = $database->query($sql)))
49
	{
50
		if(($results_array = $results->fetchRow()))
51
		{ // Get the id, username, email, and last_reset from the above db query
52
		// Check if the password has been reset in the last 2 hours
53
			if( (time() - (int)$results_array['last_reset']) < (2 * 3600) ) {
54
			// Tell the user that their password cannot be reset more than once per hour
55
				$errMsg = $MESSAGE['FORGOT_PASS_ALREADY_RESET'];
56
			} else {
57
				require_once(WB_PATH.'/framework/PasswordHash.php');
58
				$pwh = new PasswordHash(0, true);
59
				$old_pass = $results_array['password'];
60
			// Generate a random password then update the database with it
61
				$new_pass = $pwh->NewPassword();
62
				$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
63
				       'SET `password`=\''.$pwh->HashPassword($new_pass, true).'\', '.
64
				           '`last_reset`='.time().' '.
65
				       'WHERE `user_id`='.(int)$results_array['user_id'];
66
				unset($pwh); // destroy $pwh-Object
67
				if($database->query($sql))
68
				{ // Setup email to send
69
					$mail_to = $email;
70
					$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
71
				// Replace placeholders from language variable with values
72
					$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
73
					$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
74
					$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
75
				// Try sending the email
76
					if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
77
						$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
78
						$display_form = false;
79
					}else { // snd mail failed, rollback
80
						$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
81
						       'SET `password`=\''.$old_pass.'\' '.
82
						       'WHERE `user_id`='.(int)$results_array['user_id'];
83
						$database->query($sql);
84
						$errMsg = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
85
					}
86
				}else { // Error updating database
87
					$errMsg = $MESSAGE['RECORD_MODIFIED_FAILED'];
88
					if(DEBUG) {
89
						$message .= '<br />'.$database->get_error();
90
						$message .= '<br />'.$sql;
91
					}
92
				}
93
			}
94
		}else { // no record found - Email doesn't exist, so tell the user
95
			$errMsg = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
96
		}
97
	} else { // Query failed
98
		$errMsg = 'SystemError:: Database query failed!';
99
		if(DEBUG) {
100
			$errMsg .= '<br />'.$database->get_error();
101
			$errMsg .= '<br />'.$sql;
102
		}
103
	}
104
	}
37
    
38
    	$email = strip_tags($_POST['email']);
39
    	if($wb->validate_email($email) == false)
40
        {
41
    		$errMsg = $MESSAGE['USERS_INVALID_EMAIL'];
42
    		$email = '';
43
    	} else {
44
        // Check if the email exists in the database
45
        	$sql  = 'SELECT `user_id`,`username`,`display_name`,`email`,`last_reset`,`password` '.
46
        	        'FROM `'.TABLE_PREFIX.'users` '.
47
        	        'WHERE `email`=\''.$wb->add_slashes($email).'\'';
48

  
49
        	if(($results = $database->query($sql)))
50
        	{
51
        		if(($results_array = $results->fetchRow(MYSQL_ASSOC)))
52
        		{ // Get the id, username, email, and last_reset from the above db query
53
        		// Check if the password has been reset in the last 2 hours
54
        			if( (time() - (int)$results_array['last_reset']) < (2 * 3600) ) {
55
        			// Tell the user that their password cannot be reset more than once per hour
56
        				$errMsg = $MESSAGE['FORGOT_PASS_ALREADY_RESET'];
57
        			} else {
58
        				require_once(WB_PATH.'/framework/PasswordHash.php');
59
        				$pwh = new PasswordHash(0, true);
60
        				$old_pass = $results_array['password'];
61
        			// Generate a random password then update the database with it
62
        				$new_pass = $pwh->NewPassword();
63
        				$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
64
        				       'SET `password`=\''.$pwh->HashPassword($new_pass, true).'\', '.
65
        				           '`last_reset`='.time().' '.
66
        				       'WHERE `user_id`='.(int)$results_array['user_id'];
67
        				unset($pwh); // destroy $pwh-Object
68
        				if($database->query($sql))
69
        				{ // Setup email to send
70
        					$mail_to = $email;
71
        					$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
72
        				// Replace placeholders from language variable with values
73
        					$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
74
        					$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
75
        					$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
76
        				// Try sending the email
77
        					if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
78
        						$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
79
        						$display_form = false;
80
        					}else { // snd mail failed, rollback
81
        						$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
82
        						       'SET `password`=\''.$old_pass.'\' '.
83
        						       'WHERE `user_id`='.(int)$results_array['user_id'];
84
        						$database->query($sql);
85
        						$errMsg = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
86
        					}
87
        				}else { // Error updating database
88
        					$errMsg = $MESSAGE['RECORD_MODIFIED_FAILED'];
89
        					if(DEBUG) {
90
        						$message .= '<br />'.$database->get_error();
91
        						$message .= '<br />'.$sql;
92
        					}
93
        				}
94
        			}
95
        		}else { // no record found - Email doesn't exist, so tell the user
96
        			$errMsg = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
97
        		}
98
        	} else { // Query failed
99
        		$errMsg = 'SystemError:: Database query failed!';
100
//            	$errMsg = $MESSAGE['USERS_INVALID_EMAIL'];
101
        		if(DEBUG) {
102
        			$errMsg .= '<br />'.$database->get_error();
103
        			$errMsg .= '<br />'.$sql;
104
        		}
105
        	}
106
    	}
107
    }  else {
108
    	$email = '';
109
    }
110
    
105 111
} else {
106 112
	$email = '';
107 113
}
branches/2.8.x/wb/framework/class.login.php
46 46
			$username_fieldname = 'username';
47 47
			$password_fieldname = 'password';
48 48
		}
49
		$this->username = htmlspecialchars (strtolower($this->get_post($username_fieldname)), ENT_QUOTES);
50 49

  
50
        if( is_array($this->get_post($username_fieldname) ) ) {
51
            $_POST[$username_fieldname]=implode(',',$this->get_post($username_fieldname));            
52
        }
53
		$this->username = htmlspecialchars (strtolower( $this->get_post($username_fieldname) ), ENT_QUOTES);
54

  
55
        if( is_array($this->get_post($password_fieldname) ) ) {
56
            $_POST[$password_fieldname]=implode(',',$this->get_post($password_fieldname));            
57
        }
51 58
		$this->password = $this->get_post($password_fieldname);
59

  
52 60
		// Figure out if the "remember me" option has been checked
53 61
		if($this->get_post('remember') == 'true') {
54 62
			$this->remember = $this->get_post('remember');
......
60 68
			$this->username_len = strlen($this->username);
61 69
			$this->password_len = strlen($this->password);
62 70
		}
71

  
72
        $sServerUrl = $_SERVER['SERVER_NAME'];        
73
        $sServerScheme = $_SERVER['REQUEST_SCHEME'];        
74
        $sServerPath = $_SERVER['SCRIPT_NAME'];        
63 75
		// If the url is blank, set it to the default url
64 76
		$this->url = $this->get_post('url');
77
        $aUrl = parse_url( $this->url );
78
        $this->url = isset($aRedirecthUrl['host']) &&($sServerUrl==$aUrl['host']) ? $this->url:ADMIN_URL.'/start/index.php';        
65 79
		if ($this->redirect_url!='') {
80
            $aRedirecthUrl = parse_url( $this->redirect_url );
81
            $this->redirect_url = isset($aRedirecthUrl['host']) &&($sServerUrl==$aRedirecthUrl['host']) ? $this->redirect_url:$sServerScheme.'://'.$sServerUrl;        
66 82
			$this->url = $this->redirect_url;
67 83
		}
68 84
		if(strlen($this->url) < 2) {
69
			$this->url = $config_array['DEFAULT_URL'];
85
            $aDefaultUrl = parse_url( $this->default_url );
86
            $this->default_url = isset($aDefaultUrl['host']) &&($sServerUrl==$aDefaultUrl['host']) ? $this->default_url:$sServerScheme.'://'.$sServerUrl;        
87
			$this->url = $this->default_url;
70 88
		}
89

  
71 90
		if($this->is_authenticated() == true) {
72 91
			// User already logged-in, so redirect to default url
73
//				header("Location: ".$this->url);
74
//				exit(0);
75 92
				$this->send_header($this->url);
76 93
		} elseif($this->is_remembered() == true) {
77 94
			// User has been "remembered"
......
86 103
			// Check if the user exists (authenticate them)
87 104
			if($this->authenticate()) {
88 105
				// Authentication successful
89
//				header("Location: ".$this->url);
90
//				exit(0);
91 106
				$this->send_header($this->url);
92 107
			} else {
93 108
				$this->message = $MESSAGE['LOGIN_AUTHENTICATION_FAILED'];
......
119 134
			$this->password = md5($this->password);
120 135
			if($this->authenticate()) {
121 136
				// Authentication successful
122
// 				echo $this->url;exit();
123
// 				header("Location: ".$this->url);
124
// 				exit(0);
125 137
				$this->send_header($this->url);
126 138
			} else {
127 139
				$this->message = $MESSAGE['LOGIN_AUTHENTICATION_FAILED'];
......
298 310
			}
299 311
			$template->set_var(array(
300 312
				'ACTION_URL' => $this->login_url,
313
				'URL' => $this->default_url,
301 314
				'ATTEMPS' => $this->get_session('ATTEMPS'),
302 315
				'USERNAME' => $this->username,
303 316
				'USERNAME_FIELDNAME' => $this->username_fieldname,

Also available in: Unified diff