Skip to content
Snippets Groups Projects
Commit 47b019cb authored by Giovannoni Laurent's avatar Giovannoni Laurent
Browse files

evo : security on where clause

parent 1f0465b6
No related branches found
No related tags found
No related merge requests found
...@@ -298,8 +298,8 @@ class SecurityControler ...@@ -298,8 +298,8 @@ class SecurityControler
} }
} }
return array( return array(
'COLUMNS' => implode(",", $columns), 'COLUMNS' => implode(",", $columns),
'VALUES' => implode(",", $values), 'VALUES' => implode(",", $values),
); );
} }
...@@ -409,7 +409,7 @@ class SecurityControler ...@@ -409,7 +409,7 @@ class SecurityControler
$where = $whereClause; $where = $whereClause;
if (preg_match('/@user/', $whereClause)) { if (preg_match('/@user/', $whereClause)) {
$where = str_replace( $where = str_replace(
"@user", "'" . trim($userId) . "'", $whereClause "@user", "'" . trim($userId) . "'", $whereClause
); );
} }
return $where; return $where;
...@@ -436,10 +436,10 @@ class SecurityControler ...@@ -436,10 +436,10 @@ class SecurityControler
$tab['security'][ $_SESSION['collections'][$i]['id']] = array(); $tab['security'][ $_SESSION['collections'][$i]['id']] = array();
foreach (array_keys($_ENV['targets']) as $key) { foreach (array_keys($_ENV['targets']) as $key) {
$tab['security'][ $_SESSION['collections'][$i]['id']][$key] = array( $tab['security'][ $_SESSION['collections'][$i]['id']][$key] = array(
'table' => $_SESSION['collections'][$i]['table'], 'table' => $_SESSION['collections'][$i]['table'],
'label_coll' => $_SESSION['collections'][$i]['label'], 'label_coll' => $_SESSION['collections'][$i]['label'],
'view' => $_SESSION['collections'][$i]['view'], 'view' => $_SESSION['collections'][$i]['view'],
'where' => " (1=1) ", 'where' => " (1=1) ",
'securityBitmask' => MAX_BITMASK, 'securityBitmask' => MAX_BITMASK,
); );
} }
...@@ -485,19 +485,19 @@ class SecurityControler ...@@ -485,19 +485,19 @@ class SecurityControler
if ($target == 'ALL') { if ($target == 'ALL') {
foreach (array_keys($_ENV['targets']) as $key) { foreach (array_keys($_ENV['targets']) as $key) {
$tab['security'][$collId][$key] = array( $tab['security'][$collId][$key] = array(
'table' => $_SESSION['collections'][$ind]['table'], 'table' => $_SESSION['collections'][$ind]['table'],
'label_coll' => $_SESSION['collections'][$ind]['label'], 'label_coll' => $_SESSION['collections'][$ind]['label'],
'view' => $_SESSION['collections'][$ind]['view'], 'view' => $_SESSION['collections'][$ind]['view'],
'where' => $where, 'where' => $where,
'securityBitmask' => $bitmask, 'securityBitmask' => $bitmask,
); );
} }
} else { } else {
$tab['security'][$collId][$target] = array( $tab['security'][$collId][$target] = array(
'table' => $_SESSION['collections'][$ind]['table'], 'table' => $_SESSION['collections'][$ind]['table'],
'label_coll' => $_SESSION['collections'][$ind]['label'], 'label_coll' => $_SESSION['collections'][$ind]['label'],
'view' => $_SESSION['collections'][$ind]['view'], 'view' => $_SESSION['collections'][$ind]['view'],
'where' => $where, 'where' => $where,
'securityBitmask' => $bitmask, 'securityBitmask' => $bitmask,
); );
} }
...@@ -525,20 +525,20 @@ class SecurityControler ...@@ -525,20 +525,20 @@ class SecurityControler
. $where; . $where;
} else { } else {
$tab['security'][$collId][$key] = array( $tab['security'][$collId][$key] = array(
'table' => $_SESSION['collections'][$ind]['table'], 'table' => $_SESSION['collections'][$ind]['table'],
'label_coll' => $_SESSION['collections'][$ind]['label'], 'label_coll' => $_SESSION['collections'][$ind]['label'],
'view' => $_SESSION['collections'][$ind]['view'], 'view' => $_SESSION['collections'][$ind]['view'],
'where' => $where, 'where' => $where,
'securityBitmask' => $bitmask, 'securityBitmask' => $bitmask,
); );
} }
} }
} else { } else {
$tab['security'][$collId][$target] = array( $tab['security'][$collId][$target] = array(
'table' => $_SESSION['collections'][$ind]['table'], 'table' => $_SESSION['collections'][$ind]['table'],
'label_coll' => $_SESSION['collections'][$ind]['label'], 'label_coll' => $_SESSION['collections'][$ind]['label'],
'view' => $_SESSION['collections'][$ind]['view'], 'view' => $_SESSION['collections'][$ind]['view'],
'where' => $where, 'where' => $where,
'securityBitmask' => $bitmask, 'securityBitmask' => $bitmask,
); );
} }
...@@ -553,7 +553,7 @@ class SecurityControler ...@@ -553,7 +553,7 @@ class SecurityControler
* *
* @param $collId string Collection identifier * @param $collId string Collection identifier
* @return integer Indice of the collection in the $_SESSION['collections'] * @return integer Indice of the collection in the $_SESSION['collections']
* or -1 if not found * or -1 if not found
*/ */
public function get_ind_collection($collId) public function get_ind_collection($collId)
{ {
...@@ -566,7 +566,7 @@ class SecurityControler ...@@ -566,7 +566,7 @@ class SecurityControler
} }
/** /**
* Give action bitmask for given $userId over given * Give action bitmask for given $userId over given
* object * object
* @param varchar(32) $userId * @param varchar(32) $userId
...@@ -674,11 +674,11 @@ class SecurityControler ...@@ -674,11 +674,11 @@ class SecurityControler
$sessionSecurity = new session_security(); $sessionSecurity = new session_security();
$sessionSecurity->setArray( $sessionSecurity->setArray(
array( array(
'user_id' => $func->protect_string_db($userId), 'user_id' => $func->protect_string_db($userId),
'session_begin_date' => date("Y-m-d H:i"), 'session_begin_date' => date("Y-m-d H:i"),
'full_where_clause' => $func->protect_string_db($fullWhere), 'full_where_clause' => $func->protect_string_db($fullWhere),
'last_available_bitmask' => $fullBitmask, 'last_available_bitmask' => $fullBitmask,
'last_object_id' => $func->protect_string_db($objectId) 'last_object_id' => $func->protect_string_db($objectId)
) )
); // TO DO : calculate the session_end_date ); // TO DO : calculate the session_end_date
$ctrl = new session_security_controler(); $ctrl = new session_security_controler();
...@@ -686,4 +686,28 @@ class SecurityControler ...@@ -686,4 +686,28 @@ class SecurityControler
return $fullBitmask; return $fullBitmask;
} }
/**
* Check the where clause syntax
*
* @param $whereClause string The where clause to check
* @return bool true if the request is not secure, false otherwise
*/
public function isUnsecureRequest($whereClause)
{
$search1 = '#\b(?:abort|alter|copy|create|delete|disgard|drop|'
. 'execute|grant|insert|load|lock|move|reset|truncate|update)\b#i';
preg_match($search1, $whereClause, $out);
if (isset($out[0])) {
$count = count($out[0]);
if ($count == 1) {
$find1 = true;
} else {
$find1 = false;
}
} else {
$find1 = false;
}
return $find1;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment