Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from moufmouf/bugfix/109
SQL injection in OrderBy clause fix
- Loading branch information
Showing
6 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Mouf\Database\TDBM; | ||
|
||
class TDBMInvalidArgumentException extends \InvalidArgumentException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Mouf\Database\TDBM; | ||
|
||
/** | ||
* Use this object to inject any SQL string in an order by clause in $dao->find methods. | ||
* | ||
* By default, TDBM is conservative and prevents an ORDERBY clause to be anything other than a sort on columns. | ||
* This is done to prevent SQL injections. | ||
* | ||
* If you need to order on an expression, you can wrap your ORDERBY clause in this class. | ||
* | ||
* For instance: | ||
* | ||
* $this->find(null, null, new UncheckedOrderBy('RAND()')); | ||
* | ||
* Note: you understand that arguments passed inside the `UncheckedOrderBy` constructor are NOT protected and | ||
* can be used for an SQL injection based attack. Therefore, you understand that you MUST NOT put input from the user | ||
* in this constructor. | ||
*/ | ||
class UncheckedOrderBy | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $orderBy; | ||
|
||
/** | ||
* @param $orderBy | ||
*/ | ||
public function __construct(string $orderBy) | ||
{ | ||
$this->orderBy = $orderBy; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOrderBy() : string | ||
{ | ||
return $this->orderBy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters