Security: SQL-escape the return value of api_get_real_ip() as HTTP headers are vulnerable to remote tampering

pull/2495/head
Yannick Warnier 8 years ago
parent b358b8a0bf
commit 91888ab604
  1. 2
      main/exercise/exercise.class.php
  2. 4
      main/inc/lib/api.lib.php

@ -3036,7 +3036,7 @@ class Exercise
'orig_lp_item_id' => $safe_lp_item_id, 'orig_lp_item_id' => $safe_lp_item_id,
'orig_lp_item_view_id' => $safe_lp_item_view_id, 'orig_lp_item_view_id' => $safe_lp_item_view_id,
'exe_weighting' => $weight, 'exe_weighting' => $weight,
'user_ip' => api_get_real_ip(), 'user_ip' => Database::escape_string(api_get_real_ip()),
'exe_date' => api_get_utc_datetime(), 'exe_date' => api_get_utc_datetime(),
'exe_result' => 0, 'exe_result' => 0,
'steps_counter' => 0, 'steps_counter' => 0,

@ -1837,7 +1837,7 @@ function api_get_anonymous_id()
// Find if another anon is connected now // Find if another anon is connected now
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$tableU = Database::get_main_table(TABLE_MAIN_USER); $tableU = Database::get_main_table(TABLE_MAIN_USER);
$ip = api_get_real_ip(); $ip = Database::escape_string(api_get_real_ip());
$max = api_get_configuration_value('max_anonymous_users'); $max = api_get_configuration_value('max_anonymous_users');
if ($max >= 2) { if ($max >= 2) {
$sql = "SELECT * FROM $table as TEL $sql = "SELECT * FROM $table as TEL
@ -7409,6 +7409,8 @@ function api_user_is_login($user_id = null)
* Guess the real ip for register in the database, even in reverse proxy cases. * Guess the real ip for register in the database, even in reverse proxy cases.
* To be recognized, the IP has to be found in either $_SERVER['REMOTE_ADDR'] or * To be recognized, the IP has to be found in either $_SERVER['REMOTE_ADDR'] or
* in $_SERVER['HTTP_X_FORWARDED_FOR'], which is in common use with rproxies. * in $_SERVER['HTTP_X_FORWARDED_FOR'], which is in common use with rproxies.
* Note: the result of this function is not SQL-safe. Please escape it before
* inserting in a database
* *
* @return string the user's real ip (unsafe - escape it before inserting to db) * @return string the user's real ip (unsafe - escape it before inserting to db)
* *

Loading…
Cancel
Save