Skip to content
Snippets Groups Projects
Commit a5dcf86a authored by Peter Rotich's avatar Peter Rotich Committed by Peter Rotich
Browse files

CVE-2017-14396

This commit addresses an SQL injection vulnerability in ORM lookup
function.

* ORM implementation failed to properly quote fields, used in SQL
statements, that might originate from unsanitized user input.

* AttachmentFile lookup allowed for key based SQL injection by blindly
delegating non-string lookup to ORM.
parent 9ee76ca0
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ require_once(INCLUDE_DIR.'class.file.php'); ...@@ -21,7 +21,7 @@ require_once(INCLUDE_DIR.'class.file.php');
if (!$_GET['key'] if (!$_GET['key']
|| !$_GET['signature'] || !$_GET['signature']
|| !$_GET['expires'] || !$_GET['expires']
|| !($file = AttachmentFile::lookup($_GET['key'])) || !($file = AttachmentFile::lookupByHash($_GET['key']))
) { ) {
Http::response(404, __('Unknown or invalid file')); Http::response(404, __('Unknown or invalid file'));
} }
......
...@@ -559,6 +559,10 @@ class AttachmentFile { ...@@ -559,6 +559,10 @@ class AttachmentFile {
return $id; return $id;
} }
function lookupByHash($hash) {
return self::lookup(AttachmentFile::getIdByHash($hash));
}
function lookup($id) { function lookup($id) {
$id = is_numeric($id)?$id:AttachmentFile::getIdByHash($id); $id = is_numeric($id)?$id:AttachmentFile::getIdByHash($id);
......
...@@ -875,7 +875,7 @@ class MySqlCompiler extends SqlCompiler { ...@@ -875,7 +875,7 @@ class MySqlCompiler extends SqlCompiler {
} }
function quote($what) { function quote($what) {
return "`$what`"; return sprintf("`%s`", str_replace("`", "``", $what));
} }
/** /**
......
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