Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security fixes #11

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prairie/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteRule ^(.*) index.php/$1
12 changes: 6 additions & 6 deletions prairie/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
SET
user_email_notify=" . $email_notify . "
WHERE
user_id=" . $_SESSION['user_id']
user_id=" . (int)$_SESSION['user_id']
;

$db->Execute($query);
Expand Down Expand Up @@ -75,7 +75,7 @@
user_language=" . $db->qstr($_POST['user_language']) . ",
user_timezone=" . $db->qstr($_POST['user_timezone']) . ",
user_birthdate=" . $db->qstr($_POST['user_birthdate']) . "
WHERE user_id=" . $_SESSION['user_id'].";";
WHERE user_id=" . (int)$_SESSION['user_id'].";";

$db->Execute($query);

Expand Down Expand Up @@ -133,7 +133,7 @@
$query = "
UPDATE " . $db->prefix . "_user
SET user_email=" . $db->qstr(trim($_POST['user_email1'])) . "
WHERE user_id=" . $_SESSION['user_id']
WHERE user_id=" . (int)$_SESSION['user_id']
;

$db->Execute($query);
Expand All @@ -159,7 +159,7 @@
$query = "
SELECT user_id
FROM " . $db->prefix . "_user
WHERE user_id=" . $_SESSION['user_id'] . "
WHERE user_id=" . (int)$_SESSION['user_id'] . "
AND user_password=" . $db->qstr(md5($_POST['user_password_old']))
;

Expand All @@ -175,7 +175,7 @@
UPDATE " . $db->prefix . "_user
SET user_password=" . $db->qstr(md5($_POST['user_password1'])) . "
WHERE
user_id=" . $_SESSION['user_id'] . " AND
user_id=" . (int)$_SESSION['user_id'] . " AND
user_password=" . $db->qstr(md5($_POST['user_password_old']))
;

Expand All @@ -188,7 +188,7 @@


// CHECK TO DISPLAY AVATAR DELETE BUTTON ------
$av = glob($core_config['file']['dir'] . "avatars/" . $_SESSION['user_id'] . "/100*");
$av = glob($core_config['file']['dir'] . "avatars/" . (int)$_SESSION['user_id'] . "/100*");

if (isset($av[0])) {
$body->set('display_avatar_delete_button', 1);
Expand Down
2 changes: 1 addition & 1 deletion prairie/class/Db.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function Execute($query, $rows=null, $offset=null) {
function qstr($s) {

if (!get_magic_quotes_gpc()) {
$s = addslashes($s);
$s = mysql_real_escape_string($s);
}
return "'" . $s . "'";
}
Expand Down
4 changes: 2 additions & 2 deletions prairie/class/Openid.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function checkid_setup($type = null) {
$openid_return_to = GetFromURL("openid_return_to");

if ($openid_identity == 'http://specs.openid.net/auth/2.0/identifier_select'){
$openid_identity='http://'.$_SERVER['SERVER_NAME'].'/';
$openid_identity='http'.(isset($_SERVER['HTTPS'])&& (strtolower($_SERVER['HTTPS']) == 'on' || $_SERVER['HTTPS'] == 1) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].'/';
}

$openIDns=GetFromURL("openid_ns");
Expand Down Expand Up @@ -469,7 +469,7 @@ function checkid_immediate() {
$openid_return_to = GetFromURL("openid_return_to");

if ($openid_identity == 'http://specs.openid.net/auth/2.0/identifier_select'){
$openid_identity='http://'.$_SERVER['SERVER_NAME'].'/';
$openid_identity='http'.(isset($_SERVER['HTTPS'])&& (strtolower($_SERVER['HTTPS']) == 'on' || $_SERVER['HTTPS'] == 1) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].'/';
}

if (!empty($_SESSION['user_id'])) {
Expand Down
16 changes: 8 additions & 8 deletions prairie/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
if (isset($_POST['save_profile'])) {
$title = trim($_POST['webspace_title']);

if (is_file('theme/' . $_POST['theme_name'] . '/thumb.png')) {
if (in_array($_POST['theme_name'], barnraiser_scandir('theme/')) && is_file('theme/' . $_POST['theme_name'] . '/thumb.png')) {
$theme_name = $_POST['theme_name'];
}
else {
Expand All @@ -40,7 +40,7 @@
$query = "
SELECT user_id
FROM " . $db->prefix . "_webspace
WHERE user_id=" . $_SESSION['user_id']
WHERE user_id=" . (int)$_SESSION['user_id']
;

$result = $db->Execute($query);
Expand All @@ -63,17 +63,17 @@
webspace_title=" . $db->qstr($title) . ",
webspace_theme=" . $db->qstr($theme_name) . "
WHERE
user_id=" . $_SESSION['user_id']
user_id=" . (int)$_SESSION['user_id']
;

$db->Execute($query);
}

if (!empty($title)) {
makeThemeHeader($core_config['file']['dir'], $_SESSION['user_id'], $theme_name, $title);
makeThemeHeader($core_config['file']['dir'], (int)$_SESSION['user_id'], $theme_name, $title);
}
else {
unlink($core_config['file']['dir'] . "/titles/" . $_SESSION['user_id'] . ".png");
unlink($core_config['file']['dir'] . "/titles/" . (int)$_SESSION['user_id'] . ".png");
}

header('location: /editor');
Expand All @@ -89,7 +89,7 @@
$query = "
SELECT user_id
FROM " . $db->prefix . "_webspace
WHERE user_id=" . $_SESSION['user_id']
WHERE user_id=" . (int)$_SESSION['user_id']
;

$result = $db->Execute($query);
Expand All @@ -111,7 +111,7 @@
SET
webspace_html=" . $db->qstr($html) . "
WHERE
user_id=" . $_SESSION['user_id']
user_id=" . (int)$_SESSION['user_id']
;
$db->Execute($query);
}
Expand All @@ -123,7 +123,7 @@
$query = "
SELECT *
FROM " . $db->prefix . "_webspace
WHERE user_id=" . $_SESSION['user_id']
WHERE user_id=" . (int)$_SESSION['user_id']
;

$result = $db->Execute($query);
Expand Down
6 changes: 3 additions & 3 deletions prairie/get_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@
$_REQUEST['width'] = 100;
}

$av = glob($core_config['file']['dir'] . 'avatars/' . $_REQUEST['avatar'] . '/' . $_REQUEST['width'] . '*');
$av = glob($core_config['file']['dir'] . 'avatars/' . (int)$_REQUEST['avatar'] . '/' . (int)$_REQUEST['width'] . '*');

if (isset($av[0])) {
$file = $av[0];
}
else {
$file = 'template/silver/img/no_avatar_' . $_REQUEST['width'] . '.png';
$file = 'template/silver/img/no_avatar_' . (int)$_REQUEST['width'] . '.png';
}
}
elseif (isset($_REQUEST['title'])) { // ?title=file = webpage title image
$file = $core_config['file']['dir'] . 'titles/' . $_REQUEST['title'] . '.png';
$file = $core_config['file']['dir'] . 'titles/' . (int)$_REQUEST['title'] . '.png';

if (!is_file($file)) {
$file = $core_config['file']['dir'] . 'titles/0.png';
Expand Down
16 changes: 5 additions & 11 deletions prairie/inc/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function labeltextarea_($name, $label, $value="") {
function input_($name, $defval="", $type="text", $size=45, $maxlength=0, $style=""){
$html='<input';
if ($style)$html.=' class="'.$style.'"';
$html .=' name="'.$name.'" type="'.$type.'" value="'.$defval.'"';
$html .=' name="'.$name.'" type="'.$type.'" value="'.htmlspecialchars($defval).'"';
$html .= ' id="'.$name.'" size="'.$size.'"';
if ($maxlength!=0) $html.=' maxlength="'.$maxlength.'"';
$html.="/>\n";
Expand All @@ -151,16 +151,10 @@ function textarea_($name, $content="", $cols=60, $rows=4, $style="" ) {

// URL routing into array
function routeURL ($webspace_name=null) {

$document_root = trim(dirname($_SERVER['PHP_SELF']), '/');
$script_name = $_SERVER['PHP_SELF'];

$request_uri = substr($_SERVER['REQUEST_URI'], strlen($document_root) + 1);

$tmp = strpos($request_uri, '?');

if ($tmp) {
$request_uri = substr($request_uri, 0, $tmp);
if (isset($_SERVER['ORIG_PATH_INFO'])) {
$request_uri = substr($_SERVER['ORIG_PATH_INFO'], 1);
} else {
$request_uri = substr($_SERVER['PATH_INFO'], 1);
}

$request_arr = explode('/', $request_uri);
Expand Down
10 changes: 8 additions & 2 deletions prairie/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@
$data_to_send = Array ();
$data_to_send['openid.ns'] = 'http://specs.openid.net/auth/2.0';
$data_to_send['openid.mode'] = 'setup_needed';
$data_to_send['openid.user_setup_url'] = 'http://'.$_SERVER['SERVER_NAME'] . '/login';
$data_to_send['openid.user_setup_url'] = 'http'.(isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on' || $_SERVER['HTTPS'] == 1) ? 's' : '').'://'.$_SERVER['SERVER_NAME'] . '/login';

header('location: ' . $openid_return_to . $s . http_build_query($data_to_send));
$redirurl = $openid_return_to . $s . http_build_query($data_to_send);
if (strpos($redirurl, '\n') !== FALSE || (strpos($redirurl, 'http://')!==0 && strpos($redirurl, 'https://')!==0)) {
header("Status: 500");
echo "Invalid return URL found.";
exit;
}
header('location: ' . $redirurl);
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion prairie/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
$query = "
UPDATE " . $db->prefix . "_user
SET user_password=" . $db->qstr(md5($new_password)) . "
WHERE user_id=" . $result[0]['user_id']
WHERE user_id=" . (int)$result[0]['user_id']
;

$db->Execute($query);
Expand Down
10 changes: 5 additions & 5 deletions prairie/maintain.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
user_email=" . $db->qstr($_POST['user_email']) . ",
user_dob=" . $db->qstr($dob) . "
WHERE
user_id=" . $_POST['user_id']
user_id=" . (int)$_POST['user_id']
;

$db->Execute($query);
Expand All @@ -52,7 +52,7 @@
SELECT user_id
FROM " . $db->prefix . "_user
WHERE
user_id=" . $_POST['user_id']
user_id=" . (int)$_POST['user_id']
;

$result = $db->Execute($query, 1);
Expand All @@ -65,7 +65,7 @@
$query = "
UPDATE " . $db->prefix . "_user
SET user_password=" . $db->qstr(md5($new_password)) . "
WHERE user_id=" . $result[0]['user_id']
WHERE user_id=" . (int)$result[0]['user_id']
;

$db->Execute($query);
Expand Down Expand Up @@ -107,7 +107,7 @@
$query = "
UPDATE " . $db->prefix . "_user
SET user_registration_key=" . $db->qstr($key) . "
WHERE user_id=" . $_POST['user_id']
WHERE user_id=" . (int)$_POST['user_id']
;

$db->Execute($query);
Expand Down Expand Up @@ -215,7 +215,7 @@
SELECT user_id, openid_name, user_name, user_email, user_dob, user_live
FROM " . $db->prefix . "_user
WHERE
user_id=".$uri_routing[2]
user_id=".(int)$uri_routing[2]
;

$result = $db->Execute($query, 1);
Expand Down
4 changes: 2 additions & 2 deletions prairie/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@

require_once('class/Mail/class.phpmailer.php');

$email_subject = stripslashes(htmlspecialchars($_POST['contact_subject']));
$email_subject = htmlspecialchars($_POST['contact_subject']);

$mail->Subject = $email_subject;

$email_message = stripslashes(htmlspecialchars($_POST['contact_message']));
$email_message = htmlspecialchars($_POST['contact_message']);

if (!empty($_POST['contact_email'])) {
$email_message .= "\n\n";
Expand Down
2 changes: 1 addition & 1 deletion prairie/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
user_registration_key=NULL,
user_live=1
WHERE
user_id=" . $result[0]['user_id']
user_id=" . (int)$result[0]['user_id']
;

$db->Execute($query);
Expand Down
22 changes: 11 additions & 11 deletions prairie/template/account.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="box_body">
<p>
<label for="id_user_name"><?php echo _("Name");?></label>
<input type="text" name="user_name" id="id_user_name" value="<?php if (isset($_SESSION['user_name'])) { echo $_SESSION['user_name']; }?>" />
<input type="text" name="user_name" id="id_user_name" value="<?php if (isset($_SESSION['user_name'])) { echo htmlspecialchars($_SESSION['user_name']); }?>" />
</p>

<p>
Expand Down Expand Up @@ -114,7 +114,7 @@

<p>
<label for="id_user_location"><?php echo _("Location");?></label>
<input type="text" name="user_location" id="id_user_location" value="<?php if (isset($_SESSION['user_location'])) echo $_SESSION['user_location']; ?>" />
<input type="text" name="user_location" id="id_user_location" value="<?php if (isset($_SESSION['user_location'])) echo htmlspecialchars($_SESSION['user_location']); ?>" />
</p>

<p class="warning">
Expand All @@ -123,37 +123,37 @@

<p>
<label for="id_user_nick"><?php echo _("Nickname");?></label>
<input type="text" name="user_nick" id="id_user_nick" value="<?php if (isset($_SESSION['user_nick'])) echo $_SESSION['user_nick']; ?>" />
<input type="text" name="user_nick" id="id_user_nick" value="<?php if (isset($_SESSION['user_nick'])) echo htmlspecialchars($_SESSION['user_nick']); ?>" />
</p>
<p>
<label for="id_user_gender"><?php echo _("Gender (M/F)");?></label>
<input type="text" name="user_gender" id="id_user_gender" value="<?php if (isset($_SESSION['user_gender'])) echo $_SESSION['user_gender']; ?>" />
<input type="text" name="user_gender" id="id_user_gender" value="<?php if (isset($_SESSION['user_gender'])) echo htmlspecialchars($_SESSION['user_gender']); ?>" />
</p>

<p>
<label for="id_user_postcode"><?php echo _("Postcode");?></label>
<input type="text" name="user_postcode" id="id_user_postcode" value="<?php if (isset($_SESSION['user_postcode'])) echo $_SESSION['user_postcode']; ?>" />
<input type="text" name="user_postcode" id="id_user_postcode" value="<?php if (isset($_SESSION['user_postcode'])) echo htmlspecialchars($_SESSION['user_postcode']); ?>" />
</p>

<p>
<label for="id_user_country"><?php echo _("Country code");?></label>
<input type="text" name="user_country" id="id_user_country" value="<?php if (isset($_SESSION['user_country'])) echo $_SESSION['user_country']; ?>" />
<input type="text" name="user_country" id="id_user_country" value="<?php if (isset($_SESSION['user_country'])) echo htmlspecialchars($_SESSION['user_country']); ?>" />
</p>


<p>
<label for="id_user_language"><?php echo _("Preferred Language (EN)");?></label>
<input type="text" name="user_language" id="id_user_language" value="<?php if (isset($_SESSION['user_language'])) echo $_SESSION['user_language']; ?>" />
<input type="text" name="user_language" id="id_user_language" value="<?php if (isset($_SESSION['user_language'])) echo htmlspecialchars($_SESSION['user_language']); ?>" />
</p>

<p>
<label for="id_user_timezone"><?php echo _("Timezone (Europe/Paris)");?></label>
<input type="text" name="user_timezone" id="id_user_timezone" value="<?php if (isset($_SESSION['user_timezone'])) echo $_SESSION['user_timezone']; ?>" />
<input type="text" name="user_timezone" id="id_user_timezone" value="<?php if (isset($_SESSION['user_timezone'])) echo htmlspecialchars($_SESSION['user_timezone']); ?>" />
</p>

<p>
<label for="id_user_birthdate"><?php echo _("Birthdate (YYYY-MM-DD)");?></label>
<input type="text" name="user_birthdate" id="id_user_birthdate" value="<?php if (isset($_SESSION['user_birthdate'])) echo $_SESSION['user_birthdate']; ?>" />
<input type="text" name="user_birthdate" id="id_user_birthdate" value="<?php if (isset($_SESSION['user_birthdate'])) echo htmlspecialchars($_SESSION['user_birthdate']); ?>" />
</p>

<p class="buttons">
Expand All @@ -174,7 +174,7 @@

<div class="box_body">
<div style="text-align:center;">
<img src="/get_file.php?avatar=<?php echo $_SESSION['user_id'];?>&amp;width=200" width="200" class="avatar" />
<img src="/get_file.php?avatar=<?php echo (int)$_SESSION['user_id'];?>&amp;width=200" width="200" class="avatar" />
</div>

<p>
Expand Down Expand Up @@ -206,7 +206,7 @@
<p>
<?php
$text = _("Your current email address is {1}.");
echo str_replace("{1}", $_SESSION['user_email'], $text);
echo str_replace("{1}", htmlspecialchars($_SESSION['user_email']), $text);
?>
</p>

Expand Down
4 changes: 2 additions & 2 deletions prairie/template/editor.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div class="box_body">
<p>
<label for="id_webspace_title"><?php echo _("Title");?></label>
<input type="text" name="webspace_title" id="id_webspace_title" value="<?php if (isset($webspace['webspace_title'])) { echo $webspace['webspace_title']; }?>" />
<input type="text" name="webspace_title" id="id_webspace_title" value="<?php if (isset($webspace['webspace_title'])) { echo htmlspecialchars($webspace['webspace_title']); }?>" />
</p>


Expand Down Expand Up @@ -91,7 +91,7 @@ function selectTheme(theme) {
<div class="box_body">
<p>
<label for="id_html"><?php echo _("HTML");?></label>
<textarea id="id_html" name="html" class="mceEditor"><?php if (isset($webspace['webspace_html'])) echo $webspace['webspace_html']; ?></textarea>
<textarea id="id_html" name="html" class="mceEditor"><?php if (isset($webspace['webspace_html'])) echo htmlspecialchars($webspace['webspace_html']); ?></textarea>
<script type="text/javascript">
tinyMCE.init({
// General options
Expand Down
Loading